Java Hipparchus Eigenvector 和 C++ Eigen Eigenvector 有不同的结果

Java Hipparchus Eigenvector and C++ Eigen Eigenvector have different results

在比较 Java Hipparchus 和 C++ Eigen 的特征向量结果时,我得到了不同的结果。它们大部分被转置以及不匹配的 2 个元素。为什么库返回不同的值?

Java喜帕恰斯

import org.hipparchus.linear.Array2DRowRealMatrix;
import org.hipparchus.linear.EigenDecomposition;
import org.hipparchus.linear.RealVector;
...
double[][] example_matrix = {
  { 1, 2, 3 },
  { 3, 2, 1 },
  { 2, 1, 3 }
};
RealMatrix P = new Array2DRowRealMatrix(example_matrix , true);
EigenDecomposition eigenDecomposition = new EigenDecomposition(P);
RealVector[] eigenvectors = new RealVector[3];
for (int i = 0; i < 3; i++) {
  System.out.println(eigenDecomposition.getEigenvector(i));
}

// prints:
// {-0.7641805281; 0.6105725033; 0.2079166628}
// {0.5776342875; 0.5776342875; 0.5776342875}
// {-0.0235573892; -0.9140029063; 0.6060826741}

C++ 本征

Eigen::Matrix<double, 3, 3> matrix;
matrix <<
    1, 2, 3,
    3, 2, 1,
    2, 1, 3;
Eigen::EigenSolver<Eigen::Matrix<double, 3, 3>> eigen_decomposition{ matrix };
eigen_decomposition.compute(matrix, true);
const auto eigen_vectors = eigen_decomposition.eigenvectors().real();
std::cout << eigen_vectors.matrix() << "\n"

// prints:
// -0.764181    0.57735 -0.0214754
//  0.610573    0.57735  -0.833224
//  0.207917    0.57735   0.552518

虽然不完全相同,但两者的结果实际上都是正确的:

  • Java喜帕恰斯中,特征向量未归一化(向量范数不是 1!):这对于 norm is approximately 1.10. If you normalise it then you will see that it corresponds to the last column of the results Eigen gives you. Physically this does not matter as any scalar multiple of an eigenvector is again an eigenvector. Instead the library seems to normalise the matrix spanned by the eigenvectors: The magnitude of the determinant seems to correspond to unity 的最后一个尤为明显。行列式为 1 的矩阵保留了体积,因此这似乎是一个合乎逻辑的选择。

  • 另一方面,特征特征向量seem to be normalised。您绘制的矩阵为您提供 特征向量作为列 。归一化单个特征向量对我来说似乎是一个同样合理的选择。