Matlab: % We are studying a population with juveniles J, youths Y and adults A; L=[0 .8 2.2; .5 0 0; 0 .6 0] (I relabeled this population matrix with A because it worked better with the exercise I did last week) % part c) If J_0=25, Y_0=50 and A_0=25, draw plots on the same set of axes % of the populations of each stage for the first 30 seasons Under the same initial conditions, plot the natural logarithms % of the populations versus time (in the previous plot commands, % replace the population vector by log(population` vector). Read the answer % in the book to get an explanation of what is happening.
My code attempt >> clear all; timesteps=30; x=[25; 50; 25]; xhistory=x; A=log([0 .8 2.2; .5 0 0; 0 .6 0]); for t=1:timesteps; x=A*x; xhistory=[xhistory x]; end >> time=0:timesteps; subplot(2,1,1) >> plot(time,xhistory(1,:),'-'), xlabel('time'), ylabel('populations'), hold on >> plot(time, xhistory(2,:)) subplot(2,1,2) plot(xhistory(1,:), xhistory(2,:)), xlabel('juveniles'), ylabel('adults'), hold on [V,D]=eig(A) C= V\xhistory(:,1) xpprox = C(2)*V(:,2)*D(2,2).^(time) >> subplot(2,1,1) >> plot(time, xpprox, 'r') >> subplot(2,1,2) >> plot(xpprox(1,:),xpprox(2,:),'r')
These two are the graphs without the change the population matrix into a logarithm and plot those. Corresponds to part c.
@Lyrae @dan815
>> clear all; timesteps=30; x=[25; 50; 25]; xhistory=x; A=[0 .8 2.2; .5 0 0; 0 .6 0]; for t=1:timesteps; x=A*x; xhistory=[xhistory x]; end time=0:timesteps; subplot(2,1,1) semilogx(time,xhistory(1,:),'-'), xlabel('time'), ylabel('populations'), hold on semilogy(time, xhistory(2,:)) subplot(2,1,2) plot(xhistory(1,:), xhistory(2,:)), xlabel('juveniles'), ylabel('adults'), hold on >>
Hey, do you still need help with this?
Join our real-time social learning platform and learn together with your friends!