Power method to determine largest eigenvalue and corresponding eigenvector had some wrong
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yen Hung-lu
el 19 de Nov. de 2022
Comentada: Yen Hung-lu
el 20 de Nov. de 2022
I used MATLAB eig function to check answer, the answer should be 3.3876 for largest eigenvalue and [-0.371748 0.601501 -0.601501 0.371748] for the corresponding eigenvector. I have no idea why it is wrong.
Thanks for helping.
Code here:
% Matlab eig function
clc;clear
A = [1.7696 -1 0 0
-1 1.7696 -1 0
0 -1 1.7696 -1
0 0 -1 1.7696 ];
[eigvec,eigval] = eig(A);
for i=1:4
fprintf("Eigenvalue %f, corresponding eigenvector:[%f %f %f %f]\n",eigval(i,i),eigvec(:,i))
end
fprintf("\n")
%power method
[powval,powvec] = powereig(A,10^(-6));
fprintf("The largest eigenvalue and its corresponding eigenvector by power method:\n")
fprintf("Eigenvalue:%f\n",powval)
fprintf("Corresponding vector:[%f %f %f %f]\n",powvec)
function [eval, evect] = powereig(A,es)
n=length(A);
evect=ones(n,1);eval=1;iter=0;ea=100; %initialize
tol = es;
while(1)
evalold=eval; %save old eigenvalue value
evectold = evect; %save old eigenvalue vector
evect=A*evect; %determine eigenvector as [A]*{x)
eval=max(abs(evect)); %determine new eigenvalue
evect=evect./eval; %normalize eigenvector to eigenvalue
iter=iter+1;
if eval~=0, ea = abs((eval-evalold)/eval)*100; end
if ea<=es || norm(evect - evectold,2) <= tol
break
end
end
end
0 comentarios
Respuesta aceptada
John D'Errico
el 19 de Nov. de 2022
Editada: John D'Errico
el 19 de Nov. de 2022
I would claim you have two problems here. One is a pretty common mistake, the other more subtle.
Do you understand that eig normalizes the eigenvectors, to have a unit 2-norm?
V = [1.000000 -0.618034 -0.618034 1.000000];
V./norm(V)
And indeed, that is the vector corresponding to the second largest eigenvalue. So the code worked. You just needed to normalize the vector.
Still, it looks like your power method did not find the largest eigenvalue however. But that is not immediately relevant, since your code did work, in a sense. However, why did your method not find the largest eigenvalue/eigenvector pair?
The answer is a subtle one. In fact, if you look at the actual eigenvector, it turns out to be orthogonal to the starting vector you used. You started with a vector of all ones. That is a really bad idea in this case, because made up examples like this will often cause problems.
Instead, you would have been far better off using a randomly chosen vector of the correct length. That makes the probability equal to zero of starting with a vector orthogonal to one of your eigenvectors.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!