Bi7740: Scientific computing Eigenvalues and eigenvectors - Exercises Vlad Popovici popovici@iba.muni.cz Institute of Biostatistics and Analyses Masaryk University, Brno Vlad Bi7740: Scientific computing Power method function [v, lambda] = eig_power(A, x0, max_iter, ∆) ... x0 = x0(:); % make it a column vector lambda = 0; for k = 1:max_iter lambda1 = lambda; x1 = A*x0/norm(x0,inf); [xm,m] = max(abs(x1)); lambda = x1(m); % new eigenvalue: the ... largest in new x if (norm(x1−x0) < ∆) && (abs(lambda1−lambda) < ∆) break end x0 = x1; % new approximation is x0 end ... v = x0/norm(x0); % ensure unit norm Vlad Bi7740: Scientific computing Try it: >> A = [2 0 1;0 −2 0;1 0 2]; >> [v,l] = eig_power(A) v = 3 l = 0.7071 −0.0000 0.7071 >> [v,l] = eig(A) v = 0 0.7071 0.7071 −1.000 0 0 0 −0.7071 0.7071 l = −2 0 0 0 1 0 0 0 3 Vlad Bi7740: Scientific computing