Page 392 - Applied Numerical Methods Using MATLAB
P. 392

JACOBI METHOD  381
            Moreover, each of the disks contains at least one eigenvalue of the
            matrix A.
              The power method introduced in Section 8.3.1 is cast into the routine
            “eig_power()”. The MATLAB program “nm831.m” uses it to perform the power
            method, the inverse power method and the shifted inverse power method for
            finding the eigenvalues of a matrix and compares the results with that of the
            MATLAB built-in routine “eig()” for cross-check.


             function [lambda,v] = eig_power(A,x,EPS,MaxIter)
             % The power method to find the largest eigenvalue (lambda) and
             % the corresponding eigenvector (v) of a matrix A.
             if nargin < 4, MaxIter = 100; end % maximum number of iterations
             if nargin < 3, EPS = 1e-8; end % difference between successive values
             N = size(A,2);
             if nargin < 2, x = [1:N]; end % the initial vector
             x = x(:);
             lambda = 0;
             for k = 1:MaxIter
              x1 = x;  lambda1 = lambda;
              x = A*x/norm(x,inf); %Eq.(8.3.4)
              [xm,m] = max(abs(x));
              lambda = x(m); % the component with largest magnitude(absolute value)
              if norm(x1 - x) < EPS & abs(lambda1-lambda) < EPS, break; end
             end
             if k == MaxIter, disp(’Warning: you may have to increase MaxIter’); end
             v = x/norm(x);
             %nm831
             %Apply the power method to find the largest/smallest/medium eigenvalue
             clear
             A = [2 0 1;0 -2 0;1 0 2];
             x = [1 2 3]’; %x = [1 1 1]’; % with different initial vector
             EPS = 1e-8; MaxIter = 100;
             %the largest eigenvalue and its corresponding eigenvector
             [lambda_max,v] = eig_power(A,x,EPS,MaxIter)
             %the smallest eigenvalue and its corresponding eigenvector
             [lambda,v] = eig_power(A^ - 1,x,EPS,MaxIter);
             lambda_min = 1/lambda,  v %Eq.(8.3.6)
             %eigenvalue nearest to a number and its corresponding eigenvector
             s = -3;  AsI = (A - s*eye(size(A)))^ - 1;
             [lambda,v] = eig_power(AsI,x,EPS,MaxIter);
             lambda = 1/lambda+s %Eq.(8.3.8)
             fprintf(’Eigenvalue closest to %4.2f = %8.4f\nwith eigenvector’,s,lambda)
             v
             [V,LAMBDA] = eig(A) %modal matrix composed of eigenvectors



            8.4  JACOBI METHOD
            This method finds us all the eigenvalues of a real symmetric matrix. Its idea is
            based on the following theorem.
   387   388   389   390   391   392   393   394   395   396   397