Finding eigen vectors of a matrix

1 次查看(过去 30 天)
Pouyan Msgn
Pouyan Msgn 2019-7-19
回答: infinity 2019-7-25
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 个评论
infinity
infinity 2019-7-19
Hello,
In version 2018a, there is no any error. It get this
>> V
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
D =
1.0000 0 0
0 -0.1907 0
0 0 -9.9134
Maybe since your version is different.
But, you can try another approach like Maltab suggestion, for example,
For non-symmetric or complex A, the choices are 'LM', 'SM', 'LR', 'SR', 'LI' or 'SI'.
Since, in your case, C is not symmetric matrix.
Pouyan Msgn
Pouyan Msgn 2019-7-19
So you mean that C must be equal to C' which is not in this case? I use 2015R

请先登录,再进行评论。

回答(2 个)

infinity
infinity 2019-7-25
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
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 个评论
Rik
Rik 2019-7-25
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by