2

I am new to using Jama for matrices. My problem is while I'm using det() method (which is related with LUDecomposition class) it gives "Matrix must be square". Ok my matrix is triangle but with LUDecomposition it should give me square matrix. My code like this

public double findDeterminant(Matrix mtrx) {
    LUDecomposition dec = new LUDecomposition(mtrx);        
    det = dec.det();
    return det;
}
Amro
  • 123,847
  • 25
  • 243
  • 454
sinan selimoglu
  • 103
  • 1
  • 8

1 Answers1

2

From the documentation of LUDecomposition:

For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a permutation vector pig of length m so that A(piv,:) = L*U. If m < n, then L is m-by-m and U is m-by-n.

Did you perhaps mean to find the determinant of getU() or getL() (one of which will be square, based on the description above)?

The det method of LUDecomposition returns the determinant of the matrix that was used to construct the object (in your case mtrx, which I'm assuming isn't square).

arshajii
  • 127,459
  • 24
  • 238
  • 287
  • @sinanselimoglu You will probably have to check the dimensions of `mtrx` to determine if `L` is square or if `U` is square. – arshajii Nov 18 '12 at 17:30
  • @sinanselimoglu Not sure what else I can do... I mean I basically gave you the answer on a silver platter. – arshajii Nov 18 '12 at 18:53