是否有一种简单的方法来反转三角形(上或下)矩阵?

发布于 2024-07-11 13:08:49 字数 84 浏览 11 评论 0原文

我正在尝试实现一些基本的线性代数运算,其中之一是三角(上和/或下)矩阵的求逆。 有没有一种简单且稳定的算法可以做到这一点?

谢谢。

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 技术交流群。

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

发布评论

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

评论(6

风追烟花雨 2024-07-18 13:08:49

给定一个下三角矩阵 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.

挽梦忆笙歌 2024-07-18 13:08:49

如果可以的话,不要颠倒它。 它是数值线性代数的基本戒律之一。

将矩阵 L 本身保留在内存中并进行计算会更快且数值更稳定

inv(L)b

with back-substitution whenever you need to do something else with inv(L).

请注意,反转它的常规算法需要求解系统

inv(L)[1 0 0 ...],
inv(L)[0 1 0 ....],
inv(L)[0 0 1 ....]

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

inv(L)b

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

inv(L)[1 0 0 ...],
inv(L)[0 1 0 ....],
inv(L)[0 0 1 ....]

and so on, so you see it is much easier not to invert it at all.

々眼睛长脚气 2024-07-18 13:08:49

是的,使用后向替换。 求逆矩阵的标准算法是求其 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.

扭转时空 2024-07-18 13:08:49

如果您谈论的是单精度实数,请查看 LAPACK 例程的源代码 STRTRISTRTI2

If you are talking about single precision reals, have a look at the source code for the LAPACK routines STRTRI and STRTI2.

野味少女 2024-07-18 13:08:49

作为三角矩阵 A 的逆 B,您可以使用以下 MATLAB 代码:

n = size(A,1);
B = zeros(n);
for i=1:n
    B(i,i) = 1/A(i,i);
    for j=1:i-1
        s = 0;
        for k=j:i-1
            s = s + A(i,k)*B(k,j);
        end
        B(i,j) = -s*B(i,i);
    end
end

Being B inverse of A, a triangular matrix, you can use the following MATLAB code:

n = size(A,1);
B = zeros(n);
for i=1:n
    B(i,i) = 1/A(i,i);
    for j=1:i-1
        s = 0;
        for k=j:i-1
            s = s + A(i,k)*B(k,j);
        end
        B(i,j) = -s*B(i,i);
    end
end
浅唱ヾ落雨殇 2024-07-18 13:08:49

哇,这几乎是数值分析课程内容的一半。 标准算法可以做到这一点,这里有一堆预装代码 。 这个问题和大多数其他常见数值分析问题的最终来源是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.

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