是否有一种简单的方法来反转三角形(上或下)矩阵?
我正在尝试实现一些基本的线性代数运算,其中之一是三角(上和/或下)矩阵的求逆。 有没有一种简单且稳定的算法可以做到这一点?
谢谢。
I'm trying to implement some basic linear algebra operations and one of these operations is the inversion of a triangular (upper and/or lower) matrix. Is there an easy and stable algorithm to do that?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
给定一个下三角矩阵 L,回代可以求解该系统
L x = b
对于任何右侧,快速 b.
要反转 L,您可以求解该方程组的右侧 e1=(1,0,...,0), e2=(0,1,...,0), ..., en=(0 ,0,...,1) 并将所得解向量组合成单个(必须是下三角)矩阵。
如果您对封闭式解感兴趣,则逆的对角元素是原始对角元素的逆,并且当您远离对角线时,逆的其余元素的公式会变得越来越复杂。
Given a lower triangular matrix L, backsubstitution allows you to solve the system
L x = b
quickly for any right-hand side b.
To invert L, you can solve this system for right-hand sides e1=(1,0,...,0), e2=(0,1,...,0), ..., en=(0,0,...,1) and combine the resulting solution vectors into a single (necessarily lower-triangular) matrix.
If you are interested in a closed-form solution, the diagonal elements of the inverse are the inverses of the original diagonal elements, and the formula for the rest of the elements of the inverse gets more and more complicated as you move aways from the diagonal.
如果可以的话,不要颠倒它。 它是数值线性代数的基本戒律之一。
将矩阵 L 本身保留在内存中并进行计算会更快且数值更稳定
with back-substitution whenever you need to do something else with inv(L).
请注意,反转它的常规算法需要求解系统
and so on, so you see it is much easier not to invert it at all.
Don't invert it if you can. It's one of the basic commandments of numerical linear algebra.
It is much faster and numerically stabler to keep the matrix L itself in memory and compute
with back-substitution whenever you need to do something else with inv(L).
Note that the customary algorithm for inverting it requires solving the systems
and so on, so you see it is much easier not to invert it at all.
是的,使用后向替换。 求逆矩阵的标准算法是求其 LU 分解(分解为下三角矩阵和上三角矩阵),对三角块进行回代,然后组合结果以获得原始矩阵的逆矩阵。
Yes, use back substitution. A standard algorithm to invert a matrix is to find its LU decomposition (decomposition into a lower-triangular and an upper-triangular matrix), use back subsitution on the triangular pieces, and then combine the results to obtain the inverse of the original matrix.
如果您谈论的是单精度实数,请查看 LAPACK 例程的源代码 STRTRI 和 STRTI2。
If you are talking about single precision reals, have a look at the source code for the LAPACK routines STRTRI and STRTI2.
作为三角矩阵 A 的逆 B,您可以使用以下 MATLAB 代码:
Being B inverse of A, a triangular matrix, you can use the following MATLAB code:
哇,这几乎是数值分析课程内容的一半。 标准算法可以做到这一点,这里有一堆预装代码 。 这个问题和大多数其他常见数值分析问题的最终来源是Numerical Recipes。
Wow, that's practically half the contents of a numerical analysis course. The standard algorithms will do it, and there is a bunch of canned code here. The ultimate source for this and most other usual numerical analysis problems is Numerical Recipes.