我刚开始使用 Jama 来处理矩阵。我的问题是,当我使用 det()
方法(与 LUDecomposition
类相关)时,它给出“矩阵必须是正方形”
。好吧,我的矩阵是三角形,但使用 LUDecomposition 应该会给出方阵。我的代码是这样的
public double findDeterminant(Matrix mtrx) {
LUDecomposition dec = new LUDecomposition(mtrx);
det = dec.det();
return det;
}
最佳答案
来自documentation LUDecomposition
:
For an m-by-n matrix
A
with m >= n, the LU decomposition is an m-by-n unit lower triangular matrixL
, an n-by-n upper triangular matrixU
, and a permutation vectorpig
of length m so thatA(piv,:) = L*U
. If m < n, thenL
is m-by-m andU
is m-by-n.
您是否想找到 getU()
或 getL()
的行列式(其中一个将是平方,基于上面的描述)?
LUDecomposition
的 det
方法返回用于构造对象的矩阵的行列式(在您的情况下 mtrx
,我假设它不是正方形)。
关于java - Jama - 寻找行列式时矩阵必须是平方异常(exception),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13442413/