This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to sord the eigenvalues and corresponding eigenvectors?

Tags: None
(comma "," separated)
Jacory Gao
Registered Member
Posts
2
Karma
0
Hi all,
I'm new to Eigen library, and I feel really love it.
But now, I have a problem. I use EigenSolver to compute the eigenvalues and eigenvectors of a matrix, and I use function real() to avoid the complex numbers. My idea is that I want to sort the eigenvalues in order, and of course when the eigenvalues are sorted, so did the corresponding eigenvectors.
I found there are some topics in this forum about this question, but they are considered about 1 or 2 years from now. I'm wondering if Eigen library has developed some good function to do this job?
Really appreciate your help. And here's my code now.

Code: Select all
Eigen::Map<MatrixXd> covMat( matrix, n, n );
    Eigen::EigenSolver<MatrixXd> es;
    es.compute( covMat, true );
    VectorXd eVals = es.eigenvalues().real();
    std::sort( eVals.data(), eVals.data() + eVals.size() );
    cout << eVals << endl;
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Given its name, I guess that "covMat" is symmetric, then use SelfAdjointEigenSolver that will be faster with eigenvalues/vectors naturally sorted from the smallest to the largest.
Jacory Gao
Registered Member
Posts
2
Karma
0
ggael wrote:Given its name, I guess that "covMat" is symmetric, then use SelfAdjointEigenSolver that will be faster with eigenvalues/vectors naturally sorted from the smallest to the largest.

Thanks a lot, I get the exactly what I want, this library is really cool. 8-)


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar