1. ## Matlab Help

I have a hw question that I couldn't seem to find the answer for hours (its now late so I also will get 0 credit for it). I still want to know the answer, or at least what I'm doing wrong. Thanks for your help!

Question:
Consider the logistic equation
x_(k+1) = βx_k (1 − x_k + (εx^2_k)/2)
which is based upon a model used to study the growth and decay of a population of some species.
Iterate the equation for the following values of β with ε = 0.1 and x_0 = 0.479:
β = 0.8, 1.5, 2.8, 3.2, 3.5, 3.65
Iterate the equation for each β value and calculate six column vectors (one for each β) of length
50 which contains x(1) = x1 to x(50) = x50 .
Answers: Write the output as A1.dat - A6.dat

This is the code I had for it:

Code:
E = 0.1;
A1 = 0;
A2 = 0;
A3 = 0;
A4 = 0;
A5 = 0;
A6 = 0;

for B = [0.8 1.5 2.8 3.2 3.5 3.65]
xold = 0;
i = 1;
for i = 1:50
xnew = B*xold*(1-xold+(E*xold^2)/2) + 0.479;
xold = xnew ;
if B == 0.8
A1(i, 1) = xnew ;
elseif B== 1.5
A2(i, 1) = xnew ;
elseif B== 2.8
A3(i, 1) = xnew ;
elseif B== 3.2
A4(i, 1) = xnew ;
elseif B== 3.5
A5(i, 1) = xnew ;
elseif B== 3.65
A6(i, 1) = xnew ;
end
end

end

save A1.dat A1 -ascii
save A2.dat A2 -ascii
save A3.dat A3 -ascii
save A4.dat A4 -ascii
save A5.dat A5 -ascii
save A6.dat A6 -ascii

2. Originally Posted by robgld
I have a hw question that I couldn't seem to find the answer for hours (its now late so I also will get 0 credit for it). I still want to know the answer, or at least what I'm doing wrong. Thanks for your help!

Question:
Consider the logistic equation
x_(k+1) = βx_k (1 − x_k + (εx^2_k)/2)
which is based upon a model used to study the growth and decay of a population of some species.
Iterate the equation for the following values of β with ε = 0.1 and x_0 = 0.479:
β = 0.8, 1.5, 2.8, 3.2, 3.5, 3.65
Iterate the equation for each β value and calculate six column vectors (one for each β) of length
50 which contains x(1) = x1 to x(50) = x50 .
Answers: Write the output as A1.dat - A6.dat

This is the code I had for it:

Code:
E = 0.1;
A1 = 0;
A2 = 0;
A3 = 0;
A4 = 0;
A5 = 0;
A6 = 0;

for B = [0.8 1.5 2.8 3.2 3.5 3.65]
xold = 0;
i = 1;
for i = 1:50
xnew = B*xold*(1-xold+(E*xold^2)/2) + 0.479;
xold = xnew ;
if B == 0.8
A1(i, 1) = xnew ;
elseif B== 1.5
A2(i, 1) = xnew ;
elseif B== 2.8
A3(i, 1) = xnew ;
elseif B== 3.2
A4(i, 1) = xnew ;
elseif B== 3.5
A5(i, 1) = xnew ;
elseif B== 3.65
A6(i, 1) = xnew ;
end
end

end

save A1.dat A1 -ascii
save A2.dat A2 -ascii
save A3.dat A3 -ascii
save A4.dat A4 -ascii
save A5.dat A5 -ascii
save A6.dat A6 -ascii
Try single stepping through this code in the debugger and see what you get at each step for the first few trips around that loop.

Hint "x_0 = 0.479" means initialise xold to 0.479.

CB