java - 线程 "main"java.lang.RuntimeException : Matrix is singular 中的异常

标签 java matrix jama

我只是想根据 JAMA 文档创建一个 3x3 矩阵的逆矩阵。但每次它都会给我以下错误 -

线程“main”中的异常 java.lang.RuntimeException:矩阵是奇异的

谁能在这方面帮助我?

最佳答案

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         }

正如维基百科所说:

"In linear algebra an n-by-n (square) matrix A is called invertible or nonsingular or nondegenerate, if there exists an n-by-n matrix B such that AB = BA = In where In denotes the n-by-n identity matrix and the multiplication used is ordinary matrix multiplication."

简而言之,单数意味着不可逆。


如果您对 JAMA 不满意,请查看 Apache Commons 数学库,尤其是 Linear Algebra module .

关于java - 线程 "main"java.lang.RuntimeException : Matrix is singular 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6290459/

相关文章:

java - 带有 ReactNative 的 Android Studio 中不支持的类文件主要版本 59

java - Spring "cacheNames"不适用于 "key"

arrays - 仅对包含矩阵列表中完整案例的行进行子集化

Java Jama 矩阵

java - 尝试压缩图像时出现彩色像素(包括图片)

java - 枚举的每个成员的内部类?

java - 在特定时间后中断迭代的最佳方法是什么?

performance - 计算以下产品的快速方法

c - 如何返回矩阵?

java - 包含相同值的 HashMap