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

Need help with this matlab code question. THX! Problem 2: Equilibria We will now

ID: 2251507 • Letter: N

Question

Need help with this matlab code question. THX!

Problem 2: Equilibria We will now continue to investigate the logistic map that we first encountered in the previous homework: P(t) where P(t) represented the population density of a species after t years. Throughout this problem, we will assume that P(0) 10 and K = 50, (Note that these are not the same as in the previous homework. In particular, notice that time starts at year 0 now, not year 1.) If r = 2.5, create a vector containing the population densities for years 0 through 100. That is, the first entry of your vector should be P(0), the second entry should be P(1), etc., and the last entry should be P(100). If you plot these densities, you should see that the population density approaches a single value and stays there. (If you called your vector x, you could use the command plot (x) to visualize this data. Make sure you remove all plots before submitting to scorelator.) This final value is called an equilibrium or steady state of the logistic map. Repeat this process for r = 3.2 and r = 3.5. You should see very different behavior lot. In particular, these densities should not approach an equilibrium.

Explanation / Answer

%% P(t+1)= r * P(t)[1-(P(t)/k)]
close all
clear all
clc
P(1,1:3)=10; % Given P(0) = 10 but in matlab indexing starts from 1 so t=0 corresponds to the index 1 in our vector and is same for all values of r
k=50;% Given in the problem and is same for all values of r
t=0:100; % t has the number of years from 0 t0 100
r=[2.5 3.2 3.5]; % Given in the problem

for j=1:3
for t=1:100
P(t+1,j)=r(j) * P(t,j) * (1-P(t,j)/k); % length of P will be 101 because in 0 to 100 we have 101 numbers
end
A4(j,1:3)=P(99:101,j);
figure(j)
plot(P(:,j));
xlabel('t');
ylabel('r');
title(['r=',num2str(r(j))]);

end

The above code is for the first part. To remove the plots comment the lines that are in bold.

The below code is for the second part

close all
clear all
clc
%% P(t+1)= r * P(t)[1-(P(t)/k)]

r=2:0.1:3.4;
P(1,1:length(r))=10; % Given P(0) = 10 but in matlab indexing starts from 1 so t=0 corresponds to the index 1 in our vector and is same for all values of r
k=50;% Given in the problem and is same for all values of r
t=0:100; % t has the number of years from 0 t0 100
is_equilibrium=zeros(length(r),1);
equilibrium_value=zeros(length(r),1);
for j=1:length(r)
for t=1:501
P(t+1,j)=r(j) * P(t,j) * (1-P(t,j)/k); % length of P will be 101 because in 0 to 100 we have 101 numbers
end
if(abs(P(501,j)-P(500,j))<10^-8)
is_equilibrium(j)=1;
equilibrium_value(j)=P(501,j);
end
end