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

发布于 2024-11-14 15:22:09 字数 141 浏览 4 评论 0原文

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

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

任何人都可以在这方面帮助我吗?

I'm just trying to create an inverse matrix of a 3x3 matrix following JAMA documentation. But every time it's giving me the following error -

Exception in thread "main" java.lang.RuntimeException: Matrix is singular

Can anyone help me in this regard?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

噩梦成真你也成魔 2024-11-21 15:22:10

好吧,它告诉您需要知道的一切:您尝试求逆的矩阵是奇异的。

奇异矩阵是不可逆的。

如果您认为您的矩阵不是奇异的,请将其发布,我们会看一下。

Well, it's telling you everything you need to know: the matrix you are trying to invert is singular.

Singular matrices are non-invertible.

If you think your matrix isn't singular, please post it and we'll take a look.

墨洒年华 2024-11-21 15:22:09

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         }

As Wikipedia说:

“在线性代数中,如果存在一个 n×n 矩阵 B 使得 AB = BA = I,则 n×n(方)矩阵 A 称为可逆或非奇异或非简并矩阵 B n
其中 In 表示 n×n 单位矩阵,所使用的乘法是普通矩阵乘法。”

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


如果你对 JAMA 不满意,请查看 Apache Commons Maths 库,特别是 线性代数模块

The documentation for Jama is not very good.

In fact, if you look through the sourcecode, you will find that Matrix.inverse() ultimately calls LUDecomposition.solve(...) and the code says:

  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         }

As Wikipedia says:

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

In short, singular means not invertible.


If you are unhappy with JAMA, take a look at the Apache Commons Maths libraries, in particular the Linear Algebra module.

网名女生简单气质 2024-11-21 15:22:09

如果您可以计算矩阵的行列式,您会发现它为零(或接近零)。

通过检查也许就能知道。如果一行与另一行成比例,则矩阵不可逆。

3x3 很容易用手反转。尝试一下,看看哪里出了问题。

尝试 SVD 解决方案。它会告诉您矩阵的零空间是什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文