maths.free › Numerical Methods › Linear systems and ODEs › LU decomposition
LU decomposition
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…
LU decomposition
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 A be a square matrix. An LU factorization refers to expression of A into product of two factors, a lower triangular matrix L and an upper triangular matrix U such that A = LU. Sometimes factorization is impossible without prior reordering of A to prevent division by zero or uncontrolled growth of rounding errors. Hence alternative expression becomes PAQ = LU, where in formal notation permutation matrix factors P and Q indicate permutation of rows (or columns) of A. In theory P (or Q) 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 A.
Matrix A of side n has \(n^{2}\) coefficients while two triangle matrices combined contain n(n + 1) coefficients, and therefore n coefficients of matrices LU are not independent. The convention is to set L unitriangular, i.e. with all n main diagonal elements equal to one. However, setting instead U matrix unitriangular reduces to the same procedure after transpose of matrix product (cf. properties of matrix transposition): \[B = A^\textsf{T} = (LU)^\textsf{T} =U^\textsf{T}L^\textsf{T}.\] After transposition, U is lower triangle while L is upper unitriangular factor of B. 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 3 × 3 matrix A, its LU decomposition looks like this: \[\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} = \begin{bmatrix} \ell_{11} & 0 & 0 \\ \ell_{21} & \ell_{22} & 0 \\ \ell_{31} & \ell_{32} & \ell_{33} \end{bmatrix} \begin{bmatrix} u_{11} & u_{12} & u_{13} \\ 0 & u_{22} & u_{23} \\ 0 & 0 & u_{33} \end{bmatrix}.\]
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 \(a_{11} = \ell_{11} u_{11}\). If \(a_{11} = 0\), then at least one of \(\ell_{11}\) and \(u_{11}\) has to be zero, which implies that either L or U is singular. This is impossible if A is nonsingular (invertible). In terms of operations, zeroing/elimination of remaining elements of first column of A involves division of \(a_{21}, a_{31}\) with \(a_{11}\), impossible if it is 0. This is a procedural problem. It can be removed by simply reordering the rows of A 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 \(a_{11}\) of large absolute value (cf. pivoting).
LU through recursion
The above example of 3 × 3 matrices demonstrates that matrix product of top row and leftmost columns of involved matrices plays special role for LU to succeed. Let us mark consecutive versions of matrices with \((0),\;(1),\dots\) and then let us write matrix product \(A\equiv A^{(0)}=L^{(0)}U^{(0)}\) 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. \(a\equiv a_{11}\) is an ordinary number, \({\bf w}^\textsf{T} \equiv(a_{12}, a_{13})^\textsf{T}\) is a row vector and \({\bf v}=(a_{21},a_{31})\) is a column vector and \(A'\) is sub-matrix of matrix \(A^{(0)}\) without top row and leftmost column. Then we can replace \(A^{(0)}=L^{(0)}U^{(0)}\) 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 \(u{\bf l}\) denotes a vector obtained from \({\bf l}\) after multiplication of each component by a number \(u\), \({\bf lu}^\textsf{T}\) is an outer product of vectors \({\bf l, u}\), i.e. a matrix which first column is \(u_{12}{\bf l}\), next is \(u_{13}{\bf l}\) and so on for all components of \({\bf u}\) and \(L^{(1)}U^{(1)}\) is a product of sub-matrices of \(L^{(0)},\;U^{(0)}\) \[\begin{aligned} \left( \begin{array}{c|c} a & {\bf w}^\textsf{T} \\ \hline \\[-0.5em] {\bf v} & \quad A' \quad \\[-0.5em] \\ \end{array} \right) &= \left( \begin{array}{c|c} {\rm 1} & {\bf 0}^\textsf{T} \\ \hline \\[-0.5em] {\bf l} & \quad L^{(1)} \quad \\[-0.5em] \\ \end{array} \right)\; \left( \begin{array}{c|c} u & {\bf u}^\textsf{T} \\ \hline \\[-0.5em] {\bf 0} & \quad U^{(1)} \\[-0.5em] \\ \end{array} \right) \\ &=\left( \begin{array}{c|c} u & {\bf u}^\textsf{T} \\ \hline \\[-0.5em] u{\bf l} & \quad {\bf lu}^\textsf{T} + L^{(1)}U^{(1)} \\[-0.5em] \\ \end{array} \right) \end{aligned}\]
From equality of first and last matrices follow final \(u=a\), \(\bf u=w\), \({\bf l}={(1/a)}{\bf v}\) while matrix \(A'\) becomes updated/replaced with \(A^{(1)}\equiv L^{(1)}U^{(1)}=\) \(A'-{\bf lu}^\textsf{T}\). Now comes the crucial observation: nothing prevents us to treat \(A^{(1)}\) the same way as we did with \(A^{(0)}\), repeatedly. If dimension of \(A\) is n × n, after n− 1 such steps all columns \(\bf v\) form sub-diagonal part of triangle matrix \(L\) and all pivots \(a\) combined with rows \({\bf w}^\textsf{T}\) form upper triangle matrix \(U\), as required. In the above example n = 3 so only two steps suffice.
The above procedure demonstrates that at no step the top diagonal pivot element \(a\) of consecutive sub-matrices can be zero. To avoid it columns or rows may be swapped so that \(a\) becomes nonzero. Such procedure involving permutation is called LUP, decomposition with pivoting.
Permutation of columns corresponds to matrix product \(AQ^{(0)}\) where \(Q^{(0)}\) is a permutation matrix, i.e. the identity matrix \(I\) after the same column permutation. After all steps such LUP decomposition applies to \(AQ^{(0)}\cdots Q^{(n-1)}\equiv AQ=LU\). Present computation scheme and similar in Cormen et al. are examples of recurrence algorithms. They demonstrate two general properties of LU factorization:
Condensed: the full section is in Wikipedia.
LU factorization with partial pivoting
It turns out that a proper permutation of rows (or columns) to select column (or row) absolute maximal pivot a11 is sufficient for numerically stable LU factorization, except for known pathological cases. It is called 'LU factorization with partial pivoting' (LUP): \[PA = LU, \quad (AQ=LU),\] where L and U are again lower and upper triangular matrices, and P and Q are corresponding permutation matrices, which, when correspondingly left- and right-multiplied to A, reorder the rows and columns of A. 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 'rook pivoting' 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 'LU factorization with full pivoting' involves both row and column permutations to find absolute maximum element in the whole submatrix: \[PAQ = LU,\] where L, U, and P are defined as before, and Q is a permutation matrix that reorders the columns of A.
Lower-diagonal-upper (LDU) decomposition
A 'lower-diagonal-upper decomposition' (LDU) is a decomposition of the form \[A = LDU,\] where D is a diagonal matrix, and L and U are unitriangular matrices, meaning that all the entries on the diagonals of L and U are one.
Rectangular matrices
Above we required that A be a square matrix, but these decompositions can all be generalized to rectangular matrices as well. In that case, L and D are square matrices both of which have the same number of rows as A, and U has exactly the same dimensions as A. '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 U is that it is the row echelon form of the matrix A.
Example
We factor the following 2 × 2 matrix: \[\begin{bmatrix} 4 & 3 \\ 6 & 3 \end{bmatrix} = \begin{bmatrix} \ell_{11} & 0 \\ \ell_{21} & \ell_{22} \end{bmatrix} \begin{bmatrix} u_{11} & u_{12} \\ 0 & u_{22} \end{bmatrix}.\]
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 \[\left\{ \begin{alignedat}{4} \ell_{11} \cdot u_{11} && \;+\; && 0 \cdot 0 &&\;=\; && 4 \\ \ell_{11} \cdot u_{12} && \;+\; && 0 \cdot u_{22} &&\;=\; && 3 \\ \ell_{21} \cdot u_{11} && \;+\; && \ell_{22} \cdot 0 &&\;=\; && 6 \\ \ell_{21} \cdot u_{12} && \;+\; && \ell_{22} \cdot u_{22} &&\;=\; && 3 \end{alignedat}\right.\]
This system of equations is underdetermined. In this case any two nonzero elements of L and U 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 L and U matrices. For example, we can conveniently require the lower triangular matrix L 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: \[\begin{aligned} \ell_{11} &= \ell_{22} = 1 \\ \ell_{21} &= 1.5 \\ u_{11} &= 4 \\ u_{12} &= 3 \\ u_{22} &= -1.5 \end{aligned}\]
Substituting these values into the LU decomposition above yields \[\begin{bmatrix} 4 & 3 \\ 6 & 3 \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 1.5 & 1 \end{bmatrix} \begin{bmatrix} 4 & 3 \\ 0 & -1.5 \end{bmatrix}.\]
Square matrices
Any square matrix A admits LUP and PLU factorizations. If A is invertible, then it admits an LU (or LDU) factorization if and only if all its leading principal minors are nonzero (for example \(\left[\begin{smallmatrix} 0 & 1 \\ 1 & 0 \end{smallmatrix}\right]\) does not admit an LU or LDU factorization). If A is a singular matrix of rank k, then it admits an LU factorization if the first k 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 L and U equal to 1), then the factorization is unique. In that case, the LU factorization is also unique if we require that the diagonal of either L or U consists of ones.
In general, any square matrix An×n could have one of the following:
- a unique LU factorization (as mentioned above);
- infinitely many LU factorizations if any of the first (n − 1) columns are linearly dependent;
- no LU factorization if the first (n − 1) 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 aij to aij ± ε to avoid a zero leading principal minor.
Symmetric positive-definite matrices
If A is a symmetric (or Hermitian, if A is complex) positive-definite matrix, we can arrange matters so that U is the conjugate transpose of L. That is, we can write A as \[A = LL^*\,.\]
This decomposition is called the Cholesky decomposition. If A 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.
Closed formula
When an LDU factorization exists and is unique, there is a closed (explicit) formula for the elements of L, D, and U in terms of ratios of determinants of certain submatrices of the original matrix A. In particular, D1 = A1,1, and for i = 2, ... , n, Di is the ratio of the i-th principal submatrix to the (i − 1)-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 2/3n floating-point operations, ignoring lower-order terms. Partial pivoting adds only a quadratic term; this is not the case for full pivoting.
Randomized algorithm
It is possible to find a low rank approximation to an LU decomposition using a randomized algorithm. Given an input matrix A and a desired low rank k, the randomized LU returns permutation matrices P, Q and lower/upper trapezoidal matrices L, U of size m × k and k × n respectively, such that with high probability ‖PAQ − LU‖2 ≤ Cσk+1, where C is a constant that depends on the parameters of the algorithm and σk+1 is the (k+1)-th singular value of the input matrix A.
Sasa Hakuna kifaa cha kupigia hesabu kinachoweza kufanya hesabu, lakini kifaa hicho kinaweza kutumiwa katika hesabu.
Ishara zinazotumiwa hapa
Vaa alama yoyote ya ufafanuzi kamili, picha, na maana ya kila herufi.
Maswali ambayo watu huuliza
Why not just solve exactly?
Most equations have no closed-form solution at all, and many that do are unusable in practice. A numerical method delivers as many correct digits as you need, and a good one tells you how many that is.
Why can Newton's method fail?
If it starts where the tangent is nearly flat it shoots far away; near a repeated root it slows to a crawl; and with several roots it may land on the wrong one. A bracketing method like bisection is slower but cannot fail.
Sehemu za ukurasa huu zimebadilishwa kutoka kwa Wikipedia (CC BY-SA 4.0). Tumekamatwa na kukosolewa tena hapa; makosa ni yetu.
Mengi zaidi katika Numerical Methods
Root finding: bisection and Newton's methodNumerical integration: trapezoid and SimpsonInterpolation and Taylor approximationFloating point and error