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 {{nowrap|A = (a_{i,j})_{1 \leq i,j \leq N},}} define A^{(0)} 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): A^{(n-1)} = \begin{pmatrix} * & & & \cdots & & & * \\ 0 & \ddots & & & & \\ & \ddots & * & & & \\ \vdots & & 0 & a_{n,n}^{(n-1)} & & & \vdots \\ & & \vdots & a_{i,n}^{(n-1)} & * \\ & & & \vdots & \vdots & \ddots \\ 0 & \cdots & 0 & a_{i,n}^{(n-1)} & * & \cdots & * \end{pmatrix}
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 . We define the final
permutation matrix as the identity matrix which has all the same rows swapped in the same order as the matrix while it transforms into the matrix . For our matrix , we may start by swapping rows to provide the desired conditions for the -th column. For example, we might swap rows to perform partial pivoting, or we might do it to set the pivot element on the main diagonal to a nonzero number so that we can complete the Gaussian elimination. For our matrix , we want to set every element below a_{n,n}^{(n-1)} to zero (where a_{n,n}^{(n-1)} is the element in the -th column of the main diagonal). We will denote each element below a_{n,n}^{(n-1)} as a_{i,n}^{(n-1)} (where ). To set a_{i,n}^{(n-1)} to zero, we set for each row . For this operation, {{nowrap|\ell_{i,n} := {a_{i,n}^{(n-1)}}/{a_{n,n}^{(n-1)}}.}} Once we have performed the row operations for the first columns, we have obtained an
upper triangular matrix which is denoted by . We can also create the
lower triangular matrix denoted as , by directly inputting the previously calculated values of via the formula below. L = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ \ell_{2,1} & \ddots & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ \ell_{N,1} & \cdots & \ell_{N,N-1} & 1 \end{pmatrix}
Example If we are given the matrix A = \begin{pmatrix} 0 & 5 & \frac{22}{3} \\ 4 & 2 & 1 \\ 2 & 7 & 9 \\ \end{pmatrix}, we will choose to implement partial pivoting and thus swap the first and second row so that our matrix and the first iteration of our matrix respectively become A^{(0)}=\begin{pmatrix} 4 & 2 & 1 \\ 0 & 5 & \frac{22}{3} \\ 2 & 7 & 9 \\ \end{pmatrix},\quad P^{(0)}=\begin{pmatrix} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \\ \end{pmatrix}. Once we have swapped the rows, we can eliminate the elements below the main diagonal on the first column by performing \begin{alignat}{0} row_2=row_2-(\ell_{2,1})\cdot row_1 \\ row_3=row_3-(\ell_{3,1})\cdot row_1 \end{alignat} such that, \begin{alignat}{0} \ell_{2,1}= \frac{0}{4}=0 \\ \ell_{3,1}= \frac{2}{4}=0.5 \end{alignat} Once these rows have been subtracted, we have derived from the matrix A^{(1)}= \begin{pmatrix} 4 & 2 & 1 \\ 0 & 5 & \frac{22}{3} \\ 0 & 6 & 8.5 \\ \end{pmatrix}. Because we are implementing partial pivoting, we swap the second and third rows of our derived matrix and the current version of our matrix respectively to obtain A^{(1)}=\begin{pmatrix} 4 & 2 & 1 \\ 0 & 6 & 8.5 \\ 0 & 5 & \frac{22}{3} \\ \end{pmatrix}, \quad P^{(1)}=\begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \\ \end{pmatrix}. Now, we eliminate the elements below the main diagonal on the second column by performing such that . Because no nonzero elements exist below the main diagonal in our current iteration of after this row subtraction, this row subtraction derives our final matrix (denoted as ) and final matrix: A^{(2)}=A^{(N-1)}=U=\begin{pmatrix} 4 & 2 & 1 \\ 0 & 6 & 8.5 \\ 0 & 0 & 0.25 \\ \end{pmatrix}, \quad P=\begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \\ \end{pmatrix}. After also switching the corresponding rows, we obtain our final matrix: L = \begin{pmatrix} 1 & 0 & 0 \\ \ell_{3,1} & 1 & 0 \\ \ell_{2,1} & \ell_{3,2} & 1 \\ \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 \\ 0.5 & 1 & 0 \\ 0 & \frac{5}{6} & 1 \\ \end{pmatrix} Now these matrices have a relation such that .
Relations when no rows are swapped If we did not swap rows at all during this process, we can perform the row operations simultaneously for each column by setting A^{(n)} := L^{-1}_n A^{(n-1)}, where L^{-1}_n is the identity matrix with its -th column replaced by the
transposed vector . In other words, the lower triangular matrix L^{-1}_n = \begin{pmatrix} 1 & & & & & \\ & \ddots & & & & \\ & & 1 & & & \\ & & -\ell_{n+1,n} & & & \\ & & \vdots & & \ddots & \\ & & -\ell_{N,n} & & & 1 \end{pmatrix}. Performing all the row operations for the first columns using the A^{(n)} := L^{-1} _n A^{(n-1)} formula is equivalent to finding the decomposition A = L_1 L_1^{-1} A^{(0)} = L_1 A^{(1)} = L_1 L_2 L_2^{-1} A^{(1)} = L_1 L_2 A^{(2)} = \dotsm = L_1 \dotsm L_{N-1} A^{(N-1)}. Denote so that . Now let's compute the sequence of . We know that has the following formula: L_n = \begin{pmatrix} 1 & & & & & \\ & \ddots & & & & \\ & & 1 & & & \\ & & \ell_{n+1,n} & & & \\ & & \vdots & & \ddots & \\ & & \ell_{N,n} & & & 1 \end{pmatrix} If there are two lower triangular matrices with 1s in the main diagonal, and neither have a nonzero item below the main diagonal in the same column as the other, then we can include all nonzero items at their same location in the product of the two matrices. For example: \left(\begin{array}{ccccc} 1 & 0 & 0 & 0 & 0 \\ 77 & 1 & 0 & 0 & 0 \\ 12 & 0 & 1 & 0 & 0 \\ 63 & 0 & 0 & 1 & 0 \\ 7 & 0 & 0 & 0 & 1 \end{array}\right)\left(\begin{array}{ccccc} 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 22 & 1 & 0 & 0 \\ 0 & 33 & 0 & 1 & 0 \\ 0 & 44 & 0 & 0 & 1 \end{array}\right)=\left(\begin{array}{ccccc} 1 & 0 & 0 & 0 & 0 \\ 77 & 1 & 0 & 0 & 0 \\ 12 & 22 & 1 & 0 & 0 \\ 63 & 33 & 0 & 1 & 0 \\ 7 & 44 & 0 & 0 & 1 \end{array}\right) Finally, multiply together and generate the fused matrix denoted as (as previously mentioned). Using the matrix , we obtain . It is clear that in order for this algorithm to work, one needs to have a_{n,n}^{(n-1)} \neq 0 at each step (see the definition of . If this assumption fails at some point, one needs to interchange -th row with another row below it before continuing. This is why an LU decomposition in general looks like .
LU Banachiewicz decomposition Although Banachiewicz (1938) LU decomposition algorithm preceded the advent of programmed electronic computers, it was ready made for direct implementation into code as index swapping, transpose and column by column multiplication remain native built capabilities of the most programming languages and they are handled by compilers alone with little delay of the actual execution. The peculiar matrix notation used by Banachiewicz enabled him to multiply matrices column by column, a convenient feature for mechanical calculations as he could reveal consecutive factors by sliding a ruler to next rows of matrices. For human readers however, his equations are best transformed into standard matrix notation. To obtain from a full matrix triangle matrices and calculations, start by copying top row and leftmost column of respectively into corresponding positions of matrices and . The known unit diagonal elements of are not stored nor used throughout the whole process. Next calculations continue for the subsequent rows and columns till the bottom right corner of . The figure illustrates calculations for 3rd row and column, assuming previous stages were already completed. Involved matrices are named above squares marking their content. Matrix products and subtractions are applied only to elements in the thick frame boxes. Green filled thin frame boxes indicate values already known, from previous stages. Blue boxes indicate places in and matrices for storing of results. Note that at each stage the result elements of need to be divided by the corresponding pivot element on the main diagonal of . This applies to the leftmost column of too. Note that after completion of 3rd stage the involved elements of matrix are no longer used and neither those from the previous stages. This enables replacement of these elements with the result values of and , i.e. execution of LU decomposition , so that the whole is replaced with and except for the unit diagonal of . Banachiewicz LU algorithm is well suited for partial pivoting by choosing the absolute maximum pivot from the newly calculated row of and subsequently swapping its columns so that it lands on the main diagonal. More details can be figured out from inspection of the enclosed Fortran90 code. All partial pivoting LU algorithms cost roughly the same amount, of order O\left({2\over3}n^3\right) operations, where is the number of rows or columns of .
LU Crout decomposition Note that the decomposition obtained through this procedure is a ''
: the main diagonal of is composed solely of ones. If one would proceed by removing elements the main diagonal by adding multiples of the (instead of removing elements the diagonal by adding multiples of the ), we would obtain a Crout decomposition'', where the main diagonal of is of ones. Another (equivalent) way of producing a Crout decomposition of a given matrix is to obtain a Doolittle decomposition of the transpose of . Indeed, if is the LU-decomposition obtained through the algorithm presented in this section, then by taking and , we have that is a Crout decomposition.
Randomized algorithm It is possible to find a low rank approximation to an LU decomposition using a
randomized algorithm. Given an input matrix and a desired low rank , the randomized LU returns permutation matrices , and lower/upper trapezoidal matrices , of size and respectively, such that
with high probability , where is a constant that depends on the parameters of the algorithm and is the -th singular value of the input matrix .
Theoretical complexity If two matrices of order can be multiplied in time , where for some , then an LU-decomposition can be computed in time . This means, for example, that an algorithm exists based on the
Coppersmith–Winograd algorithm. See also for
fast matrix multiplication algorithms article for more details.
Sparse-matrix decomposition Special algorithms have been developed for factorizing large
sparse matrices. These algorithms attempt to find sparse factors and . Ideally, the cost of computation is determined by the number of nonzero entries, rather than by the size of the matrix. These algorithms use the freedom to exchange rows and columns to minimize fill-in (entries that change from an initial zero to a nonzero value during the execution of an algorithm). General treatment of orderings that minimize fill-in can be addressed using
graph theory. == Applications ==