Matrix regularity check

Hi Rooters,

maybe you’d know… Is there an elegant way to check regularity of a matrix. In the moment I’m checking its determinant. It works but when the matrix is singular it prints error message

which makes me nervous :confused:

Thanks for any ideas, Kašpi.

Hi Kašpi,

I assume that you are using the Determinant() method of the
matrix class. It uses the LU decomposition which gives indeed
a warning in case of a singular matrix .

If these warnings annoy you, you can take measures into your
own hands by calling a decomposition directly . a Single-value
decomposition is supposed to never fail (and therefore gives
not this warning) . You can the ask for the determinant from this
decomposition and check for regularity:

TMatrixD a;…

TDecompSVD svd(a);
Double_t d1,d2;
const Double_t determinant = d1*TMath::power(2.,d2);

You can also ask for the matrix condition number :

const Double_t condition = svd.Condition();

where high condition numbers point to ill-conditioned matrices, see doc .