function eignmovie(A,n,loops) % This program visualizes eigenvectors for 2x2 matrices. % A is a 2x2 matrix. n is optional and determines the number of frames. % The 3rd optional parameter determines the number of loops shown. % It is based on an idea by Gilbert Strang, compare CMJ vol.26 no4, % September 1995, p.316 (article by 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 e.value) % % All rights reserved: Matthias Kawski, October 1995 % http://math.asu.edu/~kawski/ % Last update: Aug. 2004, removed "movie" command -- changed to real-time % calculation and live display. No more flickering. No need to DoubleBuffer. if nargin == 0 A=[13 9;3 7]/8; end; if nargin < 2 n = 72; end; if nargin < 3 loops = 3; end; phi=2*pi/n; z=zeros(1,n+1); x=cos(phi*[0:n]); y=sin(phi*[0:n]); [V,D]=eig(A); V1=V(:,1)'; V2=V(:,2)'; v=A(1,:)*[x;y]; w=A(2,:)*[x;y]; m=1.2*max([1,max(abs(v)),max(abs(w))]); myfig=figure set(myfig,'Renderer','painters') set(myfig,'DoubleBuffer','on') hold on plot(x,y,'c-',v,w,'g-'); text(-0.8*m,0.9*m,num2str(D)); text( 0.2*m,0.9*m,num2str(V)); axis([-m,m,-m,m]); axis equal figure(myfig); %% axis('off'); for j=1:loops for i=1:n+1 p=plot([0;x(i)],[0;y(i)],'b-',[0;v(i)],[0;w(i)],'r-'); pause(2/n) delete(p) end; end; disp('Hit enter to close the plot window') pause close(myfig)