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

前端 未结 3 1793
故里飘歌
故里飘歌 2020-12-21 17:18

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 i

3条回答
  •  遥遥无期
    2020-12-21 17:18

    The documentation for Jama is not very good.

    In fact, if you look through the sourcecode, you will find that Matrix.inverse() ultimately calls LUDecomposition.solve(...) and the code says:

      270      /** Solve A*X = B
      271      @param  B   A Matrix with as many rows as A and any number of columns.
      272      @return     X so that L*U*X = B(piv,:)
      273      @exception  IllegalArgumentException Matrix row dimensions must agree.
      274      @exception  RuntimeException  Matrix is singular.
      275      */
      277      public Matrix solve (Matrix B) {
      278         if (B.getRowDimension() != m) {
      279            throw new IllegalArgumentException("Matrix row dimensions must agree.");
      280         }
      281         if (!this.isNonsingular()) {
      282            throw new RuntimeException("Matrix is singular.");
      283         }
    

    As Wikipedia says:

    "In linear algebra an n-by-n (square) matrix A is called invertible or nonsingular or nondegenerate, if there exists an n-by-n matrix B such that AB = BA = In where In denotes the n-by-n identity matrix and the multiplication used is ordinary matrix multiplication."

    In short, singular means not invertible.


    If you are unhappy with JAMA, take a look at the Apache Commons Maths libraries, in particular the Linear Algebra module.

提交回复
热议问题