Rev | Line | |
---|
[136] | 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 matrix, A:" << endl << A << endl;
|
---|
| 13 | X = MatrixXd::Random(5,5);
|
---|
| 14 | MatrixXd B = X * X.transpose();
|
---|
| 15 | cout << "and a random postive-definite matrix, B:" << endl << B << endl << endl;
|
---|
| 16 |
|
---|
| 17 | GeneralizedSelfAdjointEigenSolver<MatrixXd> es(A,B);
|
---|
| 18 | cout << "The eigenvalues of the pencil (A,B) are:" << endl << es.eigenvalues() << endl;
|
---|
| 19 | cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
|
---|
| 20 |
|
---|
| 21 | double lambda = es.eigenvalues()[0];
|
---|
| 22 | cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
|
---|
| 23 | VectorXd v = es.eigenvectors().col(0);
|
---|
| 24 | cout << "If v is the corresponding eigenvector, then A * v = " << endl << A * v << endl;
|
---|
| 25 | cout << "... 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.