Find smallest Eigenvalue and the corresponding eigenvector.

215 ビュー (過去 30 日間)
Eiman Hakimy
Eiman Hakimy 2022 年 6 月 9 日
編集済み: Torsten 2022 年 6 月 9 日
I need to write a program which computes the largest and the smallest (in terms of absolute value) eigenvalues using power method. I can find the largest one using the power method. But I have no idea how to find the smallest one using the power method.
How can I modify the power method so that it computes the smallest eigenvalue?
my power method algorithm :
1. Start
2. Define matrix X
3. Calculate Y = AX
4. Find the largest element in the magnitude of matrix Y and assign it to K.
5. Calculate fresh value X = (1/K) * Y
6. If [Kn – K(n-1)] > delta, go to step 3.
7. Stop.
Below is the coding :
function [ v d] = power_method( A )
% for finding the largest eigen value by power method
disp ( ' Enter the matrix whose eigen value is to be found')
% Calling matrix A
A = input ( ' Enter matrix A : \n')
% check for matrix A
% it should be a square matrix
[na , ma ] = size (A);
if na ~= ma
disp('ERROR:Matrix A should be a square matrix')
return
end
% initial guess for X..?
% default guess is [ 1 1 .... 1]'
disp('Suppose X is an eigen vector corresponding to largest eigen value of matrix A')
r = input ( 'Any guess for initial value of X? (y/n): ','s');
switch r
case 'y'
% asking for initial guess
X0 = input('Please enter initial guess for X :\n')
% check for initial guess
[nx, mx] = size(X0);
if nx ~= na || mx ~= 1
disp( 'ERROR: please check your input')
return
end
otherwise
X0 = ones(na,1);
end
%allowed error in final answer
t = input ( 'Enter the error allowed in final answer: ');
tol = t*ones(na,1);
% initialing k and X
k= 1;
X( : , 1 ) = X0;
%initial error assumption
err= 1000000000*rand(na,1);
% loop starts
while sum(abs(err) >= tol) ~= 0
X( : ,k+ 1 ) = A*X( : ,k); %POWER METHOD formula
% normalizing the obtained vector
[ v i ] = max(abs(A*X( : ,k+ 1 )));
E = X( : ,k+ 1 );
e = E( i,1);
X(:,k+1) = X(:,k+1)/e;
err = X( :,k+1) - X( :, k);% finding error
k = k + 1;
end
%display of final result
fprintf (' The largest eigen value obtained after %d itarations is %7.7f \n', k, e)
disp('and the corresponding eigen vector is ')
X( : ,k)
  2 件のコメント
Eiman Hakimy
Eiman Hakimy 2022 年 6 月 9 日
so which part i need to changes ? sorry because i'm still confuse. can you show which line i need to changes

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

採用された回答

John D'Errico
John D'Errico 2022 年 6 月 9 日
編集済み: John D'Errico 2022 年 6 月 9 日
Just compute the matrix
Ainv = inv(A);
Now use your code on the matrix Ainv. This works because the smallest eigenvalue is now the largest.
Will this faiil for a singular matrix A? Of course. But then you cannot use the power method there anyway.
So there is absolutely no need to modify your code. Just use it on a different matrix.
  2 件のコメント
Torsten
Torsten 2022 年 6 月 9 日
編集済み: Torsten 2022 年 6 月 9 日
d will be the smallest eigenvalue of A if you execute
A_input = inv(A);
[~, d] = power_method(A_input);
d = 1/d
But first try to understand the code you copied for the power method.

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

その他の回答 (1 件)

SALAH ALRABEEI
SALAH ALRABEEI 2022 年 6 月 9 日
You can find it here

カテゴリ

Find more on Linear Algebra in Help Center and File Exchange

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by