6.1. LU decomposition#
LU decomposition (also known as LU factorisation) is a procedure for decomposing a square matrix \(A\) into the product of a lower triangular matrix \(L\) and an upper triangular matrix \(U\) such that
The advantage of writing a matrix as a product of \(L\) and \(U\) is that the solution to a triangular set of equations is easy to calculate using forward or back substitution. Consider the LU decomposition of a \(3\times 3\) matrix
which gives a system of 9 equations (one for each element in \(A\)) in 12 unknowns. Since there are more unknowns than equations, the factorisation is not unique. A standard convention is to set the diagonal entries of \(L\) equal to 1 (\(\ell_{ii}=1\)), which produces a unique decomposition whenever it exists.
In general,
The triangular structure of \(L\) and \(U\) limits which terms are non-zero, leading to separate formulas for \(i > j\) and \(i < j\).
The elements in the lower triangular region, where \(i>j\), are
which is rearranged to
For the elements in the upper triangular region where \(i\le j\) we have
which is rearranged to
So to calculate an LU decomposition we loop through each column of \(A\) and calculate the elements of \(\ell_{ij}\) and \(u_{ij}\) for that column.
Theorem 6.1 (LU decomposition)
The LU decomposition of an \(n \times n\) square matrix \(A\) results in two \(n \times n\) matrices \(L\) and \(U\) such that \(A = LU\). The elements of \(L\) and \(U\) are calculated using
The quantity \(u_{jj}\) is called the pivot. The algorithm fails if a pivot is zero.
Note
Not every square matrix admits an LU decomposition without row exchanges. The formulas below require the pivots \(u_{jj}\) to be non-zero. If a zero pivot is encountered, row interchanges are required, leading to the more general \(PA=LU\) factorisation discussed later.
Algorithm 6.1 (LU decomposition)
Inputs: A square \(n \times n\) matrix \(A\).
Outputs: Two square \(n \times n\) matrices \(L\) and \(U\) such that \(A = LU\).
\(L \gets I_n\)
\(U \gets \mathbf{0}_{n \times n}\)
for \(j = 1, \ldots, n\)
\(u_{ij} \gets a_{ij} - \displaystyle\sum_{k=1}^{i-1} \ell_{ik}u_{kj}, \qquad i = 1, \ldots, j\)
\(\ell_{ij} \gets \dfrac{1}{u_{jj}} \left( a_{ij} - \displaystyle \sum_{k=1}^{j-1} \ell_{ik}u_{kj} \right), \qquad i = j + 1, \ldots, n\)
Return \(L\) and \(U\)
The computational cost of LU decomposition is \(O(n^3)\), comparable to Gaussian elimination. Once the factorisation has been computed, multiple systems \(A \mathbf{x} = \mathbf{b}\) can be solved efficiently using back substitution.
Example 6.1
Determine the LU decomposition of the following matrix
Solution
Loop through the columns of \(A\) and compute the elements of \(L\) and \(U\)
therefore
Checking that \(LU=A\)
6.1.1. Solving systems of linear equations using LU decomposition#
Given a system of linear equations of the form \(A \mathbf{x} = \mathbf{b}\) where LU decomposition has been applied to the coefficient matrix then since \(A = LU\) we have
Introduce an intermediate vector \(\mathbf{y}\) defined by
Since \(L\) is lower triangular, the solution of \(L \mathbf{y} = \mathbf{b}\) is easily computed using forward substitution. Once \(\mathbf{y}\) has been determined, the solution \(\mathbf{x}\) is obtained from
using back substitution.
Algorithm 6.2 (Solving systems of linear equations using LU decomposition)
Inputs: A system of linear equations expressed using the coefficient matrix \(A\) and variable vector \(\mathbf{b}\) such that \(A \mathbf{x} = \mathbf{b}\).
Outputs: The solution vector \(\mathbf{x}\).
Compute the LU decomposition of \(A\)
Solve \(L \mathbf{y} = \mathbf{b}\) using forward substitution
\(y_1 = b_1\)
\(y_i \gets b_i - \displaystyle\sum_{j=1}^{i-1} \ell_{ij} y_j\), \(\qquad i = 2, \ldots, n\)
Solve \(U \mathbf{x} = \mathbf{y}\) using back substitution
\(x_n \gets \dfrac{y_n}{u_{nn}}\)
\(x_i \gets \dfrac{1}{u_{ii}} \left( y_i - \displaystyle \sum_{j=i+1}^{n} u_{ij} x_j \right)\), \(\qquad i = n-1, \ldots, 1\)
Return \(\mathbf{x}\).
The main advantage of LU decomposition arises when solving several systems
with the same coefficient matrix \(A\). The decomposition \(A = LU\) is only computed once, after which each new right-hand side requires only one forware-substitution step and one back-substitution step.
This is why LU decomposition is commonly used in implicit Runge-Kutta methods. During the Newton iterations, the coefficient matrix \(I−h(A \otimes J_f)\) remains unchanged while the right-hand side vector \(g(\mathbf{Y})\) varies. Consequently, the LU decomposition is computed once and reused for each linear solve, leading to a substantial reduction in computational effort.
Example 6.2
Solve the following system using LU decomposition
Solution
We saw in the Example 6.1 above that the LU decomposition of the coefficient matrix is
Solving \(L \mathbf{y} = \mathbf{b}\) using forward substitution
gives
Solving \(U \mathbf{x} = \mathbf{y}\) using back substitution
gives
So the solution is \(\mathbf{x}=(1, -2, 3)\).
To verify the solution we check that \(A \mathbf{x} = b\)