[L,U] = lu(X)
[L,U,P] = lu(X)
lu(X)
lu(X)
expresses any square matrix X
as the product of two essentially triangular matrices, one of them a permutation of a lower triangular matrix and the other an upper triangular matrix. The factorization is often called the LU, or sometimes the LR, factorization. Most of the algorithms for computing it are variants of Gaussian elimination. The factorization is a key step in obtaining the inverse with inv
and the determinant with det
. It is also the basis for the linear equation solution or matrix division obtained with \
and /.
[L
,U] = lu(X)
stores an upper triangular matrix in U
and a psychologically lower triangular matrix (i.e., a product of lower triangular and permutation matrices) in L
, so that X = L*
U
.
[L
,U
,P] = lu(X)
stores an upper triangular matrix in U
, a lower triangular matrix in L
, and a permutation matrix in P
, so that L
*U = P
*X
.
By itself, lu(X)
returns the output from the LINPACK routine ZGEFA
.
To see the LU factorization, callA =
1 2 3
4 5 6
7 8 0
lu
with two output arguments:
Notice that[L,U] = lu(A)
L =
0.1429 1.0000 0
0.5714 0.5000 1.0000
1.0000 0 0
U =
7.0000 8.0000 0.0000
0 0.8571 3.0000
0 0 4.5000
L
is a permutation of a lower triangular matrix that has 1s on the permuted diagonal, and that U
is upper triangular. To check that the factorization does its job, compute the product:
which returns the originalL
*U
A
. Using three arguments on the left-hand side to get the permutation matrix as well:
returns the same value of[L,U,P]
=
lu(A)
U
, but L
is reordered:
To verify thatL =
1.0000 0 0
0.1429 1.0000 0
0.5714 0.5000 1.0000
U =
7.0000 8.0000 0
0 0.8571 3.0000
0 0 4.5000
P =
0 0 1
1 0 0
0 1 0
L
*U
is a permuted version of A
, compute L
*U
and subtract it from P
*A
:
The inverse of the example matrix,P
*A
-
L
*U
X = inv(A)
, is actually computed from the inverses of the triangular factors:
The determinant of the example matrix isX
=
inv(U)
*inv(L)
which givesd
=
det(A)
It is computed from the determinants of the triangular factors:d =
27
The solution to Ax = b is obtained with matrix division:d
=
det(L)
*det(U)
The solution is actually computed by solving two triangular systems:x
=
A\b
Triangular factorization is also used by a specialized function,y
=
L\b,
x
=
U\y
rcond
. This quantity is produced by several of the LINPACK subroutines as an estimate of the reciprocal condition number of the input matrix.
lu
uses the subroutines ZGEDI
and ZGEFA
from LINPACK. For more information, see the LINPACK User's Guide.
\
,/
,det
,inv
,qr
,rcond
,rref
(c) Copyright 1994 by The MathWorks, Inc.