Finding eigen vectors of a matrix

10 views (last 30 days)
Pouyan Msgn
Pouyan Msgn on 19 Jul 2019
Answered: infinity on 25 Jul 2019
Hi I will use [V,D]=eigs(C,3,'LA') to get the three first eigenvectors of matrix C:
clear all
clc
N=5;
L=1;
h=L/N;
C=zeros(N+1,N+1);
C(1,1)=-1; C(1,2)=1;
C(N+1,N+1)=1;
A1=1/(h^2); A2=-2/(h^2); A3=1/(h^2);
for i=1:N-1
C(i+1,i)=A1;
C(i+1,i+1)=A2;
C(i+1,i+2)=A3;
end
M=C(2:N,2:N);
[V,D]=eigs(C,3,'LA');
But I get this error:
Error using eigs/checkInputs (line 864)
Eigenvalue range sigma must be a valid 2-element string.
For real symmetric A, the choices are 'LM', 'SM', 'LA', 'SA' or 'BE'.
For non-symmetric or complex A, the choices are 'LM', 'SM', 'LR', 'SR', 'LI' or 'SI'.
Error in eigs (line 93)
[A,Amatrix,isrealprob,issymA,n,B,classAB,k,eigs_sigma,whch, ...
Error in partiel3 (line 17)
[V,D]=eigs(C,3,'LA');
  2 Comments
Pouyan Msgn
Pouyan Msgn on 19 Jul 2019
So you mean that C must be equal to C' which is not in this case? I use 2015R

Sign in to comment.

Answers (2)

infinity
infinity on 25 Jul 2019
Thank for @Rik 's comment. I have moved my comment to this section.
Since Matlab response with these lines
Error using eigs/checkInputs (line 864)
Eigenvalue range sigma must be a valid 2-element string.
For real symmetric A, the choices are 'LM', 'SM', 'LA', 'SA' or 'BE'.
For non-symmetric or complex A, the choices are 'LM', 'SM', 'LR', 'SR', 'LI' or 'SI'.
It could be understood that
the function "eigs/checkInputs" in Matlab 2015R realize that your matrix C is not symmetric and you choice "LA" approach to find the eigvalue and eigenvector. This choise is not compatible with the type of C. Matlab also suggested you use appropriate method like "LM", "SM", .etc.
So, for your current version, you should change a bit like this
[V,D]=eigs(C,3,'LM'); % of SM, etc

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Jul 2019
Hi,
It works as expected. Just restart your MATLAB and re-run your code:
>> [V,D]=eigs(C,3,'LA')
V =
0.0922 -0.6679 0.0391
0.1845 -0.5406 -0.3489
0.2841 -0.4091 -0.5986
0.3951 -0.2745 -0.6109
0.5219 -0.1378 -0.3810
0.6695 0 0
D =
1.0000 0 0
0 -0.1907 0
0 0 -9.9134
  1 Comment
Rik
Rik on 25 Jul 2019
Why would restarting Matlab do anything? The code already starts with the harsh 'clear all'. Have you tried this code on R2015b?
Since Trung VO DUY's comment points at the source of the issue and suggests a way to solve the problem, I think it should be moved to the answer section.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!