Find smallest Eigenvalue and the corresponding eigenvector.

98 次查看(过去 30 天)
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