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

% Enter the Leslie matrix
P = [0 10 10 
      .02 0  0
       0 .05 0 ];
  
% Enter the initial state
x0 = [ 10 ; 0 ; 0 ];
  
% Print header for table
fprintf(' t  eggs   juveniles  adults\n')
fprintf('-------------------------\n')

% Fill in table using a for loop
for t = [1 2 3 4 5 10 20 30 40 50 100 200]  % array of times
   x = P^t * x0;            % matrix multiplication
   e = x(1,1);              % get eggs value for this time step
   j = x(2,1);              % get juveniles value for this time step
   a = x(3,1);              % get adults value for this time step
   fprintf('%3d  %5.3f  %5.3f  %5.3f\n',t,e,j,a)  % print it all out
end