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

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

Doc

File size: 1005 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 matrix, A:" << endl << A << endl;
13X = MatrixXd::Random(5,5);
14MatrixXd B = X * X.transpose();
15cout << "and a random postive-definite matrix, B:" << endl << B << endl << endl;
16
17GeneralizedSelfAdjointEigenSolver<MatrixXd> es(A,B);
18cout << "The eigenvalues of the pencil (A,B) are:" << endl << es.eigenvalues() << endl;
19cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
20
21double lambda = es.eigenvalues()[0];
22cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
23VectorXd v = es.eigenvectors().col(0);
24cout << "If v is the corresponding eigenvector, then A * v = " << endl << A * v << endl;
25cout << "... and lambda * B * v = " << endl << lambda * B * v << endl << endl;
26
27 return 0;
28}
Note: See TracBrowser for help on using the repository browser.