필터 지우기
필터 지우기

Find smallest Eigenvalue and the corresponding eigenvector.

조회 수: 52 (최근 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
Torsten
Torsten 2022년 6월 9일
편집: Torsten 2022년 6월 9일
Iterate for the largest eigenvalue of A^(-1) - it's the inverse of the smallest of A.
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
Eiman Hakimy
Eiman Hakimy 2022년 6월 9일
okay so i need to uses the inverse method right ?
so you says that's i don't need to modify my code so which one that's i need to changes to inverse method ?
sorry if i'm asking question too much because i'm still confuse with this. @John D'Errico
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

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by