
If I try to invert a Matrix which is not invertable, it doesn't throw an Exception or gives me an error.
I just get out a Matrix where all Elements are n.def's. Is there a way to check if a Matrix is invertable or not?


Coordinator
Sep 19, 2013 at 3:48 PM

m.Inverse() is essentially the same as m.LU().Inverse() for a square matrix. The LU decomposition also provides the determinant  is it zero as it should be for a singular matrix, or is it NaN as well?
var lu = m.LU();
bool isInvertible = lu.Determinant != 0d;
var inverse = lu.Inverse();



Thanks for the answer!
The determinant gave zero.
I will use the determinant to check for invertibility, even this is not a sufficient constraint. (But suitable in my case)
There is as well the function on the Matrixobject which calculates the determinant.
bool isInvertible = m.Determinant() != 0d;


Coordinator
Sep 19, 2013 at 5:03 PM

You can also use the SVD decomposition instead of LU, which provides a condition number to get an idea how illconditioned the matrix is.
You're right, Inverse and Determinant (and also ConditionNumber) are all also available at the matrix, but they do not cache the decomposition. If your matrix is large you may want to reuse it (by using it explicitly as in my example above).

