Home > K25104 > LinearSystems > basic_power.m

basic_power

PURPOSE ^

Implements basic power method to find an eigenvector of A,

SYNOPSIS ^

function [ v,c,k ] = basic_power( A,tol )

DESCRIPTION ^

 Implements basic power method to find an eigenvector of A, 
   and its corresponding eigenvalue
 Input arguments:
   A, square matrix
   tol, tolerance; x is accepted as the eigenvector
     with eigenvalue E if |Ax-Ex|<tol.
 Output arguments:
   v, eigenvector of A
   c, corresponding eigenvalue
   k, number of iterations

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ v,c,k ] = basic_power( A,tol )
0002 % Implements basic power method to find an eigenvector of A,
0003 %   and its corresponding eigenvalue
0004 % Input arguments:
0005 %   A, square matrix
0006 %   tol, tolerance; x is accepted as the eigenvector
0007 %     with eigenvalue E if |Ax-Ex|<tol.
0008 % Output arguments:
0009 %   v, eigenvector of A
0010 %   c, corresponding eigenvalue
0011 %   k, number of iterations
0012 
0013 [n,m]=size(A); % finding the size of A
0014 if n~= m;
0015     error('input is not a square matrix');
0016 elseif tol<=0;
0017     error('tolerance should be positive');
0018 end
0019 
0020 x0=rand(n,1);  % initializing x to a random vector
0021 k=0;    % initializing k
0022 
0023 while k>=0;     % this will always hold, another statement within the loop
0024                 % determines convergence and returns the function
0025                 
0026     x1=A*x0;    % apply A to generate new estimate of eigenvector
0027     ray=x0'*A*x0/(x0'*x0);  % calculate Rayleigh quotient
0028     
0029     y=x1-ray*x0;    % we accept convergence if |y|<tol
0030     if sqrt(y'*y)<tol;  
0031         c=ray;      % accept Rayleigh quotient as eigenvalue
0032         v=x0;       % accept x0 as eigenvector
0033         return;     % return function
0034     else
0035         x0=x1/sqrt(x1'*x1); % normalize estimate of eigenvector
0036         k=k+1;              % increment k
0037     end
0038 end
0039 
0040 end
0041 
0042

Generated on Mon 18-Jan-2016 10:25:49 by m2html © 2005