Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Just need the code for (a) I haven\'t had any luck. Thanks in advance! Consider

ID: 2844655 • Letter: J

Question

Just need the code for (a) I haven't had any luck. Thanks in advance!


Consider the logistic equation xn+1 = rhoxn(1 - xn) which was first developed to model the growth and decay of a population of some species over time. The variable xn represents the size of the population as a fraction of the maximum population; so xn = 0 means that the population is zero, and xn = 1 means the population is as large as it can be. The subscript "n" indicates a particular instance in time; for this example, each iteration (and therefore each subscript index n) represents a single year passing. Iterate the equation for the following values of rho, starting with a population on year 1 of x1 = 0.5: rho = 0.5, 2.6, 3.8 Iterate the equation for each value of rho and calculate three column vectors (one for each rho) of length 40 which contains x(1) to x(40). For fun, plot your results and try to interpret. ANSWERS; Should be written out as A18.dat-A20.dat. Now, plot the three solutions that you computed. Remember to comment out the plotting commands before you upload your code. Notice that the solution for rho = 0.5 looks like it might be decaying to zero. Using rho = 0.5 and starting with x1 = 0.5, iterate until the absolute value of xn+1 is less than 10-6, which occurs on iteration n. ANSWERS: Save a 2 times 1 vector in A21.dat. The first component should be the number of iterations n, and the second component should be the absolute value of xn+1. Note that in the notation above, iteration 1 takes us from x1 to x2.

Explanation / Answer

%copy the text into matlab and click run

%generates three graphs, A18 - A21 data files in .xls fomat (Microsoft excel)


clear all;

clc;


%Initialisation

N=40;


x=zeros(N,3);


x(1,1)=0.5;

x(1,2)=0.5;

x(1,3)=0.5;


rho(1)=0.5;

rho(2)=2.6;

rho(3)=3.8;


fg=1;



for i=1:N

  

x(i+1,1)=rho(1)*x(i,1)*(1-x(i,1));

x(i+1,2)=rho(2)*x(i,2)*(1-x(i,2));

x(i+1,3)=rho(3)*x(i,3)*(1-x(i,3));

  

if(x(i+1)<10^-6 && fg)

n=i;

K(1,1)=n;

K(2,1)=x(i+1,1);

fg=0;

display(n);

end

  

end





% I have writeen output to Excel files, for easy usage

%(a) part

xlswrite('A18.xls',x(1:N,1));

xlswrite('A19.xls',x(1:N,1));

xlswrite('A20.xls',x(1:N,1));


%(b) part

xlswrite('A21.xls',K);




range=1:N;






% Uncomment if you do not want plotting


figure(1)

plot(range,x(1:N,1));

title('For rho=0.5')

xlabel('No. of iterations')

ylabel('x')


figure(2)

plot(range,x(1:N,2));

title('For rho=2.6')

xlabel('No. of iterations')

ylabel('x')


figure(3)

plot(range,x(1:N,3));

title('For rho=3.8')

xlabel('No. of iterations')

ylabel('x')