Reputation: 1173
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.
Upvotes: 0
Views: 9582
Reputation: 1249
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.
Upvotes: 0
Reputation: 4252
If the matrix has Rank <= min(numOfRows, numOfColumns) its said to be rank deficient and its impossible to compute inverse of such a matrix.
Upvotes: 0
Reputation: 25992
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?
Upvotes: 0