Re: [eigen] ordering of eigenvalues of EigenSolver

[ Thread Index | Date Index | More Archives ]


This is the code I've been using for a while to do the sorting.
In its context it's intended to live as an extension to EigenBase, but
you could easily adapt it to your needs:

Perhaps it could be optimized, but it's tested and works ;-)

template <class Derived>
template <class MATRIX1,class VECTOR1>
EIGEN_STRONG_INLINE void Eigen::MatrixBase<Derived>::eigenVectorsVec(
MATRIX1 & eVecs, VECTOR1 & eVals ) const
	Eigen::EigenSolver< Derived > es(*this, true);
	eVecs = es.eigenvectors().real(); // Keep only the real part of complex matrix
	eVals = es.eigenvalues().real(); // Keep only the real part of complex matrix

	// Sort by ascending eigenvalues:
	std::vector<std::pair<Scalar,Index> > D;
	for (Index i=0;i<eVals.size();i++)
	MATRIX1 sortedEigs;
	for (int i=0;i<eVals.size();i++)
	eVecs = sortedEigs;

Jose Luis

On Tue, Feb 8, 2011 at 6:08 PM, FMDSPAM <fmdspam@xxxxxxxxx> wrote:
> Am 08.02.2011 17:36, schrieb Milian Wolff:
>> as I was teached: the ordering of eigen values is totally arbitrary and
>> depends on the implemented algorithm. Meaning: You have to sort them to
>> your
>> expectations.
> fair enough.
> What is the most elegant way to do so in eigen(3)?
> --Frank


Dr. Jose-Luis Blanco-Claraco
Dpt. Ing. Civil, Mat. y Fabric - Phone: +34 951 952435
E.T.S.I. Industriales - Despacho 2.037
Universidad de Malaga - Campus Universitario de Teatinos
29071 Malaga, Spain

Mail converted by MHonArc 2.6.19+