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

回答(2 个)

John D'Errico
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]
A = 3×3
1.0000 0.4000 0.4000 0.4000 1.0000 -0.4000 0.4000 -0.4000 1.0000
[V,D] = eig(A)
V = 3×3
-0.5774 -0.1543 0.8018 0.5774 -0.7715 0.2673 0.5774 0.6172 0.5345
D = 3×3
0.2000 0 0 0 1.4000 0 0 0 1.4000
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)
V23 = 3×2
-0.1543 0.8018 -0.7715 0.2673 0.6172 0.5345
lambda = D(2,2)
lambda = 1.4000
format long g
A*V23/1.4
ans = 3×2
-0.154303349962092 0.801783725737273 -0.771516749810459 0.267261241912424 0.617213399848368 0.534522483824849
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)
V23hat = 3×2
-0.676055654631837 0.457837764395845 -0.734526962094594 -0.356562489085367 0.0584713074627576 0.814400253481212
So what you see are a completely different eigenvector pair. But they are still validly eigenvectors.
A*V23hat/lambda
ans = 3×2
-0.676055654631837 0.457837764395845 -0.734526962094594 -0.356562489085367 0.0584713074627575 0.814400253481212
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.
  1 个评论
Ruihong Jiang
Ruihong Jiang 2021-12-27
Thank you John! I'm curious about what external tools Matlab/Python/R uses for calculating the eigenvectors.

请先登录,再进行评论。


Matt J
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])
ans = 3×1
0.2000 1.4000 1.4000
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.

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by