Power method to determine largest eigenvalue and corresponding eigenvector had some wrong
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Linear Algebra in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!