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

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

Doc

File size: 979 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 A = MatrixXd::Random(6,6);
11cout << "Here is a random 6x6 matrix, A:" << endl << A << endl << endl;
12
13EigenSolver<MatrixXd> es(A);
14cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
15cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
16
17complex<double> lambda = es.eigenvalues()[0];
18cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
19VectorXcd v = es.eigenvectors().col(0);
20cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
21cout << "... and A * v = " << endl << A.cast<complex<double> >() * v << endl << endl;
22
23MatrixXcd D = es.eigenvalues().asDiagonal();
24MatrixXcd V = es.eigenvectors();
25cout << "Finally, V * D * V^(-1) = " << endl << V * D * V.inverse() << endl;
26
27 return 0;
28}
Note: See TracBrowser for help on using the repository browser.