## Inverting a symmetric matrix

gavinband
Registered Member
Posts
3
Karma
0

### Inverting a symmetric matrix

Wed Apr 24, 2013 2:14 pm
Hi,
Can somebody advise me the recommended way to invert a (positive definite) symmetric matrix?
The obvious way would be to use SelfAdjointEigenSolver and compute the inverse as V D^-1 V^t. However, the docs don't seem to state that the computed eigenvector matrix V is orthogonal, so it seems possible that this would be incorrect if there are repeated eigenvalues. Can anyone advise? (The docs for operatorInverseSqrt make me think it must actually be ok.)

(To be clear, I want the inverse so I can print it out, not to use it to solve anything.)

Many thanks for any help with this!
Gavin.
Dee33
Registered Member
Posts
54
Karma
0
OS

### Re: Inverting a symmetric matrix

Wed Apr 24, 2013 3:48 pm
Even if you do not want to solve a linear system with your matrix,
you can still use any decomposition suitable for your matrix : http://eigen.tuxfamily.org/dox-devel/gr ... gebra.html
and use it to solve a system like A * Ai = I where Ai is the inverse and I the Identity matrix.

If your matrix is SPD, use the Cholesky decomposition
Code: Select all
`#include <Eigen/Cholesky>... MatrixType A, Ai; //Fill the matrix A ...Ai = A.llt().solve(MatrixType::Identity(A.rows(), A.rows()));`
gavinband
Registered Member
Posts
3
Karma
0

### Re: Inverting a symmetric matrix

Thu Apr 25, 2013 8:46 am
Hi,
That makes sense, thanks. (I have been using the LDLT rather than LLT because information on [1] seemed to say it was more robust. Is there a reason to prefer LLT?)
Best wishes,
Gavin.
[1] http://eigen.tuxfamily.org/dox/TopicLin ... tions.html
Dee33
Registered Member
Posts
54
Karma
0
OS

### Re: Inverting a symmetric matrix

Thu Apr 25, 2013 9:01 am
LLT is faster than LDLT but it requires the matrix to be positive definite, otherwise it may fail to produce the decomposition
If you're not sure about that property of your matrix, then you may consider using LDLT (if the matrix is at least semi definite ) or PartialPivLU (more robust)
gavinband
Registered Member
Posts
3
Karma
0

### Re: Inverting a symmetric matrix

Mon Apr 29, 2013 10:45 am