2
$\begingroup$

Spectral decomposition of symmetric matrix $A_{n\times n}$, specifically, $n=3$

find the orthogonal matrix $Q$ and diagonal matrix $\Lambda$ such that:

$A=Q\Lambda Q^T$

How to implement such decomposition in Eigen C++? or any other C++ implementations?

$\endgroup$
6
$\begingroup$

You're looking for the SelfAdjointEigenSolver class, and there is also an example in the user manual that I report here:

#include <iostream>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;
int main()
{
   Matrix2f A;
   A << 1, 2, 2, 3;
   cout << "Here is the matrix A:\n" << A << endl;
   SelfAdjointEigenSolver<Matrix2f> eigensolver(A);
   if (eigensolver.info() != Success) abort();
   cout << "The eigenvalues of A are:\n" << eigensolver.eigenvalues() << endl;
   cout << "Here's a matrix whose columns are eigenvectors of A \n"
        << "corresponding to these eigenvalues:\n"
        << eigensolver.eigenvectors() << endl;
}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.