% Jerry Zhu
% geometric intuition of eigenvector
A=rand(2,2)
[eigvec, eigval]=eig(A)
for th=0:0.1:2*pi; 
  x=[cos(th); sin(th)]; line([0 x(1)], [0 x(2)]); 
  y=A*x; h=line([0 y(1)], [0 y(2)]); set(h, 'Color', [1 0 0]); 
  h=line([0 eigvec(1,1)], [0 eigvec(2,1)]); set(h, 'Color', [0 1 0]); 
  h=line([0 eigvec(1,2)], [0 eigvec(2,2)]); set(h, 'Color', [0 1 0]); 
  legend('x', 'Ax', 'eigenvectors of A')
  axis square; axis([-1.5 1.5 -1.5 1.5])
  pause
  clf
end    
