MATLAB: I am writting a code for power method, and I am not able to find the corresponding eigenvector for the eigenvalue

power method

here is my code, and I am able to find the eigenvalue which I am excepted, but not the corresponding eigenvector.
function [ l,x,it ] = powerit( A,x0,N,tol )
A=[1 1 0 0;1 2 0 1; 0 0 3 3;0 1 3 2]
x0=[1;1;0;1]
tol=1e-4
N=25
af=norm(A);
x=x0/norm(x0);
for k=1:N
y=A*x;
l=x'*y;
if norm(y-l*x)/af < tol
it=k;
x=y/norm(y);
return
end
x=y/norm(y);
end it=N+1
end

Best Answer

So you have an eigenvalue, but not the corresponding eigenvector? If lambda is an eigenvalue of the matrix A, then the corresponding eigenvector can be found as the vector V:
V = null(A - eye(size(A))*lambda)
Note that V MAY sometimes have more than one column, if lambda was an eigenvalue of multiplicity higher than 1.
Essentially, you need to solve the linear homogeneous system of equations for the problem
A*V = lambda*V
where lambda is known. The solution I have given implements that solution that using the null function.