[Solved] Power method, eigenvalues.

44 ビュー (過去 30 日間)
Kamil
Kamil 2011 年 5 月 12 日
回答済み: Akankshya 2024 年 2 月 13 日
function l = ww(A,E)
n = length(A);
y = [];
x = [];
for i = 1:n % starting vector
x(i) = A(i,1);
end;
l = 0;
blad = E; % starting value of error
while blad>=E
for i = 1:n % A*x
y(i) = 0;
for j = 1:n
y(i) = y(i) + A(i,j)*x(j);
end;
end;
blad = l;
l = 0; % Rayleigh
m = 0;
for i = 1:n
l = l + x(i)*y(i);
m = m + x(i)*x(i);
end;
l = l/m; % eigenvalue
blad = abs(l - blad); % error
x = y;
end;
end
That's how I've tried to compute eigenvalues. It works for some matrices, but for:
A =
0 -0.3333 -0.3333
-0.3333 0 0.3333
0.6000 0.2000 0
it doesn't work. How can I fix that?
  7 件のコメント
Lorenzo Amabili
Lorenzo Amabili 2017 年 3 月 17 日
編集済み: Lorenzo Amabili 2017 年 3 月 17 日
@Kamil
@Teja Muppirala
how do you set E initially? I am sorry in case this question is silly but I am still new to this field. Thank you!
karim hamza
karim hamza 2017 年 4 月 29 日
i have an error [not enough input argument]

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

採用された回答

Teja Muppirala
Teja Muppirala 2011 年 5 月 13 日
Simple power iteration only works when there is a single dominant eigenvalue. The matrix
A =[ 0 -0.3333 -0.3333
-0.3333 0 0.3333
0.6000 0.2000 0];
has 3 eigenvalues,
-0.3333
0.1667 + 0.3249i
0.1667 - 0.3249i
with absolute values:
0.3333
0.3651
0.3651
As you can see, the dominant eigenvalue is not unique. That is why your algorithm fails to converge.
One way to fix this is by using shifts (you can read all about it on Google).
But why not just use MATLAB's built in eigevnalue solver, EIG?
eig(A)
  1 件のコメント
Kamil
Kamil 2011 年 5 月 13 日
Thank you, I forgot about that.
I didn't use EIG, because I'm studying Numerical Methods and I'm trying to exercise that way.

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

その他の回答 (3 件)

Andrew Newell
Andrew Newell 2011 年 5 月 12 日
While we wait for more information, here is a vectorized version of whatever your algorithm is doing:
function l = ww(A,E)
x = A(:,1);
l = 0;
blad = E; % starting value of error
while blad>=E
y = A*x;
blad = l;
l = x.*y; % Rayleigh
m = x.*x;
l = l/m; % eigenvalue
blad = abs(l - blad); % error
x = y;
end;
  2 件のコメント
devalaraju venkata naga amulya
devalaraju venkata naga amulya 2019 年 7 月 24 日
when i run the above code there is an error of input values A and E(in line function) can u help it with me im sorry im very new to the matlab
Dhruv Bhavsar
Dhruv Bhavsar 2020 年 8 月 28 日
Try calling the function in the command prompt even if you get the above mentioned error.
If it works then copy the function at the bottom of a new script and write the codes to be implemented above the function defined.
I have attached my code file for your reference.

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


Kamil
Kamil 2011 年 5 月 13 日
Are there any other methods of computing eigenvalues?

Akankshya
Akankshya 2024 年 2 月 13 日
function l = ww(A,E)
x = A(:,1);
l = 0;
blad = E; % starting value of error
while blad>=E
y = A*x;
blad = l;
l = x.*y; % Rayleigh
m = x.*x;
l = l/m; % eigenvalue
blad = abs(l - blad); % error
x = y;
end

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by