Different eigenvectors calculated from Matlab and Python
85 次查看(过去 30 天)
显示 更早的评论
I was studying an eigenvector problem and found Matlab and Python produce different eigenvectors for the same matrix. (The matrix does not have unique eigenvectors) R has the same result with Python. I was wondering the reason of this issue. Thank you!
An example of the matrix is
1 个评论
Star Strider
2021-12-25
Calculating them manually will also produce different eigenvectors. Eigenvectors are not unique.
回答(2 个)
John D'Errico
2021-12-25
编辑:John D'Errico
2021-12-25
Look at it this way. THERE IS NO ISSUE. While you say that R and Python produce the same result, does it matter? (It possibly means that R and Python may both use the same external tool to compute the eigenvalues and eigenvectors.)
You say yourself that the eigenvalues are not unique, because of the eigenvalue of multiplicity 2. But that means MATLAB, or ANY code, could arbitrarily have made a different choice.
A = [1 .4 .4; .4 1 -.4; .4 -.4 1]
[V,D] = eig(A)
The second and third columns are the eigenvectors that correspond to the replicated eigenvalues. Are there different eigenvectors possible? Of course. Rotate them any way you wish.
V23 = V(:,2:3)
lambda = D(2,2)
format long g
A*V23/1.4
As you can see, we get back V23 by this operation. But suppose I rotate the vectors? For example...
rot = @(theta) [cos(theta) sin(theta);-sin(theta) cos(theta)];
V23hat = V23*rot(pi/4)
So what you see are a completely different eigenvector pair. But they are still validly eigenvectors.
A*V23hat/lambda
As you can see, they still work nicely as eigenvectors for that eigenvalue.
Again. There is no issue. The only issue lies in your appreciation of what it means to be non-unique.
Matt J
2021-12-25
编辑:Matt J
2021-12-25
Eigenvectors are not unique.
Especially in a symmetric matrix with eigenvalues having multiplicity >1, as is the case here,
eig([1.0000 0.4000 0.4000
0.4000 1.0000 -0.4000
0.4000 -0.4000 1.0000])
Because this matrix is symmetric, the eigenvalue λ=1.4 is guaranteed to have at least two linearly independent eigenvectors. Moreover, every linear combination of those eigenvectors is also an eigenvector for λ=1.4.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!