In numerical analysis and linear algebra, lower–upper (LU) decomposition or factorization factors a matrix as the product of a lower triangular matrix and an upper triangular matrix (see matrix multiplication and matrix decomposition). The product sometimes includes a permutation matrix as well. LU decomposition can be viewed as the matrix form of Gaussian elimination. Computers usually solve square systems of linear equations using LU decomposition, and it is also a key step when inverting a matrix or computing the determinant of a matrix. It is also sometimes referred to as LR decomposition (factors into left and right triangular matrices). The LU decomposition algorithm for general matrices was introduced by the Polish astronomer Tadeusz Banachiewicz in 1938.

Definitions

Let be a square matrix. An LU factorization refers to expression of into product of two factors – a lower triangular matrix and an upper triangular matrix such that . Sometimes factorization is impossible without prior reordering of to prevent division by zero or uncontrolled growth of rounding errors. Hence alternative expression becomes , where in formal notation permutation matrix factors and indicate permutation of rows (or columns) of . In theory (or ) is obtained by permutations of rows (or columns) of the identity matrix; in practice the corresponding permutations are applied directly to rows (or columns) of .

Matrix of side has coefficients while two triangle matrices combined contain coefficients, and therefore coefficients of matrices are not independent. The convention is to set unitriangular, i.e. with all main diagonal elements equal to one. However, setting instead matrix unitriangular reduces to the same procedure after transpose of matrix product (cf. properties of matrix transposition):

After transposition, is lower triangle while is upper unitriangular factor of . This demonstrates also, that operations on rows (e.g. pivoting) are equivalent to those on columns of a transposed matrix, and in general choice of row or column algorithm offers no advantage.

In the lower triangular matrix all elements above the main diagonal are zero, in the upper triangular matrix, all the elements below the diagonal are zero. For example, for a matrix , its LU decomposition looks like this:

Without a proper ordering or permutations in the matrix, the factorization may fail to materialize. For example, it is easy to verify (by expanding the matrix multiplication) that . If , then at least one of and has to be zero, which implies that either or is singular. This is impossible if is nonsingular (invertible). In terms of operations, zeroing/elimination of remaining elements of first column of involves division of with , impossible if it is 0. This is a procedural problem. It can be removed by simply reordering the rows of so that the first element of the permuted matrix is nonzero. The same problem in subsequent factorization steps can be removed the same way. For numerical stability against rounding errors/division by small numbers it is important to select of large absolute value (cf. pivoting).

LU through recursion The above example of matrices demonstrates that matrix product of top row and leftmost columns of involved matrices plays special role for to succeed. Let us mark consecutive versions of matrices with and then let us write matrix product in such way that these rows and columns are separated from the rest. In doing so we shall use block matrix notation, such that e.g. is an ordinary number, is a row vector and is a column vector and is sub-matrix of matrix without top row and leftmost column. Then we can replace with a block matrix product. Namely it turns out that one can multiply matrix blocks in such way as if they were ordinary numbers, i.e. row times column, except that now their components are sub-matrices, sometimes reduced to scalars or vectors. Thus denotes a vector obtained from after multiplication of each component by a number is an outer product of vectors i.e. a matrix which first column is next is and so on for all components of and is a product of sub-matrices of

From equality of first and last matrices follow final while matrix becomes updated/replaced with Now comes the crucial observation: nothing prevents us to treat the same way as we did with repeatedly. If dimension of is , after such steps all columns form sub-diagonal part of triangle matrix and all pivots combined with rows form upper triangle matrix as required. In the above example so only two steps suffice.

The above procedure demonstrates that at no step the top diagonal pivot element of consecutive sub-matrices can be zero. To avoid it columns or rows may be swapped so that becomes nonzero. Such procedure involving permutation is called LUP, decomposition with pivoting.

Permutation of columns corresponds to matrix product where is a permutation matrix, i.e. the identity matrix after the same column permutation. After all steps such LUP decomposition applies to Present computation scheme and similar in Cormen et al. are examples of . They demonstrate two general properties of LU factorization:

Recurrence algorithms are not overly costly in terms of algebraic operations yet they suffer from practical disadvantage due to need to update and store most elements of at each step. It will be seen that by reordering calculations it is possible to dispose with storage of intermediate values.

LU factorization with partial pivoting

It turns out that a proper permutation of rows (or columns) to select column (or row) absolute maximal pivot is sufficient for numerically stable LU factorization, except for known pathological cases. It is called '' (LUP):

where and are again lower and upper triangular matrices, and and are corresponding permutation matrices, which, when correspondingly left- and right-multiplied to , reorder the rows and columns of . It turns out that all square matrices can be factorized in this form,. and the factorization is numerically stable in practice. This makes LUP decomposition a useful technique in practice.

A variant called '' at each step involves search of maximum element the way rook moves on a chessboard, along column, row, column again and so on till reaching a pivot maximal in both its row and column. It can be proven that for large matrices of random elements its cost of operations at each step is similarly to partial pivoting proportional to the length of matrix side unlike its square for full pivoting.

LU factorization with full pivoting

An '' involves both row and column permutations to find absolute maximum element in the whole submatrix:

where , , and are defined as before, and is a permutation matrix that reorders the columns of .

Lower-diagonal-upper (LDU) decomposition

A '' (LDU) is a decomposition of the form

where is a diagonal matrix, and and are unitriangular matrices, meaning that all the entries on the diagonals of and are one.

Rectangular matrices Above we required that be a square matrix, but these decompositions can all be generalized to rectangular matrices as well. In that case, and are square matrices both of which have the same number of rows as , and has exactly the same dimensions as . 'Upper triangular' should be interpreted as having only zero entries below the main diagonal, which starts at the upper left corner. Similarly, the more precise term for is that it is the row echelon form of the matrix .

Example

We factor the following matrix:

One way to find the LU decomposition of this simple matrix would be to simply solve the linear equations by inspection. Expanding the matrix multiplication gives

This system of equations is underdetermined. In this case any two nonzero elements of and matrices are parameters of the solution and can be set arbitrarily to any nonzero value. Therefore, to find the unique LU decomposition, it is necessary to put some restriction on and matrices. For example, we can conveniently require the lower triangular matrix to be a unit triangular matrix, so that all the entries of its main diagonal are set to one. Then the system of equations has the following solution:

Substituting these values into the LU decomposition above yields

Existence and uniqueness

Square matrices

Any square matrix admits LUP and PLU factorizations. If is invertible, then it admits an LU (or LDU) factorization if and only if all its leading principal minors are nonzero (for example does not admit an LU or LDU factorization). If is a singular matrix of rank , then it admits an LU factorization if the first leading principal minors are nonzero, although the converse is not true.

If a square, invertible matrix has an LDU factorization (with all diagonal entries of and equal to ), then the factorization is unique. In that case, the LU factorization is also unique if we require that the diagonal of either or consists of ones.

In general, any square matrix could have one of the following: a unique LU factorization (as mentioned above); infinitely many LU factorizations if any of the first columns are linearly dependent; no LU factorization if the first columns are linearly independent and at least one leading principal minor is zero.

In Case 3, one can approximate an LU factorization by changing a diagonal entry to to avoid a zero leading principal minor.

Symmetric positive-definite matrices

If is a symmetric (or Hermitian, if is complex) positive-definite matrix, we can arrange matters so that is the conjugate transpose of . That is, we can write as

This decomposition is called the Cholesky decomposition. If is positive definite, then the Cholesky decomposition exists and is unique. Furthermore, computing the Cholesky decomposition is more efficient and numerically more stable than computing some other LU decompositions.

General matrices

For a (not necessarily invertible) matrix over any field, the exact necessary and sufficient conditions under which it has an LU factorization are known. The conditions are expressed in terms of the ranks of certain submatrices. The Gaussian elimination algorithm for obtaining LU decomposition has also been extended to this most general case.

Algorithms

Closed formula

When an LDU factorization exists and is unique, there is a closed (explicit) formula for the elements of , , and in terms of ratios of determinants of certain submatrices of the original matrix . In particular, , and for , is the ratio of the -th principal submatrix to the -th principal submatrix. Computation of the determinants is computationally expensive, so this explicit formula is not used in practice.

Using Gaussian elimination The following algorithm is essentially a modified form of Gaussian elimination. Computing an LU decomposition using this algorithm requires floating-point operations, ignoring lower-order terms. Partial pivoting adds only a quadratic term; this is not the case for full pivoting.

Generalized explanation

Notation Given an matrix define as the original, unmodified version of the matrix . The parenthetical superscript (e.g., ) of the matrix is the version of the matrix. The matrix is the matrix in which the elements below the main diagonal have already been eliminated to 0 through Gaussian elimination for the first columns.

Below is a matrix to observe to help us remember the notation (where each represents any real number in the matrix):

Procedure During this process, we gradually modify the matrix using row operations until it becomes the matrix in which all the elements below the main diagonal are equal to zero. During this, we will simultaneously create two separate matrices and , such that .