function [lam, ssd, rv, sens, elas] = senstuff(mat); %sensitivity, elasticity, lambda, rteigenvector, lfteigenvector %call for all the output: % [lam ssd rv sens elas] = senstuff(matrix) % these are the outputs input %call for lambda only: % senstuff(matrix) % will give only the first output variable, which is lambda1 %find the left eigenvector [matlvec,matval] = eig(mat'); [maxmatval, loc] = max(abs(diag(matval))); vvec=abs(matlvec(:,loc)); %find the right eigenvector [matrvec,matval] = eig(mat); [maxmatval, loc] = max(abs(diag(matval))); uvec=abs(matrvec(:,loc)); %dom eigenvalue lam = maxmatval; uvec=uvec./sum(uvec);%rescales the rt eigenvector to sum to 1 vvec=vvec./(vvec'*uvec);%rescales the lft eigenvector to calc sens sens=vvec*uvec';%gets the sensitivity matrix elas=sens.*(mat./lam);%which scales each sij by each aij/lambda ssd=uvec;%already normalized to sum to 1 rv=vvec;%normalized so that its scalar product with ssd is 1, rv'*sd=1