>> eigshow % run this program to visualize eigenvalues/eigenvectors >> A = [1 1; 0 2] % demo of the "eig" command in MATLAB A = 1 1 0 2 >> lambda = eig(A) % with one argument, eig returns only the eigenvalues lambda = 1 2 >> [V,D] = eig(A) % with two arguments, eig returns matrices V and D % with eigenvectors as the columns of V and % eigenvalues on the diagonal entries of D. V = 1.0000 0.7071 0 0.7071 D = 1 0 0 2 >> [A*V V*D] % note that A*V = V*D ans = 1.0000 1.4142 1.0000 1.4142 0 1.4142 0 1.4142 >> A*V-V*D ans = 0 0 0 0 >> v1 = V(:,1) % first column of V v1 = 1 0 >> v2 = V(:,2) % second column of V v2 = 0.7071 0.7071 >> >> lam1 = D(1,1) % first eigenvalue lam1 = 1 >> lam2 = D(2,2) % second eigenvalue lam2 = 2 >> [A*v1 lam1*v1] ans = 1 1 0 0 >> A*v1 - lam1*v1 % indeed, lam1 and v1 are an eigenvalue/eigenvector pair ans = 0 0 >> [A*v2 lam2*v2] ans = 1.4142 1.4142 1.4142 1.4142 >> A*v2 - lam2*v2 % indeed, lam2 and v2 are an eigenvalue/eigenvector pair ans = 0 0 >> A = [1 1; -1 1] % new matrix A = 1 1 -1 1 >> [V,D] = eig(A) % compute eigenvalues/eigenvectors V = 0.7071 0.7071 0 + 0.7071i 0 - 0.7071i D = 1.0000 + 1.0000i 0 0 1.0000 - 1.0000i % A has real entries.... % but complex eigenvalues and eigenvectors >> v1 = V(:,1); v2 = V(:,2); >> lam1 = D(1,1); lam2 = D(2,2); >> [A*v1 lam1*v1] ans = 0.7071 + 0.7071i 0.7071 + 0.7071i -0.7071 + 0.7071i -0.7071 + 0.7071i >> A*v1 - lam1*v1 ans = 0 0 >> [A*v2 lam2*v2] ans = 0.7071 - 0.7071i 0.7071 - 0.7071i -0.7071 - 0.7071i -0.7071 - 0.7071i >> A*v2 - lam2*v2 ans = 0 0 % In fact, "typical" matrices with real entries have complex eigenvalues. % Next we look at an example of a random matrix. >> A = randn(100)/sqrt(100); % entries normally distributed, mean 0, variance 1/100 >> lam = eig(A); >> plot(real(lam),imag(lam),'k.') >> axis equal, axis([-1.25 1.25 -1.25 1.25]) % As the matrix dimension gets large, these eigenvalues tend to cover % the unit circle in the complex plane with uniform probability. % To see this, we plot the unit circle... >> T = exp(linspace(0,2i*pi,500)); >> hold on, plot(real(T),imag(T),'r-','linewidth',2) % repeat this experiment for a larger matrix >> A = randn(500)/sqrt(500); >> lam = eig(A); >> figure >> plot(real(lam),imag(lam),'k.') >> axis equal, axis([-1.25 1.25 -1.25 1.25]) >> hold on, plot(real(T),imag(T),'r-','linewidth',2) % Random SYMMETRIC matrices act very differently. Here's one example. >> Asym = A + A'; >> norm(Asym-Asym') % If Asym = Asym', then this norm should be zero ans = 0 >> lam = eig(Asym); >> figure >> plot(real(lam),imag(lam),'k.') % Now all the eigenvalues look to be real numbers! Let's check this: >> max(abs(imag(lam))) ans = 0 % This turns is a remarkable property: % real symmetric matrices ALWAYS have real eigenvalues.