% chinook popluation evolution over 24 years

% initial age distribution
x0=[1000;1000;1000];

% projection matrix
M=[0 0 2000; 0.005 0 0; 0 .10 0];

% % optional: Inspect M
% % set format so that Matlab uses the best of fixed or floating point
%format short g 
%M

% suppose we want to calculate population size and age distribution for the
% next 24 years

% 1) initialize an array that can hold 24 age distribution vectors:
X=zeros(3,24);

% 2) place the initial age distribution vector in the first column of X
X(:,1) = x0;

% 3) Calculate the second through twenty-fourth column of X by iterating
% the equation x(k) = M x(k-1) for k from two through twenty four

for k=2:24, X(:,k)=M*X(:,k-1); end


% 4) plot results
figure
% 4.1) plot number of salmon in the three age classes over time
subplot(2,1,1)
plot(X')
xlabel('time in years')
ylabel('number of individuals per age class')
legend('Juveniles','Subadults','Adults')
% 4.2) repeat but with logarithmic scale on the y-axis
subplot(2,1,2)
semilogy(X')
xlabel('time in years')
ylabel('number of individuals per age class')
legend('Juveniles','Subadults','Adults')

% 4.3) plot age distribution in years 1:8
figure
for i=1:8
    subplot(2,4,i)
    set(gca,'FontSize',14)
    barh(log10(X(:,i)));
    set(gca,'YTickLabel',{'Y1' 'Y2' 'Y3'})
    xlabel('log10(indiv.)')
    title(['Y' num2str(i)])
    axis([-1 6 0.5 3.5])
end


