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 A = MatrixXd::Random(6,6);
|
---|
11 | cout << "Here is a random 6x6 matrix, A:" << endl << A << endl << endl;
|
---|
12 |
|
---|
13 | EigenSolver<MatrixXd> es(A);
|
---|
14 | cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
|
---|
15 | cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
|
---|
16 |
|
---|
17 | complex<double> lambda = es.eigenvalues()[0];
|
---|
18 | cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
|
---|
19 | VectorXcd v = es.eigenvectors().col(0);
|
---|
20 | cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
|
---|
21 | cout << "... and A * v = " << endl << A.cast<complex<double> >() * v << endl << endl;
|
---|
22 |
|
---|
23 | MatrixXcd D = es.eigenvalues().asDiagonal();
|
---|
24 | MatrixXcd V = es.eigenvectors();
|
---|
25 | cout << "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.