Line | |
---|
1 | #include <Eigen/Dense>
|
---|
2 | #include <iostream>
|
---|
3 |
|
---|
4 | using namespace Eigen;
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 | int main(int, char**)
|
---|
8 | {
|
---|
9 | cout.precision(3);
|
---|
10 | MatrixXd X = MatrixXd::Random(5,5);
|
---|
11 | MatrixXd A = X + X.transpose();
|
---|
12 | cout << "Here is a random symmetric 5x5 matrix, A:" << endl << A << endl << endl;
|
---|
13 |
|
---|
14 | SelfAdjointEigenSolver<MatrixXd> es(A);
|
---|
15 | cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
|
---|
16 | cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
|
---|
17 |
|
---|
18 | double lambda = es.eigenvalues()[0];
|
---|
19 | cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
|
---|
20 | VectorXd v = es.eigenvectors().col(0);
|
---|
21 | cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
|
---|
22 | cout << "... and A * v = " << endl << A * v << endl << endl;
|
---|
23 |
|
---|
24 | MatrixXd D = es.eigenvalues().asDiagonal();
|
---|
25 | MatrixXd V = es.eigenvectors();
|
---|
26 | cout << "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.