%Simulate the age structure for sage grouse data
%Data 

N = 3;
A=[0.18,0.6,0.6;0.33,0,0;0,0.73,0.73];


%initial population

x = ones(N,1);


x = x/sum(x);

for j = 1:100
    x = A*x;
    x = x/sum(x);
    m(j) = [1:N]*x;
end
figure(1)
plot(x,'*')
xlabel('age class')
ylabel('percentage')
%figure(2)
%plot(m)

figure(3)
lam0 = max(abs(eig(A)));
plot(real(eig(A)),imag(eig(A)),'*')

%calculate elasticities
E = zeros(N,N);
for j = 1:N
    for k = 1:N
        
       if (A(j,k)~= 0)
           
           B = A;
           B(j,k) = 1.1*A(j,k);
           lambda = max(abs(eig(B)));
           
           E(j,k) =(lambda-lam0)/lam0/0.1;
       end
    end
end
    E
    
           