### How to compute the eigenvalues/eigenvectors of a 3x3 double matrix in C++ (serial)?

533
views
0
9 months ago by
Hi all,

I have 6 entries of a symmetric matrix (they are all doubles). I need simply to assemble the matrix and compute its eigencouples. I tried a lot of things, unsuccessfully. I tried to use PETScMatrix object, but I can't fill the entries, I can't initialize it too. I tried to initialize it with a PETSc Mat object, but I can't even initialize it, since it requires MPI_Comm as input parameter and my code works in serial. Consider that I tried to initialize PETScMatrix with a TensorLayout, but it requires an MPI_Comm too.

Thanks
Community: FEniCS Project

3
9 months ago by
As suggested, there are analytical expressions for specific case.

In any case, do not use dolfin::PETScMatrix or dolfin::Matrix. These are designed for large, sparse matrices. From Python use NumPy/SciPy, and from C++ use Eigen3.
1
9 months ago by
A 3x3 matrix leads to a cubic equation for eigenvalues. There are explicit formulae for roots of a cubic. This would be faster than doing it numerically I think.