使用 Jama.Matrix 测试可逆性

发布于 2024-07-12 22:52:28 字数 220 浏览 9 评论 0原文

我有一个使用 JAMA 的程序,需要测试矩阵是否可以反转。 我知道我可以尝试它并捕获异常,但这似乎是一个坏主意(将 catch 块作为“正常”代码路径的一部分似乎是不好的形式)。

最好还返回逆运算(或者以比逆运算更好的 O() 运行)的测试。

I have a program that uses JAMA and need to test is a matrix can be inverted. I know that I can just try it and catch an exception but that seems like a bad idea (having a catch block as part of the "normal" code path seems to be bad form).

A test that also returns the inverse (or run in a better O() than the inverse operation) would be preferred.

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

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

发布评论

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

评论(4

耶耶耶 2024-07-19 22:52:29

如果抛出异常,你的恢复位置是什么?

如果您进行 LU 分解并发现它是奇异的,您是否会捕获异常并尝试 SVD(奇异值分解)?

If an exception is thrown, what is your recovery position?

If you do an LU decomposition and find that it's singular, do you catch the exception and try an SVD (singular value decomposition) instead?

怎言笑 2024-07-19 22:52:29

听起来您想估计条件数的倒数。

这个网站看起来很有前途...

另请参阅Golub 和 Van Loan,第 14 页 128-130。 (如果您没有副本,请获取一份。)

...或 Higham,数值方法方面的权威。 只是解析数学有点困难……就像穿过一片覆盆子灌木丛一样。 :/

或者检查 Octave 源代码的 MATLAB 的 <代码>rcond()。 我找到了这篇文章。

sounds like you would like to estimate the reciprocal of the condition number.

This site looks somewhat promising...

See also Golub and Van Loan, p. 128-130. (If you don't have a copy of it, get one.)

...or Higham, who's an authority on numerical methods. Except that it's kind of hard to parse the math... like walking through a thicket of raspberry bushes. :/

Or maybe check the Octave sources for their version of MATLAB's rcond(). I found this post.

一向肩并 2024-07-19 22:52:29

对于方阵,您可以只检查其 行列式 --- Matrix.det() 返回零当且仅当矩阵是单一的。 当然,您还需要注意病态矩阵。

For a square matrix, you could you just check its determinant --- Matrix.det() returns zero if and only if the matrix is singular. Of course, you will need to watch out for ill-conditioned matrices too.

筱果果 2024-07-19 22:52:28

一般来说,如果你无法解出矩阵,那么它就是奇异的(不可逆的)。 我相信 JAMA 这样做的方法是尝试使用 LU 分解来求解矩阵,如果失败,则为 isSingular() 返回“true”。

实际上并没有一种通用的方法来仅查看矩阵的元素并确定它是否是奇异的 - 您需要检查每一列以查看它是否与其他列正交(即矩阵的零空间为 0)。 通常,LU 分解速度相当快……但是,有时它会占用大量操作。

您是否有想要克服的实际速度问题?

In general, if you can't solve the matrix, it's singluar (non-invertable). I believe the way that JAMA does this is to try to solve the matrix using LU factorization, and if it fails, it returns "true" for isSingular().

There isn't really a general way to just look at the elements of a matrix and determine if it is singular - you need to check each column to see if it is orthogonal with the others (i.e. the nullspace for the matrix is 0). LU factorization is quite fast, usually... there are times where it takes the bulk of an operation, however.

Do you have an actual speed problem you're trying to overcome?

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