Eigenvalues by power method

조회 수: 28 (최근 30일)
Sofy
Sofy 2022년 6월 1일
편집: John D'Errico 2024년 4월 1일 19:39
hello everyone, is there's anyone could help me to solve this problem using matlab code
  댓글 수: 3
James Tursa
James Tursa 2022년 6월 1일
What have you done so far? What specific problems are you having with your code?
Sofy
Sofy 2022년 6월 2일
actually it wasn't home work I'm just try to know the way of coding this issue coz I'm beginner in matlab

댓글을 달려면 로그인하십시오.

채택된 답변

Hiro Yoshino
Hiro Yoshino 2022년 6월 1일
See eig and eigs. Looks like eigs is more suitable for you though ...
I suppose u represents an eigen vector but the initial point seems to have to be u_0. In this case you may need to keep the norms of the eigen vectors <= 1.
  댓글 수: 3
Hiro Yoshino
Hiro Yoshino 2022년 6월 1일
Agreed
Sofy
Sofy 2022년 6월 1일
Thx for your comments

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kashish
Kashish 2024년 4월 1일 10:13
편집: Voss 2024년 4월 1일 16:29
function [m,y_final]=power_method(A,x);
m=0;
n=length(x);
y_final=zeros(n,1);
y_final=x;
tol=1e-3;
while(1)
mold=m;
y_final=A*y_final;
m=max(y_final);
y_final=y_final/m;
if (m-mold)<tol
break;
end
end
end
  댓글 수: 1
John D'Errico
John D'Errico 2024년 4월 1일 16:08
편집: John D'Errico 2024년 4월 1일 19:39
I'm sorry, but this code is terribly poor as an answer to the question. It will fail far too often. (I'm not even sure it will ever work correctly. My guess is, under a specific set of circumstances, it MAY produce an estimate of an eigenvalue.) In fact, there are multiple flaws in the code I can see. If I tell you what you did wrong, you won't learn anything. You need to spend some time understanding what you did.
A = rand(3) - 3*eye(3)
A =
-2.1537 0.59001 0.50669
0.45027 -2.5355 0.19874
0.08948 0.47973 -2.5368
eig(A)
ans =
-1.6144 + 0i
-2.8058 + 0.13422i
-2.8058 - 0.13422i
I've created a simple 3x3 matrix. Surely power_method might find even one of the eigenvalues? How hard can that be? Yes, two of the eigenvalues were complex, but the other is not.
power_method(A,ones(3,1))
ans =
-1.057
I would suggest you consider why the code failed, even on that simple example. If it bothers you that my example matrix had complex eigenvalues, then I'll do this:
A = A + A'
A =
-4.3073 1.0403 0.59617
1.0403 -5.071 0.67847
0.59617 0.67847 -5.0736
That simple operation insures all of the eigenvalues are real. We can test that claim easily enough.
eig(A)
ans =
-5.8925
-5.387
-3.1725
So purely real eigenvalues. But surely your code should work now?
power_method(A,ones(3,1))
ans =
-2.6709
So strange. It still fails miserably.
Ok, maybe your code will only work on symmetric, positive definite matrices? Anyway, that was what was requested in the homework assignment as posted. Sigh. It does not. I can swap the signs on the eigenvalues of A simply enough.
A = -A
A =
4.3073 -1.0403 -0.59617
-1.0403 5.071 -0.67847
-0.59617 -0.67847 5.0736
eig(A)
ans =
3.1725
5.387
5.8925
Surely with 3 positive eigenvalues on a symmetric matrix, surely it will work?
power_method(A,ones(3,1))
ans =
5.2965
How strange. It still fails completely, even on what should be a trivially simple problem now. It came a little closer this time, but really...
Again, you should seriously look at your code, and think about what happened, why it failed. Use the debugger, running on that last example matrix and think about why your code is failing.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by