Different eigenvectors calculated from Matlab and Python
62 views (last 30 days)
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
John D'Errico on 25 Dec 2021
Edited: John D'Errico on 25 Dec 2021
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
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.
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 on 25 Dec 2021
Edited: Matt J on 25 Dec 2021
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.