xref: /aosp_15_r20/external/eigen/doc/snippets/ComplexEigenSolver_compute.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li MatrixXcf A = MatrixXcf::Random(4,4);
2*bf2c3715SXin Li cout << "Here is a random 4x4 matrix, A:" << endl << A << endl << endl;
3*bf2c3715SXin Li 
4*bf2c3715SXin Li ComplexEigenSolver<MatrixXcf> ces;
5*bf2c3715SXin Li ces.compute(A);
6*bf2c3715SXin Li cout << "The eigenvalues of A are:" << endl << ces.eigenvalues() << endl;
7*bf2c3715SXin Li cout << "The matrix of eigenvectors, V, is:" << endl << ces.eigenvectors() << endl << endl;
8*bf2c3715SXin Li 
9*bf2c3715SXin Li complex<float> lambda = ces.eigenvalues()[0];
10*bf2c3715SXin Li cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
11*bf2c3715SXin Li VectorXcf v = ces.eigenvectors().col(0);
12*bf2c3715SXin Li cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
13*bf2c3715SXin Li cout << "... and A * v = " << endl << A * v << endl << endl;
14*bf2c3715SXin Li 
15*bf2c3715SXin Li cout << "Finally, V * D * V^(-1) = " << endl
16*bf2c3715SXin Li      << ces.eigenvectors() * ces.eigenvalues().asDiagonal() * ces.eigenvectors().inverse() << endl;
17