Find smallest Eigenvalue and the corresponding eigenvector.

94 vues (au cours des 30 derniers jours)
Eiman Hakimy
Eiman Hakimy le 9 Juin 2022
Modifié(e) : Torsten le 9 Juin 2022
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 commentaires
Torsten
Torsten le 9 Juin 2022
Modifié(e) : Torsten le 9 Juin 2022
Iterate for the largest eigenvalue of A^(-1) - it's the inverse of the smallest of A.
Eiman Hakimy
Eiman Hakimy le 9 Juin 2022
so which part i need to changes ? sorry because i'm still confuse. can you show which line i need to changes

Connectez-vous pour commenter.

Réponse acceptée

John D'Errico
John D'Errico le 9 Juin 2022
Modifié(e) : John D'Errico le 9 Juin 2022
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 commentaires
Eiman Hakimy
Eiman Hakimy le 9 Juin 2022
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 le 9 Juin 2022
Modifié(e) : Torsten le 9 Juin 2022
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.

Connectez-vous pour commenter.

Plus de réponses (1)

SALAH ALRABEEI
SALAH ALRABEEI le 9 Juin 2022
You can find it here

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by