Search code examples
javamatrixjama

Exception in thread "main" java.lang.RuntimeException: Matrix is singular


I'm just trying to create an inverse matrix of a 3x3 matrix following JAMA documentation. But every time it's giving me the following error -

Exception in thread "main" java.lang.RuntimeException: Matrix is singular

Can anyone help me in this regard?


Solution

  • If you can calculate the determinant of your matrix, you'll find that it's zero (or close to it).

    You might be able to tell by inspection. If one row is proportional to another, your matrix is not invertible.

    3x3 is easy enough to invert by hand. Try it and see where it goes wrong.

    Try a SVD solution. It'll tell you what the null space for your matrix is.