Reputation: 2352
I have the following (edited) code for computing all the Eigen values and vectors of a small matrix using the power series method (by deflation technique):
function [eigvect,eigval]=eigen2(A,x0,nit)
% calculates the largest eigenvalue and corresponding eigenvector of
% matrix A by the power method using x0 as the starting vector and
% carrying out nit interactions.
%
eigval=0;
siz=size(A);
siz=siz(1);
for m=1:siz
x = x0;t=x0;
for n = 1:nit
xnew = A*x;
lambda = norm(xnew,inf);
tnew=transpose(A)*t;% computing left eigenvectors
x1=x;
x=xnew/lambda;
x2=x;
t1=t;
t=tnew/lambda;
t2=t;
end
x = x/(norm(x)); %normalise x
t=t/(norm(t));
eigvect(:,m)=x;
eigval(m)=lambda;
teigvect(:,m)=t;
% eigvect
Anew=A-x*transpose(x)*A*x*transpose(x);
A=Anew;
fprintf('\n lambda= %f',lambda);
end
teigvect
fprintf('n = %4d normalised x = %g %g %g\n', n, x');
% eigval
%end
The function calculates the eigen values correctly but not the corresponding eigen vectors for the non-dominant eigenvalues.
Can someone point where the error is?
EDIT1: Since the right and left eigen vectors are equal in a symmetric matrix, I am not involving the left eigen vector in the computation of Anew.
Test cases:
Computed using matlab's in-built eigen function:
A=[ 2 1 2; 1 2 1; 2 1 2];
[v,d]=eig(A)
v =
0.7071 0.3251 0.6280
0.0000 -0.8881 0.4597
-0.7071 0.3251 0.6280
d =
-0.0000 0 0
0 1.2679 0
0 0 4.7321
Result of the eigen2 function:
[r,s]=eigen2(A,[3 7 8]',100)
lambda= 4.732051
lambda= 1.267949
lambda= 0.000000
r =
0.6280 -0.3251 0.7071
0.4597 0.8881 0
0.6280 -0.3251 0.7071
s =
4.7321 1.2679 0.0000
Upvotes: 1
Views: 4298
Reputation: 25992
It is the power method, no power series here.
One obvious problem is that you assume that the left eigenvector is equal to the right eigenvector. This is only true for symmetric (and normal) matrices. If you use any other matrix, it is a wonder that the eigenvalues are computed correctly.
Upvotes: 1