% Filename: LesliePopulationPlot.m
% M-file to
% - Print out a table showing population structure over time

% Enter the transfer matrix
P = [ 0 10 1000 
      .02 0  0
       0 .05 0 ];
  
% Enter the initial state
x0 = [ 10 ; 0 ; 0 ];

% We will create a matrix x that has three columns.
% Each column will contain time series data for one class.
% Each row will correspond to a time step (t=0 to t=200) 
x = zeros(51,3);

x(1,:) = x0;       % Data for time step t = 0

% Use for loop to generate times series data
for t = 1:50
   x(t+1,:) = P^t * x0;  % Data for time step t
end

% Time series information for number of eggs is
% in the first column
eg = x(:,1);

% Time series information for number of juveniles 
%  is in the second column
ju = x(:,2);

% Time series information for number of adults is in the
% third column
a = x(:,3);

% Generate plot
time = [0:50];
plot(time,eg,'r-',time,ju,'g-',time,a,'b-')
legend('eggs', 'juv', 'adult')
xlabel('Time step t')
ylabel('Number of individuals')
figure
% Generate plot of proportion in each group
time = [0:50];
plot(time,eg/(eg+ju+a),'r-',time,ju/(eg+ju+a),'g-',time,a/(eg+ju+a),'b-')
legend('eggs', 'juv', 'adult')
xlabel('Time step t')
ylabel('Proportion of individuals')
