I want to find the corresponding eigenvector of the eigenvalue of minimum magnitude of a matrix U. What is the easiest way to do this?
Currently I am using the algorithm
[evecs, D] = eigs(U);
evals = diag(D);
smallesteig = inf;
for k = 1:length(evals)
if (evals(k) < smallesteig)
smallesteig = evals(k);
vec = evecs(:, k);
end
end
Is there a more efficient way of doing this?
There is a very simple shorthand for this: [V,D] = eigs(U,1,'SM').
If you look at the eigs documentation, it states:
EIGS(A,K,SIGMA) and EIGS(A,B,K,SIGMA) return K eigenvalues. If SIGMA is:
'LM' or 'SM' - Largest or Smallest Magnitude
For real symmetric problems, SIGMA may also be:
'LA' or 'SA' - Largest or Smallest Algebraic
'BE' - Both Ends, one more from high end if K is odd
For nonsymmetric or complex problems, SIGMA may also be:
'LR' or 'SR' - Largest or Smallest Real part
'LI' or 'SI' - Largest or Smallest Imaginary part
So, [V,D] = eigs(U,1,'SM') returns the eigenvector and value for the 1st eigenvalue of U when sorted by Smallest Magnitude.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With