0

I looked for this everywhere, but I am wrong somewhere. In my Java program, I created few 2D Arrays. Now, I need to form new 2D arrays with previous, like, inverse, transpose, multiplying , LEFT DIVISION and maybe even more. Some of them (simple) I created myself, but left division, right division, inverse I didn't.

By using libs like Jama, some problem appears.

java.lang.RuntimeException: Matrix is rank deficient.

And I code it like this:

Matrix Am=new Matrix(A);
Am=Am.inverse();

A is 2D Array (m x n), and Am is new matrix created from 2DArray A.

I tried to do this to get left division, but I cannot solve matrix inverse first.

Where is my mistake? Does someone know another library to convert from 2DArray to Matrix, and then do harder matrix operations (left div, inv...) with it?

EDIT

I use inverse on this matrix to get A\P (can be computed as inverse(A)*P as I saw somewhere). Do you know how to get A\P with Jama? This is my primary probleb, left division.

AdrienW
  • 3,092
  • 6
  • 29
  • 59
Aleksandar
  • 1,163
  • 22
  • 41

4 Answers4

1

For matrix libraries, you can check this question:

But for code you wrote, no one can say anything, you have to include the code itself to see where the problem is.

Community
  • 1
  • 1
Asqan
  • 4,319
  • 11
  • 61
  • 100
0

As your exception says, your matrix is rank deficient, it is mathematically impossible to compute an inverse matrix. The computer is not above mathematics in these affairs.

This can have multiple reasons. First of all, inverse matrices only exist for square inputs, i.e., format n x n. You did not indicate that this is the case. There exists the idea of the pseudo-inverse that can be constructed for all matrices.

But even for square matrices, the rank can be deficient, i.e., the matrix can be singular. In exact terms, this happens if the determinant is zero. In computational terms, this can also happen for ill-conditioned matrices with a wide magnitude range in their singular values.

Can you provide the matrix where that problem occurs?

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • Ok then. I use inverse on this matrix to get A\P (can be computed as inverse(A)*P as I saw somewhere). Do you know how to get A\P with Jama? – Aleksandar Feb 26 '14 at 00:10
  • Normally, you don't. What you do is solving a linear system. I.e., the quadratic matrix A gets factored as PLU or QR and this factorization is used to solve AX=P. If A=QR was computed, then the steps are to multiply Q^T*P and then to apply back-substitution to the triangular factor. -- This all assumes that A is quadratic, regular and well-conditioned. Violating any of these conditions precludes or aborts the computation. – Lutz Lehmann Feb 26 '14 at 00:27
  • Ok, got it. I'll try to get another way to solve problem without using this formula... Thanks. – Aleksandar Feb 26 '14 at 00:35
0

If the matrix has Rank <= min(numOfRows, numOfColumns) its said to be rank deficient and its impossible to compute inverse of such a matrix.

Kakarot
  • 4,252
  • 2
  • 16
  • 18
0

A is 2D Array (m x n), and Am is new matrix created from 2DArray A.

Make sure that your matrix is quadratic (n x n), otherwise the inverse is not defined.

If you can't avoid that the matrix is not full-ranked or quadratic, you might consider using the pseudo-inverse.

exception1
  • 1,239
  • 8
  • 17
  • My matrix is not quadratic, but in documentation says (as I understood) if matrix isnt quadratic it will return as pseudo - inverse. – Aleksandar Feb 26 '14 at 00:01