Back to References


LU Decomposition for Solving Linear Equations


Learning Objectives

Nothing here yet.

Forward Substitution Algorithm

The forward substitution algorithm solves the linear system \(Lx = b\) where \(L\) is a lower triangular matrix.

A lower-triangular linear system \(Lx = b\) can be written in matrix form: \[ \begin{bmatrix} \ell_{11} & 0 & \ldots & 0 \\ \ell_{21} & \ell_{22} & \ldots & 0 \\ \vdots & \vdots & \ddots & 0 \\ \ell_{n1} & \ell_{n2} & \ldots & \ell_{nn} \\ \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} = \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix}. \] This can also be written as the set of linear equations: \[ \begin{matrix} \ell_{11} x_1 & & & & & & & = & b_1 \\ \ell_{21} x_1 & + & \ell_{22} x_2 & & & & & = & b_2 \\ \vdots & + & \vdots & + & \ddots & & & = & \vdots \\ \ell_{n1} x_1 & + & \ell_{n2} x_2 & + & \ldots & + & \ell_{nn} x_n & = & b_n. \end{matrix} \]

The forward substitution algorithm solves a lower-triangular linear system by working from the top down and solving each variable in turn. In math this is: \[ \begin{aligned} x_1 &= \frac{b_1}{\ell_{11}} \\ x_2 &= \frac{b_2 - \ell_{21} x_1}{\ell_{22}} \\ &\vdots \\ x_n &= \frac{b_n - \sum_{j=1}^{n-1} \ell_{nj} x_j}{\ell_{nn}}. \end{aligned} \]

The properties of the forward substitution algorithm are:

  1. If any of the diagonal elements \(L_{ii}\) are zero then the system is singular and cannot be solved.
  2. If all diagonal elements of \(L\) are non-zero then the system has a unique solution.
  3. The number of operations for the forward substitution algorithm is \(O(n^2)\) as \(n \to \infty\).

The code for the forward substitution algorithm to solve \(L x = b\) is:

import numpy as np
def forward_sub(L, b):
    """x = forward_sub(L, b) is the solution to L x = b
       L must be a lower-triangular matrix
       b must be a vector of the same leading dimension as L
    """
    n = L.shape[0]
    x = np.zeros(n)
    for i in range(n):
        tmp = b[i]
        for j in range(i):
            tmp -= L[i,j] * x[j]
        x[i] = tmp / L[i,i]
    return x

Back Substitution Algorithm

The back substitution algorithm solves the linear system \(Ux = b\) where \(U\) is an upper-triangular matrix. It is the backwards version of forward substitution.

The upper-triangular system \(Ux = b\) can be written as the set of linear equations: \[ \begin{matrix} u_{11} x_1 & + & u_{12} x_2 & + & \ldots & + & u_{1n} & = & b_1 \\ & & u_{22} x_2 & + & \ldots & + & u_{2n} & = & b_2 \\ & & & & \ddots & & \vdots & = & \vdots \\ & & & & & & u_{nn} & = & b_n. \end{matrix} \]

The back substitution solution works from the bottom up to give: \[ \begin{aligned} x_n &= \frac{b_n}{u_{nn}} \\ x_{n-1} &= \frac{b_{n-1} - u_{n-1n} x_n}{u_{n-1n-1}} \\ &\vdots \\ x_1 &= \frac{b_1 - \sum_{j=2}^n u_{1j} x_j}{\ell_{11}}. \end{aligned} \]

The properties of the back substitution algorithm are:

  1. If any of the diagonal elements \(U_{ii}\) are zero then the system is singular and cannot be solved.
  2. If all diagonal elements of \(U\) are non-zero then the system has a unique solution.
  3. The number of operations for the back substitution algorithm is \(O(n^2)\) as \(n \to \infty\).

The code for the back substitution algorithm to solve \(U x = b\) is:

import numpy as np
def back_sub(U, b):
    """x = back_sub(U, b) is the solution to U x = b
       U must be an upper-triangular matrix
       b must be a vector of the same leading dimension as U
    """
    n = U.shape[0]
    x = np.zeros(n)
    for i in range(n-1, -1, -1):
        tmp = b[i]
        for j in range(i+1, n):
            tmp -= U[i,j] * x[j]
        x[i] = tmp / U[i,i]
    return x

LU Decomposition

The LU decomposition of a matrix \(A\) is the pair of matrices \(L\) and \(U\) such that:

  1. \(A = LU\)
  2. \(L\) is a lower-triangular matrix with all diagonal entries equal to 1
  3. \(U\) is an upper-triangular matrix.

The properties of the LU decomposition are:

  1. The LU decomposition may not exist for a matrix \(A\).
  2. If the LU decomposition exists then it is unique.
  3. The LU decomposition provides an efficient means of solving linear equations.
  4. The reason that \(L\) has all diagonal entries set to 1 is that this means the LU decomposition is unique. This choice is somewhat arbitrary (we could have decided that \(U\) must have 1 on the diagonal) but it is the standard choice.
  5. We use the terms decomposition and factorization interchangeably to mean writing a matrix as a product of two or more other matrices, generally with some defined properties (such as lower/upper triangular).

Example: LU Decomposition

Consider the matrix \[ A = \begin{bmatrix} 1 & 2 & 2 \\ 4 & 4 & 2 \\ 4 & 6 & 4 \end{bmatrix} .\]

The LU factorization is \[A = LU = \begin{bmatrix} 1 & 0 & 0 \\ 4 & 1 & 0 \\ 4 & 0.5 & 1 \end{bmatrix} \begin{bmatrix} 1 & 2 & 2 \\ 0 & -4 & -6 \\ 0 & 0 & -1 \end{bmatrix}.\]

Example: Matrix for Which LU Decomposition Fails

An example of a matrix which has no LU decomposition is \[ A = \begin{bmatrix} 0 & 1 \\ 2 & 1 \end{bmatrix}. \]

If we try and find the LU decomposition of this matrix then we get \[ \overbrace{\begin{bmatrix} 0 & 1 \\ 2 & 1 \end{bmatrix}}^{A} = \overbrace{\begin{bmatrix} 1 & 0 \\ \ell_{21} & 1 \end{bmatrix}}^{L} \overbrace{\begin{bmatrix} u_{11} & u_{12} \\ 0 & u_{22} \end{bmatrix}}^{U} = \begin{bmatrix} u_{11} & u_{12} \\ \ell_{21} u_{11} & \ell_{21} u_{12} + u_{22} \end{bmatrix}. \] Equating the individual entries gives us four equations to solve. The top-left and bottom-left entries give the two equations: \[ \begin{aligned} u_{11} &= 0 \\ \ell_{21} u_{11} &= 2. \end{aligned} \] These equations have no solution, so \(A\) does not have an LU decomposition.

Solving LU Decomposition Linear Systems

Knowing the LU decomposition for a matrix \(A\) allows us to solve the linear system \(A x = b\) using a combination of forward and back substitution. In equations this is: \[ \begin{aligned} A x &= b \\ L U x &= b \\ U x &= L^{-1} b \\ x &= U^{-1} (L^{-1} b), \end{aligned} \] where we first evaluate \(L^{-1} b\) using forward substitution and then evaluate \(x = U^{-1} (L^{-1} b)\) using back substitution.

An equivalent way to write this is to introduce a new vector \(y\) defined by \(y = U x\). This means we can rewrite \(A x = b\) as: \[ \begin{aligned} A x &= b \\ L U x &= b \\ L y &= b \text{ and } U x = y. \end{aligned} \] We have thus replaced \(Ax = b\) with two linear systems: \(L y = b\) and \(U x = y\). These two linear systems can then be solved one after the other using forward and back substitution.

The LU solve algorithm for solving the linear system \(L U x = b\) written as code is:

import numpy as np
def lu_solve(L, U, b):
    """x = lu_solve(L, U, b) is the solution to L U x = b
       L must be a lower-triangular matrix
       U must be an upper-triangular matrix of the same size as L
       b must be a vector of the same leading dimension as L
    """
    y = forward_sub(L, b)
    x = back_sub(U, y)
    return x

The number of operations for the LU solve algorithm is \(O(n^2)\) as \(n \to \infty\).

The LU Decomposition Algorithm

Given a matrix \(A\) there are many different algorithms to find the matrices \(L\) and \(U\) for the LU decomposition. Here we will use the recursive leading-row-column LU algorithm.

This algorithm is based on writing \(A = LU\) in block form as: \[ \begin{aligned} A &= LU \\ \begin{bmatrix} a_{11} & \boldsymbol{a}_{12} \\ \boldsymbol{a}_{21} & A_{22} \end{bmatrix} &= \begin{bmatrix} 1 & \boldsymbol{0} \\ \boldsymbol{\ell}_{21} & L_{22} \end{bmatrix} \begin{bmatrix} u_{11} & \boldsymbol{u}_{12} \\ \boldsymbol{0} & U_{22} \end{bmatrix} \\ &= \begin{bmatrix} u_{11} & \boldsymbol{u}_{12} \\ u_{11} \boldsymbol{\ell}_{21} & (\boldsymbol{\ell}_{21} \boldsymbol{u}_{12} + L_{22} U_{22}) \end{bmatrix}. \end{aligned} \] In the above block form of the \(n \times n\) matrix \(A\), the entry \(a_{11}\) is a scalar, \(\boldsymbol{a}_{12}\) is a \(1 \times (n-1)\) row vector, \(\boldsymbol{a}_{12}\) is an \((n-1) \times 1\) column vector, and \(A_{22}\) is an \((n-1) \times (n-1)\) matrix.

Comparing the left- and right-hand side entries of the above block matrix equation we see that: \[ \begin{aligned} a_{11} &= u_{11} \\ \boldsymbol{a}_{12} &= \boldsymbol{u}_{12} \\ \boldsymbol{a}_{21} &= u_{11} \boldsymbol{\ell}_{21} \\ A_{22} &= \boldsymbol{\ell}_{21} \boldsymbol{u}_{12} + L_{22} U_{22}. \end{aligned} \] These four equations can be rearranged to solve for the components of the \(L\) and \(U\) matrices as: \[ \begin{aligned} u_{11} &= a_{11}\\ \boldsymbol{u}_{12} &= \boldsymbol{a}_{12} \\ \boldsymbol{\ell}_{21} &= \frac{1}{u_{11}} \boldsymbol{a}_{21} \\ L_{22} U_{22} &= \underbrace{A_{22} - \boldsymbol{a}_{21} (a_{11})^{-1} \boldsymbol{a}_{12}}_{\text{Schur complement } S_{22}}. \end{aligned} \] The first three equations above can be immediately evaluated to give the first row and column of \(L\) and \(U\). The last equation can then have its right-hand-side evaluated, which gives the Schur complement \(S_{22}\) of \(A\). We thus have the equation \(L_{22} U_{22} = S_{22}\), which is an \((n-1) \times (n-1)\) LU decomposition problem which we can recursively solve.

The code for the recursive leading-row-column LU algorithm to find \(L\) and \(U\) for \(A = LU\) is:

import numpy as np
def lu_decomp(A):
    """(L, U) = lu_decomp(A) is the LU decomposition A = L U
       A is any matrix
       L will be a lower-triangular matrix with 1 on the diagonal, the same shape as A
       U will be an upper-triangular matrix, the same shape as A
    """
    n = A.shape[0]
    if n == 1:
        L = np.array([[1]])
        U = A.copy()
        return (L, U)

    A11 = A[0,0]
    A12 = A[0,1:]
    A21 = A[1:,0]
    A22 = A[1:,1:]

    L11 = 1
    U11 = A11

    L12 = np.zeros(n-1)
    U12 = A12.copy()

    L21 = A21.copy() / U11
    U21 = np.zeros(n-1)

    S22 = A22 - np.outer(L21, U12)
    (L22, U22) = lu_decomp(S22)

    L = np.block([[L11, L12], [L21, L22]])
    U = np.block([[U11, U12], [U21, U22]])
    return (L, U)

The number of operations for the recursive leading-row-column LU decomposition algorithm is \(O(n^3)\) as \(n \to \infty\).

Solving Linear Systems Using LU Decomposition

We can put the above sections together to produce an algorithm for solving the system \(A x = b\), where we first compute the LU decomposition of A and then use forward and backward substitution to solve for \(x\).

The properties of this algorithm are:

  1. The algorithm may fail, even if \(A\) is invertible.
  2. The number of operations in the algorithm is \(O(n^3)\) as \(n \to \infty\).

The code for the linear solver using LU decomposition is: import numpy as np

import numpy as np
def linear_solve_without_pivoting(A, b):
    """x = linear_solve_without_pivoting(A, b) is the solution to A x = b (computed without pivoting)
       A is any matrix
       b is a vector of the same leading dimension as A
       x will be a vector of the same leading dimension as A
    """
    (L, U) = lu_decomp(A)
    x = lu_solve(L, U, b)
    return x

Pivoting

The LU decomposition can fail when the top-left entry in the matrix \(A\) is zero or very small compared to other entries. Pivoting is a strategy to mitigate this problem by rearranging the rows and/or columns of \(A\) to put a larger element in the top-left position.

There are many different pivoting algorithms. The most common of these are full pivoting, partial pivoting, and scaled partial pivoting. We will only discuss partial pivoting in detail.

  1. Partial pivoting only rearranges the rows of \(A\) and leaves the columns fixed. Partial pivoting schematic

  2. Full pivoting rearranges both rows and columns. Full pivoting schematic

  3. Scaled partial pivoting approximates full pivoting without actually rearranging columns.

LU Decomposition with Partial Pivoting

The LU decomposition with partial pivoting (LUP) of an \(n \times n\) matrix \(A\) is the triple of matrices \(L\), \(U\), and \(P\) such that:

  1. \(PA = LU\)
  2. \(L\) is an \(n \times n\) lower-triangular matrix with all diagonal entries equal to 1
  3. \(U\) is an \(n \times n\) upper-triangular matrix
  4. \(P\) is an \(n \times n\) permutation matrix.

The properties of the LUP decomposition are:

  1. The permutation matrix \(P\) acts to permute the rows of \(A\). This attempts to put large entries in the top-left position of \(A\) and each sub-matrix in the recursion, to avoid needing to divide by a small or zero element.
  2. The LUP decomposition always exists for a matrix \(A\).
  3. The LUP decomposition of a matrix \(A\) is not unique.
  4. The LUP decomposition provides a more robust method of solving linear systems than LU decomposition without pivoting, and it is approximately the same cost.

Solving LUP Decomposition Linear Systems

Knowing the LUP decomposition for a matrix \(A\) allows us to solve the linear system \(A x = b\) by first applying \(P\) and then using the LU solver. In equations we start by taking \(A x = b\) and multiplying both sides by \(P\), giving \[ \begin{aligned} Ax &= b \\ PAx &= Pb \\ LUx &= Pb. \end{aligned} \]

The code for the LUP solve algorithm to solve the linear system \(L U x = P b\) is:

import numpy as np
def lup_solve(L, U, P, b):
    """x = lup_solve(L, U, P, b) is the solution to L U x = P b
       L must be a lower-triangular matrix
       U must be an upper-triangular matrix of the same shape as L
       P must be a permutation matrix of the same shape as L
       b must be a vector of the same leading dimension as L
    """
    z = np.dot(P, b)
    x = lu_solve(L, U, z)
    return x

The number of operations for the LUP solve algorithm is \(O(n^2)\) as \(n \to \infty\).

The LUP Decomposition Algorithm

Just as there are different LU decomposition algorithms, there are also different algorithms to find a LUP decomposition. Here we use the recursive leading-row-column LUP algorithm.

This algorithm is a recursive method for finding \(L\), \(U\), and \(P\) so that \(P A = L U\). It consists of the following steps.

  1. First choose \(i\) so that row \(i\) in \(A\) has the largest absolute first entry. That is, \(|A_{i1}| \ge |A_{j1}|\) for all \(j\). Let \(P_1\) be the permutation matrix that pivots (shifts) row \(i\) to the first row, and leaves all other rows in order. We can explicitly write \(P_1\) as \[ P_1 = \begin{bmatrix} 0_{1(i-1)} & 1 & 0_{1(n-i)} \\ I_{(i-1)(i-1)} & 0 & 0_{(i-1)(n-i)} \\ 0_{(n-i)(i-1)} & 0 & I_{(n-i)(n-i)} \end{bmatrix} = \begin{bmatrix} 0 & \ldots & 0 & 1 & 0 & \ldots & 0 \\ 1 & \ldots & 0 & 0 & 0 & \ldots & 0 \\ \vdots & \ddots & \vdots & \vdots & \vdots & \ldots & 0 \\ 0 & \ldots & 1 & 0 & 0 & \ldots & 0 \\ 0 & \ldots & 0 & 0 & 1 & \ldots & 0 \\ \vdots & \ddots & \vdots & \vdots & \vdots & \ldots & 0 \\ 0 & \ldots & 0 & 0 & 0 & \ldots & 1 \end{bmatrix}. \]

  2. Write \(\bar{A}\) to denote the pivoted \(A\) matrix, so \(\bar{A} = P_1 A\).

  3. Let \(P_2\) be a permutation matrix that leaves the first row where it is, but permutes all other rows. We can write \(P_2\) as \[ P_2 = \begin{bmatrix} 1 & \boldsymbol{0} \\ \boldsymbol{0} & P_{22} \end{bmatrix}, \] where \(P_{22}\) is an \((n-1) \times (n-1)\) permutation matrix.

  4. Factorize the (unknown) full permutation matrix \(P\) as the product of \(P_2\) and \(P_1\), so \(P = P_2 P_1\). This means that \(P A = P_2 P_1 A = P_2 \bar{A}\), which first shifts row \(i\) of \(A\) to the top, and then permutes the remaining rows. This is a completely general permuation matrix \(P\), but this factorization is key to enabling a recursive algorithm.

  5. Using the factorization \(P = P_2 P_1\), now write the LUP factorization in block form as \[ \begin{aligned} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% P A &= L U \\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% P_2 \bar{A} &= L U \\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{bmatrix} 1 & \boldsymbol{0} \\ \boldsymbol{0} & P_{22} \end{bmatrix} \begin{bmatrix} \bar{a}_{11} & \bar{\boldsymbol{a}}_{12} \\ \bar{\boldsymbol{a}}_{21} & \bar{A}_{22} \end{bmatrix} &= \begin{bmatrix} 1 & \boldsymbol{0} \\ \boldsymbol{\ell}_{21} & L_{22} \end{bmatrix} \begin{bmatrix} u_{11} & \boldsymbol{u}_{12} \\ \boldsymbol{0} & U_{22} \end{bmatrix} \\ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{bmatrix} \bar{a}_{11} & \bar{\boldsymbol{a}}_{12} \\ P_{22} \bar{\boldsymbol{a}}_{21} & P_{22} \bar{A}_{22} \end{bmatrix} &= \begin{bmatrix} u_{11} & \boldsymbol{u}_{12} \\ u_{11} \boldsymbol{\ell}_{21} & (\boldsymbol{\ell}_{21} \boldsymbol{u}_{12} + L_{22} U_{22}) \end{bmatrix} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{aligned} \]

  6. Equating the entries in the above matrices gives the equations \[ \begin{aligned} \bar{a}_{11} &= u_{11} \\ \bar{\boldsymbol{a}}_{12} &= \boldsymbol{u}_{12} \\ P_{22} \bar{\boldsymbol{a}}_{21} &= u_{11} \boldsymbol{\ell}_{21} \\ P_{22} \bar{A}_{22} &= \boldsymbol{\ell}_{21} \boldsymbol{u}_{12} + L_{22} U_{22}. \end{aligned} \]

  7. Substituting the first three equations above into the last one and rearranging gives \[ P_{22} \underbrace{\Bigl(\bar{A}_{22} - \bar{\boldsymbol{a}}_{21} (\bar{a}_{11})^{-1} \bar{\boldsymbol{a}}_{12}\Bigr)}_{\text{Schur complement } S_{22}} = L_{22} U_{22}. \]

  8. Recurse to find the LUP decomposition of \(S_{22}\), resulting in \(L_{22}\), \(U_{22}\), and \(P_{22}\) that satisfy the above equation.

  9. Solve for the first rows and columns of \(L\) and \(U\) with the above equations to give \[ \begin{aligned} u_{11} &= \bar{a}_{11} \\ \boldsymbol{u}_{12} &= \bar{\boldsymbol{a}}_{12} \\ \boldsymbol{\ell}_{21} &= \frac{1}{\bar{a}_{11}} P_{22} \bar{\boldsymbol{a}}_{21}. \end{aligned} \]

  10. Finally, reconstruct the full matrices \(L\), \(U\), and \(P\) from the component parts.

In code the recursive leading-row-column LUP algorithm for finding the LU decomposition of \(A\) with partial pivoting is:

import numpy as np
def lup_decomp(A):
    """(L, U, P) = lup_decomp(A) is the LUP decomposition P A = L U
       A is any matrix
       L will be a lower-triangular matrix with 1 on the diagonal, the same shape as A
       U will be an upper-triangular matrix, the same shape as A
       U will be a permutation matrix, the same shape as A
    """
    n = A.shape[0]
    if n == 1:
        L = np.array([[1]])
        U = A.copy()
        P = np.array([[1]])
        return (L, U, P)

    i = np.argmax(A[:,0])
    A_bar = np.vstack([A[i,:], A[:i,:], A[(i+1):,:]])

    A_bar11 = A_bar[0,0]
    A_bar12 = A_bar[0,1:]
    A_bar21 = A_bar[1:,0]
    A_bar22 = A_bar[1:,1:]

    S22 = A_bar22 - np.dot(A_bar21, A_bar12) / A_bar11

    (L22, U22, P22) = lup_decomp(S22)

    L11 = 1
    U11 = A_bar11

    L12 = np.zeros(n-1)
    U12 = A_bar12.copy()

    L21 = np.dot(P22, A_bar21) / A_bar11
    U21 = np.zeros(n-1)

    L = np.block([[L11, L12], [L21, L22]])
    U = np.block([[U11, U12], [U21, U22]])
    P = np.block([
        [np.zeros((1, i-1)), 1,                  np.zeros((1, n-i))],
        [P22[:,:(i-1)],      np.zeros((n-1, 1)), P22[:,i:]]
    ])
    return (L, U, P)

The properties of the recursive leading-row-column LUP decomposition algorithm are:

  1. The computational complexity (number of operations) of the algorithm is \(O(n^3)\) as \(n \to \infty\).

  2. The last step in the code that computes \(P\) does not do so by constructing and multiplying \(P_2\) and \(P_1\). This is because this would be an \(O(n^3)\) step, making the whole algorithm \(O(n^4)\). Instead we take advantage of the special structure of \(P_2\) and \(P_1\) to compute \(P\) with \(O(n^2)\) work.

Solving Linear Systems Using LUP Decomposition

Just as with the plain LU decomposition, we can use LUP decomposition to solve the linear system \(A x = b\). This is the linear solver using LUP decomposition algorithm.

The properties of this algorithm are:

  1. The algorithm may fail, even if \(A\) is invertible. (IS THIS TRUE?)
  2. The number of operations in the algorithm is \(O(n^3)\) as \(n \to \infty\).

The code for the linear solver using LUP decomposition is:

import numpy as np
def linear_solve(A, b):
    """x = linear_solve(A, b) is the solution to A x = b (computed with partial pivoting)
       A is any matrix
       b is a vector of the same leading dimension as A
       x will be a vector of the same leading dimension as A
    """
    (L, U, P) = lup_decomp(A)
    x = lup_solve(L, U, P, b)
    return x

Example: Matrix for Which LUP Decomposition Succeeds But LU Decomposition Fails

Recall our example of a matrix which has no LU decomposition: \[ A = \begin{bmatrix} 0 & 1 \\ 2 & 1 \end{bmatrix}. \]

To find the LUP decomposition of \(A\), we first write the permutation matrix \(P\) that shifts the second row to the top, so that the top-left entry has the largest possible magnitude. This gives \[ \overbrace{\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}}^{P} \overbrace{\begin{bmatrix} 0 & 1 \\ 2 & 1 \end{bmatrix}}^{A} = \overbrace{\begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix}}^{\bar{A}} = \overbrace{\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}}^{L} \overbrace{\begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix}}^{U}. \]