rotating_image
rotating_image

Reputation: 3076

GeneralizedEigenSolver not giving eigenvectors in Eigen library

I am new to the Eigen library and trying to solve a generalized eigen value problem. As per the documentation of the GeneralizedEigenSolver template class in Eigen library here I am able to get the eigen values but not the eigen vectors. Seems like the eigenvectors() member function is not implemented. Is there any other way I can generate the eigen vectors once I know the eigen values.I am using Eigen 3.2.4.

Upvotes: 1

Views: 2299

Answers (2)

Avi Ginsburg
Avi Ginsburg

Reputation: 10596

It doesn't appear to be implemented yet. At the end of the compute function there is:

 m_eigenvectorsOk = false;//computeEigenvectors;

indicating that they're not actually calculated. Additionally, the eigenvectors() function is commented out and looks like (note the TODO):

//template<typename MatrixType>
//typename GeneralizedEigenSolver<MatrixType>::EigenvectorsType GeneralizedEigenSolver<MatrixType>::eigenvectors() const
//{
//  eigen_assert(m_isInitialized && "EigenSolver is not initialized.");
//  eigen_assert(m_eigenvectorsOk && "The eigenvectors have not been computed together with the eigenvalues.");
//  Index n = m_eivec.cols();
//  EigenvectorsType matV(n,n);
//  // TODO
//  return matV;
//}

If you wanted eigenvalues from a single matrix you could use EigenSolver like this:

int main(int argc, char *argv[]) {

    Eigen::EigenSolver<Eigen::MatrixXf> es;
    Eigen::MatrixXf A = Eigen::MatrixXf::Random(4,4);
    es.compute(A);

    std::cout << es.eigenvectors() << std::endl;
    return 0;
}

Upvotes: 1

cfh
cfh

Reputation: 4666

It's strange that this isn't implemented, the docs suggest that it is. It's definitely worth asking on the Eigen mailing list or filing a ticket, maybe somebody is working on this and it's in the latest repository.

I have in the past used the GeneralizedSelfAdjointEigenSolver and it definitely produces eigenvectors. So if you know that both your matrices are symmetric, you can use that.

If your matrices are very small, as a quick fix you could apply the standard EigenSolver to M^{-1} A since

A x = lambda * M x    <==>   M^{-1} A x = lambda * x,

but obviously this requires you to compute the inverse of your right-hand side matrix which is very expensive, so this is really a last resort.

If all else fails, you could pull in a dedicated eigensolver library, say, FEAST, or use the LAPACK routines.

Upvotes: 1

Related Questions