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

Wrong with SelfAdjointEigenSolver<MatrixXcd> complex class

Tags: None
(comma "," separated)
wendingmai
Registered Member
Posts
16
Karma
0
Hi,

I try to use SelfAdjointEigenSolver<MatrixXcd> to decompose a pure imaginary Selfadjoint matrix. However the result shows, by multiply eigenvector*eigenvalue.diag*eigenvector.transpose, it produces a simply symmetric matrix, instead of a selfadoint one.

Is the SelfAdjointEigenSolver only suitable for symmetric matrix, not for complex selfadjoint one?
Or is there anything wrong with my code?
Thank you.

Code: Select all
#include <Eigen/Core>
#include <Eigen/Sparse>
#include <Eigen/Dense>
#include <Eigen/Eigenvalues>
//#include <GenEigsSolver.h>
//#include <MatOp/SparseGenMatProd.h>
#include <iostream>
using namespace Eigen;
using namespace std;

int main()
{
   int na = 5;
   int nb = 4;

   MatrixXcd VA(na, na);
   MatrixXcd VB(nb, nb);
   VectorXcd Va(na),Vb(nb);
   VectorXcd Ve(nb);
   MatrixXd A = MatrixXd::Random(na, na);
   MatrixXd B = MatrixXd::Random(nb, nb);

   
   MatrixXcd Aa;
   MatrixXcd Ua(na, na),Ub(nb,nb),U1(na,nb);
   MatrixXcd M(na, nb),TEMP(nb,nb);
   for (int i = 0; i < na; i++)
      for (int j = 0; j < na; j++)
      {
         if (i == j)
            A(i, j) = 0;
         else if (i < j)
            A(i, j) = -A(j, i);
      }

   for (int i = 0; i < nb; i++)
      for (int j = 0; j < nb; j++)
      {
         if (i == j)
            B(i, j) = 0;
         else if (i < j)
            B(i, j) = -B(j, i);
      }
   //cout << A << endl;
   VA = A.cast<complex<double>>();
   VB = B.cast<complex<double>>();
   VA.imag() = VA.real();
   VA.real() *= 0;
   VB.imag() = VB.real();
   VB.real() *= 0;

   //cout << VA<<endl;
   SelfAdjointEigenSolver<MatrixXcd> esa(VA);
   if (esa.info() != Success) abort();
   cout <<VA<<endl<< esa.eigenvectors() << endl << endl << esa.eigenvalues() << endl << endl
      << esa.eigenvectors()*esa.eigenvalues().asDiagonal()*esa.eigenvectors().transpose();
}
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You have to use .adjoint() instead of .transpose()
wendingmai
Registered Member
Posts
16
Karma
0
ggael wrote:You have to use .adjoint() instead of .transpose()


...Thank you very much ggael.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]