我只是想按照 JAMA 文档创建一个 3x3 矩阵的逆矩阵。但每次它给我以下错误 -
Exception in thread "main" java.lang.RuntimeException: Matrix is singular
任何人都可以在这方面帮助我吗?
Jama的文档不是很好。
实际上,如果您查看源代码,您会发现Matrix.inverse()
最终调用LUDecomposition.solve(...)
并且代码说:
270 /** Solve A*X = B
271 @param B A Matrix with as many rows as A and any number of columns.
272 @return X so that L*U*X = B(piv,:)
273 @exception IllegalArgumentException Matrix row dimensions must agree.
274 @exception RuntimeException Matrix is singular.
275 */
277 public Matrix solve (Matrix B) {
278 if (B.getRowDimension() != m) {
279 throw new IllegalArgumentException("Matrix row dimensions must agree.");
280 }
281 if (!this.isNonsingular()) {
282 throw new RuntimeException("Matrix is singular.");
283 }
正如维基百科所说:
“在线性代数中,如果存在一个 n×n 矩阵 B 满足 AB = BA = I n 其中 I n表示 n-by -n 单位矩阵,使用的乘法是普通矩阵乘法。”
简而言之,单数意味着不可逆。
如果您对 JAMA 不满意,请查看 Apache Commons Maths 库,尤其是Linear Algebra 模块。
If you can calculate the determinant of your matrix, you'll find that it's zero (or close to it).
You might be able to tell by inspection. If one row is proportional to another, your matrix is not invertible.
3x3 is easy enough to invert by hand. Try it and see where it goes wrong.
Try a SVD solution. It'll tell you what the null space for your matrix is.
好吧,它告诉了你需要知道的一切:你试图求逆的矩阵是奇异的。
奇异矩阵是不可逆的。
如果您认为您的矩阵不是单数的,请发布它,我们会看看。