% Calculates lambda, sensitivity and elastivity function lambda(mat,k) % mat = set of transition matrices, one bellow each other, without any headings % k = number of stages % Reads the transition matrix fid=fopen(mat,'r'); b=fscanf(fid,'%f',[k,k]); % Transpose the transition matrix - this is due to matlab way of reading b=transpose(b); fclose(fid); [W,d] = eig(b); lambda = diag(d); imax = find(lambda==max(lambda)); V=conj(inv(W)); % w = stable stage distribution w = W(:,imax) % v = reproductive value v=real(V(imax,:)) % gets population growth rate - the dominant eigenvalue of the matrix lambda1 = lambda(imax) % calculates sensitivity of the matrix sen = v'*w'; % calculates elasticity of the matrix ela = sen.*b/max(eig(b)); % prints the results fid=fopen('lambda','a'); fprintf(fid,'%10.7f\t%10.7f\n',lambda1,i); fclose(fid);