Accessing eigenvalues in eigen3
c++, eigen, linear-algebra, matrix
Solution
The solution appeared to be quite trivial:
EigenSolver<MatrixXd> eigensolver(A);
cout << "tell me something" << endl;
complex<double> E;
cout << "tell me something more" << endl;
for(int i = 0; i < A.rows(); ++i){
E = eigensolver.eigenvalues().col(0)[i];
cout << E << endl;
}
Problem
I am trying to set up eigen3 eigenvalue solver and it looks like I faced some complications. The code compiles well, but then fails at some point. The piece of code that fails is ``` EigenSolver<MatrixXd> eigensolver(A); cout << "tell me something" << endl; Matrix<complex<double>, -1, 1, 0, -1, 1> E = eigensolver.eigenvalues(); cout << "tell me something more" << endl; cout << E; ``` and the output with an error message: ``` tell me something tell me something more (3.5,1.93649) class_out: /usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h:407: Eigen::internal::traits<Derived>::Scalar &Eigen::DenseCoeffsBase<Derived, 1>::operator()(Eigen::internal::traits<Derived>::Index) [with Derived = Eigen::Matrix<std::complex<double>, -1, 1, 0, -1, 1>]: Assertion `index >= 0 && index < size()' failed. (3.5,-1.93649)Aborted ``` This looks a bit weird, but it doesn't look like it's an issue of the `<<` operator, as ordinary ``` cout << eigensolver.eigenvalues(); ``` works fine as well as `cout` for an ordinary matrix. Also, I've checked eigenvalues of A with Mathematica and I got exactly (3.5,1.93649) and (3.5,-1.93649). Does anyone know why this is happening, or maybe someone could suggest other way to access eigenvalues?