Search code examples
javalinear-algebraojalgo

Ojalgo: Handling of singular matrices


I am using ojalgo to solve a (NxN) Ax = b System in java. Since there are chances that A will be a singular matrix, I would like my code to know this somehow. Is there a way? (documentation states that the solve() method returns one possible solution if the problem is under-qualified and the invert() method does not throw an exception).

Any help would be greatly appreciated. Thanks in advance.


Solution

  • Sounds like you're using the solve- and invert-methods on a BasicMatrix directly.

    Switch to using an LU-decompostion instead. After you have decomposed the matrix, but before attempting the solve, you can call:

    lu.isSquareAndNotSingular();