xref: /aosp_15_r20/external/eigen/doc/examples/TutorialLinAlgSelfAdjointEigenSolver.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li #include <iostream>
2*bf2c3715SXin Li #include <Eigen/Dense>
3*bf2c3715SXin Li 
4*bf2c3715SXin Li using namespace std;
5*bf2c3715SXin Li using namespace Eigen;
6*bf2c3715SXin Li 
main()7*bf2c3715SXin Li int main()
8*bf2c3715SXin Li {
9*bf2c3715SXin Li    Matrix2f A;
10*bf2c3715SXin Li    A << 1, 2, 2, 3;
11*bf2c3715SXin Li    cout << "Here is the matrix A:\n" << A << endl;
12*bf2c3715SXin Li    SelfAdjointEigenSolver<Matrix2f> eigensolver(A);
13*bf2c3715SXin Li    if (eigensolver.info() != Success) abort();
14*bf2c3715SXin Li    cout << "The eigenvalues of A are:\n" << eigensolver.eigenvalues() << endl;
15*bf2c3715SXin Li    cout << "Here's a matrix whose columns are eigenvectors of A \n"
16*bf2c3715SXin Li         << "corresponding to these eigenvalues:\n"
17*bf2c3715SXin Li         << eigensolver.eigenvectors() << endl;
18*bf2c3715SXin Li }
19