function eigplot(file,n) % This function plots response of the dominant eigenvalue to changes in matrix elements % and finds the element value that produces dominant eigenvalue == 1 % file - matrix % n - number of stages factor = [0.02 0.05 0.1 0.2 0.5 0.7 1 1.5 2 3 5 10 15 20]; factordiag=0.4; ifplot = 1; %change as you wish (1 plots, 0 does not) fid=fopen(file,'r'); a1=fscanf(fid,'%f',[n, n]); a1=transpose(a1); for i1=1:n for j1=1:n alleig=0; allelem=0; a=a1; if (a(i1,j1) > 0) if (i1 ~= j1) for t = 1:10 if (a1(i1,j1) * factor(t) < 1) a(i1,j1) = a1(i1,j1) * factor(t); temp=eig(a); [w,d] = eig(a); d=diag(d); imax = find(d==max(d)); alleig(t) = temp(imax); allelem(t) = a(i1,j1); end end else for t = 1:10 if (1 - (1-a1(i1,j1)) * factor(t) * factordiag) > 0 a(i1,j1) = 1 - (1-a1(i1,j1)) * factor(t) * factordiag; temp = eig(a); [w,d] = eig(a); d=diag(d); imax = find(d==max(d)); alleig(t) = temp(imax); allelem(t) = a(i1,j1); end end end %alleig %allelem %lambda_equal_1_for = [i1 j1 a1(i1,j1) interp1(alleig,allelem,1)] if (ifplot == 1) figure; plot(allelem,alleig); TITLE(sprintf('i: %1d j: %1d',i1,j1)); end end end end fclose(fid);