I have a complex vector (VSII_Complex
containing Eigen values) and a complex matrix (CUII_Complex
containing Eigen vectors). Each element of VSII_Complex
is corresponding to a column of CUII_Complex
. My problem is that I want to sort the Eigen values inside VSII_Complex
based on their real part (NOT imaginary part) and I will have to sort the columns of CUII_Complex
according to the sorted VSII_Complex
. The following code is developed by my friend but I feel like something is wrong with this code but I cannot figure it out. I wonder if anybody can tell what is wrong if any.
EIG eigA=EIG(m_IIStiffnessAct,m_IIMassAct,true);
ComplexColumnVector VSII_Complex=eigA.eigenvalues();
ComplexMatrix CUII_Complex=eigA.eigenvectors();
///// make eigenvalues in decreasing order, so do eigenvectors
for (long ii = 0; ii < VSII_Complex.rows(); ii++)
{
for (long jj = ii+1; jj < VSII_Complex.rows(); jj++)
{
if (VSII_Complex(ii).real() < VSII_Complex(jj).real())
{
Complex temp = VSII_Complex(ii);
VSII_Complex(ii) = VSII_Complex(jj);
VSII_Complex(jj) = temp;
for (long kk = 0; kk < CUII_Complex.rows(); kk++)
{
Complex tempVec = CUII_Complex(kk,ii);
CUII_Complex(kk,ii) = CUII_Complex(kk,jj);
CUII_Complex(kk,jj) = tempVec;
}
}
}
}