简体   繁体   中英

Is there around a straightforward way to invert a triangular (upper or lower) matrix?

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.

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.

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.

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.

如果您正在讨论单精度实数,请查看LAPACK例程STRTRISTRTI2的源代码。

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM