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

624

views

0

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.

Any suggestions about this?

Thanks

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.

Any suggestions about this?

Thanks

Community: FEniCS Project

### 2 Answers

3

As suggested, there are analytical expressions for specific case.

In any case, do not use

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

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.

Please login to add an answer/comment or follow this question.