Intel MKL与LAPACK(numpy实现)矩阵对角化结果差异问询
Great question! This is a super common point of confusion when working with eigenvalue problems, so let's break down exactly what's happening here.
1. Eigenvectors Aren't Unique—They Live in Subspaces
First, a key linear algebra fact: eigenvectors are not uniquely determined by their eigenvalues. For any eigenvalue λ, all vectors that satisfy ( A\mathbf{x} = \lambda\mathbf{x} ) form a subspace called the eigenspace for λ. Any non-zero linear combination of vectors in this subspace is also a valid eigenvector for λ.
This is especially critical for repeated eigenvalues (like the eigenvalue 0 in your case, which has multiplicity 2). The eigenspace here is 2-dimensional, meaning there are infinitely many possible pairs of basis vectors that can span this space. Different numerical libraries just pick different valid bases—and both are correct.
2. Let's Verify Your Results
Your matrix is:
A = [[0,-2,-2,0], [-2,0,0,-2], [-2,0,0,-2], [0,-2,-2,0]]
Both libraries correctly find eigenvalues: -4, 0, 0, 4. Now let's look at the eigenvectors:
- For the unique eigenvalues (-4 and 4):
- MKL's eigenvector for -4 is
[0.5, 0.5, 0.5, 0.5]; NumPy's is identical. For 4, MKL's is[0.5, -0.5, -0.5, 0.5]and NumPy's is[-0.5, 0.5, 0.5, -0.5]—this is just a scalar multiple (-1x), which is totally allowed (multiplying an eigenvector by any non-zero scalar gives another valid eigenvector).
- MKL's eigenvector for -4 is
- For the repeated eigenvalue 0:
- MKL uses the basis vectors
[0.5, -0.5, 0.5, -0.5]and[-0.5, -0.5, 0.5, 0.5]. - NumPy uses
[0.707107, 0, 0, -0.707107](which is ( [1/\sqrt{2}, 0, 0, -1/\sqrt{2}] )) and[0, 0.707107, -0.707107, 0]( ( [0, 1/\sqrt{2}, -1/\sqrt{2}, 0] ) ).
- MKL uses the basis vectors
Both pairs of vectors span the same 2-dimensional eigenspace for λ=0—you can even express MKL's basis vectors as linear combinations of NumPy's, and vice versa. And if you multiply A by any of these vectors, you'll get the zero vector (which is ( 0 \times \mathbf{x} )), so all are valid eigenvectors.
3. Library Implementation Differences
MKL and LAPACK (the underlying library for NumPy's eigenvalue functions) use slightly different algorithms or orthogonalization strategies when computing eigenvectors for repeated eigenvalues:
- They might handle the Schur decomposition (a core step in eigenvalue solvers) differently for degenerate subspaces.
- They could use different orthogonalization methods (like modified Gram-Schmidt vs. Householder reflections) to produce orthonormal eigenvectors, leading to different valid basis choices.
These differences are intentional and don't mean either library is wrong—they're just choosing different valid representations of the same eigenspace.
Final Takeaway
As long as:
- The eigenvalues match (which they do), and
- Each eigenvector satisfies ( A\mathbf{x} = \lambda\mathbf{x} ) (which both sets do),
both results are completely correct. The non-uniqueness of eigenvectors is a fundamental property of linear algebra, and numerical libraries will naturally pick different valid bases based on their internal algorithms.
内容的提问来源于stack exchange,提问作者Juhee Lee

