inverse power method for smallest eigenvector calculation
Show older comments
Hi,
I need to calculate the smallest eigenvector of a matrix. I use eigs(A,1,'sm') and I would like to compare the result with inverse power method and see how many iteration it takes to calculate the same result. Here is the code,
function [x,iter] = invitr(A, ep, numitr)
[m,n] = size(A);
if m~=n
disp('matrix A is not square') ;
return;
end;
x=rand(n,1);
for k = 1 : numitr
iter = k;
xhat = A \ x;
x = xhat/norm(xhat,2);
if norm((A)* x , inf) <= ep
break;
end;
end;
end
First of all after some point the eigenvector stops converging yet the result comes with a sign change. That is ;
A =
1 3 5
2 6 8
3 8 10
x1 = (by eigs)
0.8241
-0.5356
0.1844
x2 = (by inverse power method)
-0.8241
0.5356
-0.1844
iter =
100
and
x1 =
-0.8241
0.5356
-0.1844
x2 =
0.8241
-0.5356
0.1844
iter =
1000
I might have done something wrong with my function, yet I don't understand why the sign changes with eigs. I appreciate all comments.
Accepted Answer
More Answers (1)
David Goodmanson
on 22 Feb 2017
Edited: David Goodmanson
on 22 Feb 2017
Hello Turker, There is nothing wrong here. The eigenvalue equation is
A*v = lambda*v
and so for the eigenvector, both v and -v are good solutions. The eigenvalue can't do that but it comes out correctly, which you can verify (since all components of your eigenvector are well away from equaling zero):
>> (A*x2)./x2
ans =
0.1689
0.1689
0.1689
compared to
>> eig(A)
ans =
17.5075
-0.6764
0.1689
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!