%project3 - Math 151 
%This is to illustrate eigenvalues and 
%eigenvectors arising from a population
%projection model.
%Read in a command file that is
%this file of commands for MATLAB
%by typing the name of this file in the command line
%   project3
%where project3.m is this file on your 
%computer, modified to use the particular parameters
%for your case
% P is the projection matrix and n0 is the
% initial population structure, ni is the population
% structure at time i, nitot is the total population size 
% at time i, ninorm is the normalized population structure
% at time i (sum of the elements of ninorm is 1)
P=[0 .6 .1; .5 0 0 ; 0 .7 0],pause
n0=[40;35;25],pause
n0tot=sum(n0)
n2=P^2*n0,pause
n2tot=sum(n2),pause
n2norm=n2/n2tot,pause
% growthi is the population growth rate from time i to i+1
% now compute the changes from time 20 to time 21
n20=P^20*n0,pause
n20tot=sum(n20),pause
n20norm=n20/n20tot,pause
n21=P^21*n0,pause
n21tot=sum(n21),pause
n21norm=n21/n21tot,pause
growth20=(n21tot-n20tot)/n20tot,pause
junk=[n20norm';n21norm';(n21norm-n20norm)'],pause
comp2=junk',pause
% Now compute the eigenvalues and compare these
% to the population growth rate at time 20
[X,e]=eig(P),pause
growth20,pause
% Now get the eigenvector for the dominant eigenvalue, 
% normalize it to get ev1norm, and compare this to 
% the normalized population structure at time 21
ev1=X(:,1),pause
ev1norm=ev1/sum(ev1),pause
n21norm,pause


