How to Invert a Matrix ?
The most straightforward way to invert a matrix is to invoke the Invert(Double_t &det=0) function or the appropriate constructor:
TMatrixD a(...); a.Invert();
TMatrixD b(kInvert,a);
| Name | Matrix Type | Comment |
| TDecompLU | general | |
| TDecompQRH | general | |
| TDecompSVD | general | Can manipulate singular matrix. |
| TDecompBK | symmetric | |
| TDecompChol | symmetric | Matrix should also be positive definite. |
| TDecompSparse | sparse |
If the required matrix type is general, it can of course also handle symmetric matrices.
The following example shows how to check whether the matrix is singular before attempting to invert it.
TDecompLU lu(a); TMatrixD b; if (!lu.Decompose()) { cout << "Decomposition failed, matrix singular ?" << endl; cout << "condition number = " << = a.GetCondition() << endl; } else { lu.Invert(b); }