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 10x1 = (by eigs) 0.8241 -0.5356 0.1844x2 = (by inverse power method) -0.8241 0.5356 -0.1844iter = 100
and
x1 = -0.8241 0.5356 -0.1844x2 = 0.8241 -0.5356 0.1844iter = 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.
Best Answer