Post · 13 min read· pp. 745–751

What Is an LU Factorization?

An LU factorization of an n×nn\times n matrix AA is a factorization A=LUA = LU, where LL is unit lower triangular and UU is upper triangular. “Unit” means that LL has ones on the diagonal. Example:

[3−111−131−1−1−1311113]=[1000−13100−13−1210131201][3−11108343−2300410003].(1)\notag \left[\begin{array}{rrrr} 3 & -1 & 1 & 1\\ -1 & 3 & 1 & -1\\ -1 & -1 & 3 & 1\\ 1 & 1 & 1 & 3 \end{array}\right] = \left[\begin{array}{rrrr} 1 & 0 & 0 & 0\\ -\frac{1}{3} & 1 & 0 & 0\\ -\frac{1}{3} & -\frac{1}{2} & 1 & 0\\ \frac{1}{3} & \frac{1}{2} & 0 & 1 \end{array}\right] \left[\begin{array}{rrrr} 3 & -1 & 1 & 1\\ 0 & \frac{8}{3} & \frac{4}{3} & -\frac{2}{3}\\ 0 & 0 & 4 & 1\\ 0 & 0 & 0 & 3 \end{array}\right]. \qquad (1)

An LU factorization simplifies the solution of many problems associated with linear systems. In particular, solving a linear system Ax=bAx = b reduces to solving the triangular systems Ly=bLy = b and Ux=yUx = y, since then b=L(Ux)b = L(Ux).

For a given AA, an LU factorization may or may not exist, and if it does exist it may not be unique. Conditions for existence and uniqueness are given in the following result (see Higham, 2002, Thm. 9.1 for a proof). Denote by Ak=A(1 ⁣:k,1 ⁣:k)A_k = A(1\colon k,1\colon k) the leading principal submatrix of AA of order kk.

Theorem 1. The matrix A∈Rn×nA\in\mathbb{R}^{n\times n} has a unique LU factorization if and only if AkA_k is nonsingular for k=1 ⁣:n−1k=1\colon n-1. If AkA_k is singular for some 1≤k≤n−11\le k \le n-1 then the factorization may exist, but if so it is not unique.

Note that the (non)singularity of AA plays no role in Theorem 1. However, if AA is nonsingular and has an LU factorization then the factorization is unique. Indeed if AA has LU factorizations A=L1U1=L2U2A = L_1U_1 = L_2U_2 then the UiU_i are necessarily nonsingular and so L2−1L1=U2U1−1L_2^{-1}L_1 = U_2U_1^{-1}. The left side of this equation is unit lower triangular and the right side is upper triangular; therefore both sides must equal the identity matrix, which means that L1=L2L_1 = L_2 and U1=U2U_1 = U_2, as required.

Equating leading principal submatrices in A=LUA = LU gives Ak=LkUkA_k = L_k U_k, which implies that det⁡(Ak)=det⁡(Uk)=u11u22…ukk\det(A_k) = \det(U_k) = u_{11} u_{22} \dots u_{kk}. Hence ukk=det⁡(Ak)/det⁡(Ak−1)u_{kk} = \det(A_k)/\det(A_{k-1}). In fact, such determinantal formulas hold for all the elements of LL and UU:

ℓij=det⁡(A([1:j−1, i],1:j))det⁡(Aj),i>j,uij=det⁡(A(1:i,[1:i−1, j]))det⁡(Ai−1),i≤j.\notag \begin{aligned} \ell_{ij} &= \frac{ \det\bigl( A( [1:j-1, \, i], 1:j ) \bigr) }{ \det( A_j ) }, \quad i > j, \\ u_{ij} &= \frac{ \det\bigl( A( 1:i, [1:i-1, \, j] ) \bigr) } { \det( A_{i-1} ) }, \quad i \le j. \end{aligned}

Here, A(u,v)A(u,v), where uu and vv are vectors of subscripts, denotes the submatrix formed from the intersection of the rows indexed by uu and the columns indexed by vv.

Relation with Gaussian Elimination

LU factorization is intimately connected with Gaussian elimination. Recall that Gaussian elimination transforms a matrix A(1)=A∈Rn×nA^{(1)} = A\in\mathbb{R}^{n\times n} to upper triangular form U=A(n)U = A^{(n)} in n−1n-1 stages. At the kkth stage, multiples of row kk are added to the later rows to eliminate the elements below the diagonal in column kk, using the formulas

aij(k+1)=aij(k)−mikakj(k),i=k+1 ⁣:n,  j=k+1 ⁣:n,\notag a_{ij}^{(k+1)} = a_{ij}^{(k)} - m_{ik} a_{kj}^{(k)}, \quad i = k+1 \colon n, \; j = k+1 \colon n,

where the quantities mik=aik(k)/akk(k)m_{ik} = a_{ik}^{(k)} / a_{kk}^{(k)} are the multipliers. Of course each akk(k)a_{kk}^{(k)} must be nonzero for these formulas to be defined, and this is connected with the conditions of Theorem 1, since ukk=akk(k)u_{kk} = a_{kk}^{(k)}. The final UU is the upper triangular LU factor, with uij=aij(i)u_{ij} = a_{ij}^{(i)} for j≥ij\ge i, and ℓij=mij\ell_{ij} = m_{ij} for i>ji > j, that is, the multipliers make up the LL factor (for a proof of these properties see any textbook on numerical linear algebra).

The matrix factorization viewpoint is well established as a powerful paradigm for thinking and computing. Separating the computation of LU factorization from its application is beneficial. For example, given A=LUA = LU we saw above how to solve Ax=bAx = b. If we need to solve for another right-hand side b2b_2 we can just solve Ly2=b2Ly_2 = b_2 and Ux2=y2Ux_2 = y_2, re-using the LU factorization. Similarly, solving ATz=cA^Tz = c reduces to solving the triangular systems UTw=cU^T w = c and LTz=wL^Tz = w.

Computation

An LU factorization can be computed by directly solving for the components of LL and UU in the equation A=LUA = LU. Indeed because LL has unit diagonal the first row of UU is the same as the first row of AA, and ak1=ℓk1u11=ℓk1a11a_{k1} = \ell_{k1} u_{11} = \ell_{k1} a_{11} then determines the first column of LL. One can go on to determine the kkth row of UU and the kkth row of LL, for k=2 ⁣:nk = 2\colon n. This leads to the Doolittle method, which involves inner products of partial rows of LL and partial columns of UU.

Given the equivalence between LU factorization and Gaussian elimination we can also employ the Gaussian elimination equations:

% kji form of LU factorization.\mboxfor k=1:n−1\mboxfor j=k+1:n\mboxfor i=k+1:naij(k+1)=aij(k)−aik(k)akj(k)/akk(k)\mboxend\mboxend\mboxend\notag \begin{array}{l} \%~kji~\mathrm{form~of~LU~factorization.}\\ \mbox{for}~k=1:n-1 \\ \qquad \mbox{for}~ j=k+1:n \\ \qquad \qquad \mbox{for}~ i=k+1:n \\ \qquad\qquad\qquad a_{ij}^{(k+1)} = a_{ij}^{(k)} - a_{ik}^{(k)}a_{kj}^{(k)} / a_{kk}^{(k)}\\ \qquad\qquad\mbox{end}\\ \qquad\mbox{end}\\ \mbox{end}\\ \end{array}

This kjikji ordering of the loops in the factorization is the basis of early Fortran implementations of LU factorization, such as that in LINPACK. The inner loop travels down the columns of AA, accessing contiguous elements of AA since Fortran stores arrays by column. Interchanging the two inner loops gives the kijkij ordering, which updates the matrix a row at a time, and is appropriate for a language such as C that stores arrays by row.

The ijkijk and jikjik orderings correspond to the Doolittle method. The last two of the 3!=63! = 6 orderings are the ikjikj and jkijki orderings, to which we will return later.

Schur Complements

For A∈Rn×nA\in\mathbb{R}^{n\times n} with α=a11≠0\alpha = a_{11} \ne 0 we can write

A=[αbTcD]=[10c/αIn−1][αbT0D−cbT/α]=:L1U1.(2)\notag A = \begin{bmatrix} \alpha & b^T \\ c & D \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ c/\alpha & I_{n-1} \end{bmatrix} \begin{bmatrix} \alpha & b^T \\ 0 & D - cb^T/\alpha \end{bmatrix} = : L_1U_1. \qquad (2)

The (n−1)×(n−1)(n-1)\times (n-1) matrix S=D−cbT/αS = D - cb^T/\alpha is called the Schur complement of α\alpha in AA.

The first row and column of L1L_1 and U1U_1 have the correct forms for a unit lower triangular matrix and an upper triangular matrix, respectively. If we can find an LU factorization S=L2U2S = L_2U_2 then

A=[10c/αL2][αbT0U2]\notag A = \begin{bmatrix} 1 & 0 \\ c/\alpha & L_2 \end{bmatrix} \begin{bmatrix} \alpha & b^T \\ 0 & U_2 \end{bmatrix}

is an LU factorization of AA. Note that this is simply another way to express the kjikji algorithm above.

For several matrix structures it is immediate that α≠0\alpha \ne 0. If we can show that the Schur complement inherits the same structure then it follows by induction that we can compute the factorization for SS, and so an LU factorization of AA exists. Classes of matrix for which a11≠0a_{11} \ne 0 and AA being in the class implies the Schur complement SS is also in the class include

  • symmetric positive definite matrices,
  • MM-matrices,
  • matrices (block) diagonally dominant by rows or columns.

(The proofs of these properties are nontrivial.) Note that the matrix (1) is row diagonally dominant, as is its UU factor, as must be the case since its rows are contained in Schur complements.

We say that AA has upper bandwidth qq if aij=0a_{ij} = 0 for j>i+qj>i+q and lower bandwidth pp if aij=0a_{ij} = 0 for i>j+pi>j+p. Another use of (2) is to show that LL and UU inherit the bandwidths of AA.

Theorem 2. Let A∈Rn×nA\in\mathbb{R}^{n\times n} have lower bandwidth pp and upper bandwidth qq. If AA has an LU factorization then LL has lower bandwidth pp and UU has upper bandwidth qq.

Proof. In (2), the first column of L1L_1 and the first row of U1U_1 have the required structure and SS has upper bandwidth qq and lower bandwidth pp, since cc and bb have only pp and qq nonzero components, respectively. The result follows by induction.

Block Implementations

In order to achieve high performance on modern computers with their hierarchical memories, LU factorization is implemented in a block form expressed in terms of matrix multiplication and the solution of multiple right-hand side triangular systems. We describe two block forms of LU factorization. First, consider a block form of (2) with block size pp, where A11A_{11} is p×pp \times p:

A=[A11A12A21A22]=[L110L21In−p][U11U120S].\notag A = \begin{bmatrix} A_{11} & A_{12}\\ A_{21} & A_{22} \end{bmatrix} = \begin{bmatrix} L_{11} & 0 \\ L_{21}& I_{n-p} \end{bmatrix} \begin{bmatrix} U_{11} & U_{12} \\ 0 & S \end{bmatrix}.

Here, SS is the Schur complement of A11A_{11} in AA, given by S=A22−A21A11−1A12S = A_{22} - A_{21}A_{11}^{-1}A_{12}. This leads to the following algorithm:

  1. Factor A11=L11U11A_{11} = L_{11}U_{11}.
  2. Solve L11U12=A12L_{11}U_{12} = A_{12} for U12U_{12}.
  3. Solve L21U11=A21L_{21}U_{11} = A_{21} for L21L_{21}.
  4. Form S=A22−L21U12S = A_{22}-L_{21}U_{12}.
  5. Repeat steps 1–4 on SS to obtain S=L22U22S = L_{22}U_{22}.

The factorization on step 1 can be done by any form of LU factorization. This algorithm is known as a right-looking algorithm, since it accesses data to the right of the block being worked on (in particular, at each stage lines 2 and 4 access the last few columns of the matrix).

An alternative algorithm can derived by considering a block 3×33\times 3 partitioning, in which we assume we have already computed the first block column of LL and UU:

A=[A11A12A13A21A22A23A31A32A33]=[L1100L21L220L31L32I][U11U12×0U22×00×].\notag A = \begin{bmatrix} A_{11} & A_{12} & A_{13}\\ A_{21} & A_{22} & A_{23}\\ A_{31} & A_{32} & A_{33} \end{bmatrix} = \begin{bmatrix} L_{11} & 0 & 0 \\ L_{21} & L_{22}& 0 \\ L_{31} & L_{32} & I \end{bmatrix} \begin{bmatrix} U_{11} & U_{12} & \times \\ 0 & U_{22} & \times \\ 0 & 0 & \times \end{bmatrix}.

We now compute the middle block column of LL and UU, comprising pp columns, by

  1. Solve L11U12=A12L_{11}U_{12} = A_{12} for U12U_{12}.
  2. Factor A22−L21U12=L22U22A_{22}-L_{21}U_{12} = L_{22}U_{22}.
  3. Solve L32U22=A32−L31U12L_{32}U_{22} = A_{32} - L_{31}U_{12} for L32L_{32}.
  4. Repartition so that the first two block columns become a single block column and repeat steps 1–4.

This algorithm corresponds to the jkijki ordering. Note that the Schur complement is updated only a block column at a time. Because the algorithm accesses data only to the left of the block column being worked on, it is known as a left-looking algorithm.

Our description of these block algorithms emphasizes the mathematical ideas. The implementation details, especially for the left-looking algorithm, are not trivial. The optimal choice of block size pp will depend on the machine, but pp is typically in the range 6464—512512.

An important point is that all these different forms of LU factorization, no matter which ijkijk ordering or which value of pp, carry out the same operations. The only difference is the order in which the operations are performed (and the order in which the data is accessed). Even the rounding errors are the same for all versions (assuming the use of “plain vanilla” floating-point arithmetic).

Rectangular Matrices

Although it is most commonly used for square matrices, LU factorization is defined for rectangular matrices, too. If A∈Rm×nA\in\mathbb{R}^{m\times n} then the factorization has the form A=LUA = LU with L∈Rm×mL\in\mathbb{R}^{m\times m} lower triangular and U∈Rm×nU\in\mathbb{R}^{m\times n} upper trapezoidal. The conditions for existence and uniqueness of an LU factorization of AA are the same as those for A(1 ⁣:p,1 ⁣:p)A(1\colon p, 1\colon p), where p=min⁡(m,n)p = \min(m,n).

Block LU Factorization

Another form of LU factorization relaxes the structure of LL and UU from triangular to block triangular, with LL having identity matrices on the diagonal:

L=[IL21I⋮⋱Lm1…Lm,m−1I],U=[U11U12…U1mU22⋮⋱Um−1,mUmm].\notag L = \begin{bmatrix} I & & & \\ L_{21} & I & & \\ \vdots & & \ddots & \\ L_{m1} & \dots & L_{m,m-1} & I \end{bmatrix}, \quad U = \begin{bmatrix} U_{11} & U_{12} & \dots & U_{1m} \\ & U_{22} & & \vdots \\ & & \ddots & U_{m-1,m} \\ & & & U_{mm} \end{bmatrix}.

Note that UU is not, in general, upper triangular.

An example of a block LU factorization is

A=[0111−1111−2342−1213]=[1000010012101101][0111−1111001−100−11].\notag A = \left[ \begin{array}{rr|rr} 0 & 1 & 1 & 1 \\ -1 & 1 & 1 & 1 \\\hline -2 & 3 & 4 & 2 \\ -1 & 2 & 1 & 3 \\ \end{array} \right] = \left[ \begin{array}{cc|cc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\\hline 1 & 2 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ \end{array} \right] \left[ \begin{array}{rr|rr} 0 & 1 & 1 & 1 \\ -1 & 1 & 1 & 1 \\\hline 0 & 0 & 1 & -1 \\ 0 & 0 & -1 & 1 \\ \end{array} \right].

LU factorization fails on AA because of the zero (1,1)(1,1) pivot. This block LU factorization corresponds to using the leading 2×22\times 2 principal submatrix of AA to eliminate the elements in the (3 ⁣:4,1 ⁣:2)(3\colon 4,1\colon 2) submatrix. In the context of a linear system Ax=bAx=b, we have effectively solved for the variables x1x_1 and x2x_2 in terms of x3x_3 and x4x_4 and then substituted for x1x_1 and x2x_2 in the last two equations.

Conditions for the existence of a block LU factorization are analogous to, but less stringent than, those for LU factorization in Theorem 1.

Theorem 3. The matrix A∈Rn×nA\in\mathbb{R}^{n\times n} has a unique block LU factorization if and only if the first m−1m-1 leading principal block submatrices of AA are nonsingular.

The conditions in Theorem 3 can be shown to be satisfied if AA is block diagonally dominant by rows or columns.

Note that to solve a linear system Ax=bAx = b using a block LU factorization we need to solve Ly=bLy = b and Ux=yUx = y, but the latter system is not triangular and requires the solution of systems Uiixi=yiU_{ii}x_i = y_i involving the diagonal blocks of UU, which would normally be done by (standard) LU factorization.

Sensitivity

If AA has a unique LU factorization then for a small enough perturbation ΔA\Delta A an LU factorization A+ΔA=(L+ΔL)(U+ΔU)A + \Delta A = (L + \Delta L)(U + \Delta U) exists. To first order, this equation is ΔA=ΔLU+LΔU\Delta A = \Delta L U + L \Delta U, which gives

L−1ΔAU−1=L−1ΔL+ΔUU−1.\notag L^{-1}\Delta A \mskip2mu U^{-1} = L^{-1}\Delta L + \Delta U \mskip2mu U^{-1}.

Since ΔL\Delta L is strictly lower triangular and ΔU\Delta U is upper triangular, we have, to first order,

ΔL=L tril(L−1ΔAU−1),ΔU=triu(L−1ΔAU−1)U,\notag \Delta L = L \mskip 1mu \mathrm{tril}( L^{-1}\Delta A U^{-1} ), \quad \Delta U = \mathrm{triu}( L^{-1}\Delta A U^{-1} )U,

where tril\mathrm{tril} denotes the strictly lower triangular part and triu\mathrm{triu} the strictly upper triangular part. Clearly, the sensitivity of the LU factors depends on the inverses of LL and UU. However, in most situations, such as when we are solving a linear system Ax=bAx = b, it is the backward stability of the LU factors, not their sensitivity, that is relevant.

Pivoting and Numerical Stability

Since not all matrices have an LU factorization, we need the option of applying row and column interchanges to ensure that the pivots are nonzero unless the column in question is already in triangular form.

In finite precision computation it is important that computed LU factors L^\widehat L and U^\widehat U are numerically stable in the sense that L^U^=A+ΔA\widehat L \widehat U = A + \Delta A with ∥ΔA∥≤cnu∥A∥\|\Delta A\|\le c_n u \|A\|, where cnc_n is a constant and uu is the unit roundoff. For certain matrix properties, such as diagonal dominance by rows or columns, numerical stability is guaranteed, but in general it is necessary to incorporate row interchanges, or row or column interchanges, in order to obtain a stable factorization.

See What Is the Growth Factor for Gaussian Elimination? for details of pivoting strategies and see Randsvd Matrices with Large Growth Factors for some recent research on growth factors.

References

This is a minimal set of references, which contain further useful references within.

This article is part of the “What Is” series, available from https://nhigham.com/category/what-is and in PDF form from the GitHub repository https://github.com/higham/what-is.