Вопрос

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;
}
Это было полезно?

Решение

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).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top