source: pacpussensors/trunk/Vislab/lib3dv/eigen/Eigen-install/doc/snippets/compile_SelfAdjointEigenSolver_SelfAdjointEigenSolver_MatrixType.cpp@ 136

Last change on this file since 136 was 136, checked in by ldecherf, 7 years ago

Doc

File size: 996 bytes
Line 
1#include <Eigen/Dense>
2#include <iostream>
3
4using namespace Eigen;
5using namespace std;
6
7int main(int, char**)
8{
9 cout.precision(3);
10 MatrixXd X = MatrixXd::Random(5,5);
11MatrixXd A = X + X.transpose();
12cout << "Here is a random symmetric 5x5 matrix, A:" << endl << A << endl << endl;
13
14SelfAdjointEigenSolver<MatrixXd> es(A);
15cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
16cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
17
18double lambda = es.eigenvalues()[0];
19cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
20VectorXd v = es.eigenvectors().col(0);
21cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
22cout << "... and A * v = " << endl << A * v << endl << endl;
23
24MatrixXd D = es.eigenvalues().asDiagonal();
25MatrixXd V = es.eigenvectors();
26cout << "Finally, V * D * V^(-1) = " << endl << V * D * V.inverse() << endl;
27
28 return 0;
29}
Note: See TracBrowser for help on using the repository browser.