Fail to compute eigenvalues for a simple 3x3 companion matrix for root finding
Submitted by Gary Tan
Assigned to Nobody
Link to original bugzilla bug (#1557)
Version: 3.3 (current stable)
Description
The following
#include <Eigen/Eigenvalues>
#include <iostream>
using namespace Eigen;
using namespace std;
int main() {
Matrix3d A;
A << 0, 0, 0, 1, 0, 0.5887907064808635127, 0, 1, 0;
cout << "Here is a random 3x3 matrix, A:" << endl << A << endl << endl;
EigenSolver<MatrixXd> es(A);
cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
cout << "The matrix of eigenvectors, V, is:" << endl
<< es.eigenvectors() << endl
<< endl;
complex<double> lambda = es.eigenvalues()[0];
cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
VectorXcd v = es.eigenvectors().col(0);
cout << "If v is the corresponding eigenvector, then lambda * v = " << endl
<< lambda * v << endl;
cout << "... and A * v = " << endl
<< A.cast<complex<double> >() * v << endl
<< endl;
MatrixXcd D = es.eigenvalues().asDiagonal();
MatrixXcd V = es.eigenvectors();
cout << "Finally, V * D * V^(-1) = " << endl << V * D * V.inverse() << endl;
return 0;
}
produces
Here is a random 3x3 matrix, A:
0 0 0
1 0 0.588791
0 1 0
The eigenvalues of A are:
(0,0)
(0,0)
(0,0)
The matrix of eigenvectors, V, is:
(1,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
(0,0) (0,0) (0,0)
Consider the first eigenvalue, lambda = (0,0)
If v is the corresponding eigenvector, then lambda * v =
(0,0)
(0,0)
(0,0)
... and A * v =
(0,0)
(1,0)
(0,0)
Finally, V * D * V^(-1) =
(-nan,-nan) (-nan,-nan) (-nan,-nan)
(-nan,-nan) (-nan,-nan) (-nan,-nan)
(-nan,-nan) (-nan,-nan) (-nan,-nan)
However, it's expected to obtain
sqrt(0.5887907064808635127) = 0.76733
and its opposite.
Thanks,
Gary