2

I am using Jama API for solving a problem with Linear Algebra. But it is giving me an error: java.lang.RuntimeException: Matrix is singular.

I suppose when the matrix is singular there are multiple solutions possible. Is there a way in Jama API to get one of these solutions or is there any other API that can help me here.

Below is a code snippet I am using:

Matrix A = new Matrix(input);
Matrix B = new Matrix(startState);
Matrix X = A.solve(B);
answer = X.getArray();
return answer;
gobernador
  • 5,659
  • 3
  • 32
  • 51
Balkrishna Rawool
  • 1,865
  • 3
  • 21
  • 35
  • 3
    [This question](http://stackoverflow.com/questions/6290459/exception-in-thread-main-java-lang-runtimeexception-matrix-is-singular) might help you out. – Michael Jul 03 '12 at 16:09
  • Singular means there are no solutions, not many. – Sean Owen Jul 03 '12 at 16:33
  • @SeanOwen: The matrix of coefficients may be singular (not invertible) if the equations are _inconsistent_, e.g. two parallel lines having _no_ intersection, or if some equations are _dependent_, e.g. two coincident lines having _infinite_ intersection. – trashgod Jul 03 '12 at 17:55
  • You are right @trashgod, I thought Jama would use a pseudo-inverse in the case of dependent rows to give a solution but it does not. – Sean Owen Jul 03 '12 at 21:33

1 Answers1

1

check the determinant of the matrix - if zero, it means that the matrix does not have an inverse (rows making up the matrix are not independent). In that case, you can look into SVD, Gauss-Siedel, Jacobi iteration etc. Also, as an alternate library, you could look into apache commons math if it helps.

ali haider
  • 19,175
  • 17
  • 80
  • 149
  • I looked into Apache Commons. They have nice API for Linear Algebra: [Commons Math](http://commons.apache.org/math/). I used SVD. @ali haider – Balkrishna Rawool Jul 03 '12 at 17:25