function eigplot(A,n) % This program visualizes eigenvectors for 2x2 matrices. % A is a 2x2 matrix. n is optional and determines the number % of vectors drawn. % The program works best for positive definite matrices. Negative % eigenvalues less than -1 give particularly cluttered images. % % As a reference see the CMJ vol.26,no4, Sept. 1995, p.316 (S. Schonefeld). % % Typical examples use the matrices: % % A=[13 9;3 7]/8; (fairly generic) % A=[cos(pi/4) -sin(pi/4);sin(pi/4) cos(pi/4)]; %% (nonreal eigenvalues) % A=[2 -2; -1 1]; (one zero eigenvalue) % A=[2-sqrt(3) -3; 1 2+sqrt(3)]/2; (double eigenvalue) % % All rights reseved: Matthias Kawski, October 1995 % http://math.asu.edu/~kawski/ % Most recent update: Aug 2004. Corrected placement of aspect ratio command. if nargin == 0 A=[13 9;3 7]/8; end; if nargin < 2 n=48; end; phi=2*pi/n; z=zeros(1,n); x=cos(phi*[0:n-1]); y=sin(phi*[0:n-1]); v=A(1,:)*[x;y]; w=A(2,:)*[x;y]; hold on [V,D]=eig(A); m=1.2*max([1,max(abs(v)),max(abs(w))]); myfig=figure hold on text(-0.8*m,0.9*m,num2str(D)); text( 0.2*m,0.9*m,num2str(V)); plot([z;x],[z;y],'b-',[x;x+v],[y;y+w],'r-') axis([-m,m,-m,m]); axis equal figure(myfig); disp('Hit enter to close the plot window') pause close(myfig)