# How to implement the spectral decomposition of a symmetric dense matrix via Eigen C++

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?

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;