Power method to determine largest real eigenvalue does not converge

I have written a function as per the pseudocode to determine the maximum eigenvalue of a given nxn matrix given a specified tolerance value. Unfortunately my anwser does not converge. The vector seems to be unchanged after the first 50-60 iterations so i attempted to caclulate the eigenvalue at the 55th iteration by calculating the infinite norm of the corresponding vector. The anwser is not close at all. Any assistance would be appreciated (i have attached the pseudocode as a PNG).
% M = randi(15,5)/10;
% A = M'*M;
A = [1 2 1; 6 -1 0; -1 -2 -1];
[V,D] = eig(A)
[e,v]= power_method(A,1e-4)
function [eigen_value,vector]= power_method(A,tol)
% Write you code here
x0 = randi([1,5],length(A),1); %arbitrary vector x0
vector = x0; %start with arbitrary vector x0
iter = 1; %iteration counter
while 1
vector_old = vector;
vector = A*vector;
eigen_value = norm(vector,inf);
vector = vector/max(vector);
error = norm(vector - vector_old);
if error<tol
break
end
iter = iter + 1;
end
iter
error
end

1 件のコメント

Umar Mirza
Umar Mirza 2021 年 3 月 28 日
Did some more investigation and figured out that my A matrix is singular. Method seems to work fine for a non-singular matrix. I'm assuming that the power method only works for non-singular matrices, ie. invertible?

サインインしてコメントする。

回答 (1 件)

Bruno Luong
Bruno Luong 2021 年 3 月 28 日

1 投票

The png is not correct if A has negative largest eigan (absolute) value
Try this
A = [1 2 1; 6 -1 0; -1 -2 -1];
[V,D] = eig(A)
[e,v]= power_method(A,1e-4)
function [eigen_value,vector]= power_method(A,tol)
% Write you code here
x0 = randi([1,5],length(A),1); %arbitrary vector x0
vector = x0; %start with arbitrary vector x0
iter = 1; %iteration counter
while 1
vector_old = vector;
vector = A*vector;
[~,imax] = max(abs(vector));
maxv = vector(imax);
vector = vector/maxv;
error = norm(vector - vector_old);
if error<tol
break
end
iter = iter + 1;
end
eigen_value = maxv
iter
end

2 件のコメント

Umar Mirza
Umar Mirza 2021 年 3 月 28 日
編集済み: Umar Mirza 2021 年 3 月 28 日
Thanks. Is the comment i made to my original post above valid?
Bruno Luong
Bruno Luong 2021 年 3 月 28 日
No

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeEigenvalues & Eigenvectors についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 3 月 28 日

コメント済み:

2021 年 3 月 28 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by