Chapter 6 — Direct Methods for Solving Linear Systems

Math 128A, Fall 2026 · Per-Olof Persson

A linear system is the one problem in this course that can be solved exactly in finitely many steps — no iteration, no truncation error, just arithmetic. That is what direct means. What remains is everything else: how many operations it costs, and how round-off behaves along the way. Both turn out to matter, and the second one is why §6.2 exists.

6.1 Linear Systems of Equations

Direct Methods for Linear Systems

Consider solving a linear system of the form: \[ \begin{aligned} E_1: a_{11}x_1 + a_{12}x_2+\cdots+a_{1n}x_n &= b_1, \\ E_2: a_{21}x_1 + a_{22}x_2+\cdots+a_{2n}x_n &= b_2, \\ & \ \,\vdots \\ E_n: a_{n1}x_1 + a_{n2}x_2+\cdots+a_{nn}x_n &= b_n, \end{aligned} \] for \(x_1,\ldots,x_n\). Direct methods give an answer in a fixed number of steps, subject only to round-off errors.

We use three row operations to simplify the linear system:

  1. Multiply Eq. \(E_i\) by \(\lambda\ne 0\): \((\lambda E_i)\rightarrow (E_i)\)
  2. Multiply Eq. \(E_j\) by \(\lambda\) and add to Eq. \(E_i\): \((E_i + \lambda E_j) \rightarrow (E_i)\)
  3. Exchange Eq. \(E_i\) and Eq. \(E_j\): \((E_i) \leftrightarrow (E_j)\)

Write the system as \(A\mathbf{x} = \mathbf{b}\), where \[ A = [a_{ij}] = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \cdots & a_{nn} \end{bmatrix}, \qquad \mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}, \qquad \mathbf{b} = \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix}. \]

Gaussian elimination

Gaussian Elimination
Gaussian Elimination with Backward Substitution
Row Exchanges
Definition 6.1

An \(n\times m\) matrix is a rectangular array of elements with \(n\) rows and \(m\) columns in which both value and position of an element is important


Everything is done on the augmented matrix \([A, \mathbf{b}]\), since the row operations act on \(A\) and \(\mathbf{b}\) together. The goal is to clear everything strictly below the diagonal.

The augmented matrix. Elimination clears the shaded block below the diagonal, using row operations that leave the solution unchanged.
Figure 6.1: The augmented matrix. Elimination clears the shaded block below the diagonal, using row operations that leave the solution unchanged.

It is done one column at a time. At step \(k\) the pivot row \(k\) is used to clear column \(k\) beneath it, and the zeros from earlier steps are left undisturbed.

Gaussian elimination on a 4\times 4 system. The circled row is the pivot row at that stage; after n-1 stages the matrix is upper triangular.
Figure 6.2: Gaussian elimination on a \(4\times 4\) system. The circled row is the pivot row at that stage; after \(n-1\) stages the matrix is upper triangular.

In pseudocode, with \(m\) the multiplier: \[ \begin{aligned} &\textbf{for } i = 1 : n-1 \\ &\quad \textbf{for } j = i+1 : n \\ &\quad\quad m \leftarrow a_{ji}\,/\,a_{ii} &&\text{1 division} \\ &\quad\quad \textbf{for } k = i : n \\ &\quad\quad\quad a_{jk} \leftarrow a_{jk} - m\cdot a_{ik} &&\text{1 multiply, 1 subtract} \\ &\quad\quad \textbf{end} \\ &\quad\quad b_j \leftarrow b_j - m\cdot b_i \\ &\quad \textbf{end} \\ &\textbf{end} \end{aligned} \]

Back-substitution

Elimination leaves an upper triangular system, \[ \left[\begin{array}{ccccc|c} \times & \times & \cdots & & \times & \times \\ 0 & \times & \cdots & & \times & \times \\ 0 & 0 & \times & \cdots & \times & \times \\ \vdots & \vdots & & \ddots & \vdots & \vdots \\ 0 & 0 & \cdots & 0 & \times & \times \end{array}\right], \] which is solved from the bottom up: the last equation gives \(x_n\) directly, and each earlier one then has only a single unknown left. \[ \begin{aligned} &\mathbf{x} \leftarrow \mathbf{b} \\ &\textbf{for } i = n : -1 : 1 \\ &\quad \textbf{for } j = i+1 : n \\ &\quad\quad x_i \leftarrow x_i - a_{ij}\cdot x_j \\ &\quad \textbf{end} \\ &\quad x_i \leftarrow x_i / a_{ii} \\ &\textbf{end} \end{aligned} \]

Operation counts

Operation Counts
Reduction to Triangular Form

Multiplications/divisions: \[ \begin{aligned} \sum_{i=1}^{n-1} (n-i)(n-i+2) = \cdots = \frac{2n^3 + 3n^2 -5n}{6} \end{aligned} \] Additions/subtractions: \[ \begin{aligned} \sum_{i=1}^{n-1} (n-i)(n-i+1) = \cdots = \frac{n^3 - n}{3} \end{aligned} \]


How expensive is this? Count the arithmetic in the elimination phase, ignoring the \(\mathbf{b}\) vector. Three summation identities do all the work: \[ \sum_{i=1}^{n} 1 = n, \qquad \sum_{i=1}^{n} i = \frac{n(n+1)}{2}, \qquad \sum_{i=1}^{n} i^2 = \frac{n(n+1)(2n+1)}{6}. \]

Divisions. The inner loop performs one division for each \(j\) from \(i+1\) to \(n\), that is \(n-i\) of them, so \[ \sum_{i=1}^{n-1}(n-i) = \sum_{i=1}^{n-1}n - \sum_{i=1}^{n-1}i = n(n-1) - \frac{(n-1)n}{2} = \frac{n(n-1)}{2}. \]

Multiplications. For each of those \(n-i\) values of \(j\) the innermost loop runs over \(k = i : n\), which is \(n-i+1\) values, so \[ \begin{aligned} \sum_{i=1}^{n-1}(n-i)(n-i+1) &= \sum_{i=1}^{n-1}\left(n^2 - 2ni + n + i^2 - i\right) \\ &= \sum_{i=1}^{n-1}\left[(n^2+n) - (2n+1)i + i^2\right] \\ &= (n^2+n)(n-1) - (2n+1)\frac{(n-1)n}{2} + \frac{(n-1)n(2n-1)}{6} \\ &= \cdots = \frac{n(n^2-1)}{3}. \end{aligned} \]

So elimination costs \(O(n^3)\) operations while back-substitution costs only \(O(n^2)\) — the factorization dominates, which is the observation §6.5 exploits.

Operation Counts
Backward Substitution

Multiplications/divisions: \[ \begin{aligned} 1+\sum_{i=1}^{n-1} ((n-i)+1) = \frac{n^2+n}{2} \end{aligned} \] Additions/subtractions: \[ \begin{aligned} \sum_{i=1}^{n-1} ((n-i-1)+1) = \frac{n^2-n}{2} \end{aligned} \]


Operation Counts
Gaussian Elimination Total Operation Count

Multiplications/divisions: \[ \begin{aligned} \frac{n^3}{3}+n^2-\frac{n}{3} \end{aligned} \] Additions/subtractions: \[ \begin{aligned} \frac{n^3}{3}+\frac{n^2}{2}-\frac{5n}{6} \end{aligned} \]


6.2 Pivoting Strategies

Elimination as written divides by \(a_{ii}\), so it fails outright if a pivot is zero. The repair is obvious — exchange rows — but the interesting case is when the pivot is merely small.

Example 6.1

A zero pivot.

\[ \left[\begin{array}{cc|c} 0 & 1 & 1 \\ 1 & 1 & 2 \end{array}\right] \xrightarrow{\ \text{exchange rows}\ } \left[\begin{array}{cc|c} 1 & 1 & 2 \\ 0 & 1 & 1 \end{array}\right], \] and back-substitution gives \(x_2 = 1\), then \(x_1 = 2 - 1 = 1\), so \[ \mathbf{x} = \begin{bmatrix} 1 \\ 1 \end{bmatrix}. \]

Example 6.2

A small pivot is just as bad.

Perturb the zero to something tiny but nonzero: \[ \left[\begin{array}{cc|c} 10^{-20} & 1 & 1 \\ 1 & 1 & 2 \end{array}\right] \xrightarrow{\ \ } \left[\begin{array}{cc|c} 10^{-20} & 1 & 1 \\ 0 & 1 - 10^{20} & 2 - 10^{20} \end{array}\right]. \]

Elimination is legal now — the pivot is nonzero — but in floating point both \(1 - 10^{20}\) and \(2 - 10^{20}\) round to \(-10^{20}\), because the leading digits swamp the trailing ones. This is exactly the cancellation of §1.2. So back-substitution gives \[ x_2 = \frac{-10^{20}}{-10^{20}} = 1, \qquad x_1 = \frac{1 - x_2}{10^{-20}} = \frac{0}{10^{-20}} = 0, \] that is \(\mathbf{x} \approx \begin{bmatrix} 0 \\ 1\end{bmatrix}\) — the first component is completely wrong.

The moral: pivot even when \(a_{ii} \ne 0\).

Partial Pivoting

Partial pivoting exchanges rows so that the largest available entry in the column becomes the pivot.

Example 6.3

The same system, with partial pivoting.

\[ \left[\begin{array}{cc|c} 1 & 1 & 2 \\ 10^{-20} & 1 & 1 \end{array}\right] \xrightarrow{\ \ } \left[\begin{array}{cc|c} 1 & 1 & 2 \\ 0 & 1 - 10^{-20} & 1 - 2\cdot 10^{-20} \end{array}\right]. \]

Now the perturbations are small relative to the entries they sit in, so \(1 - 10^{-20} \approx 1\) and \(1 - 2\cdot 10^{-20} \approx 1\). Back-substitution gives \(x_2 = 1\) and \(x_1 = 2 - 1 = 1\): \[ \mathbf{x} \approx \begin{bmatrix} 1 \\ 1 \end{bmatrix}, \] which is exact. The same arithmetic, in a different order.

Scaled Partial Pivoting

6.3 Linear Algebra and Matrix Inversion

Linear Algebra
Definition 6.2

Two matrices \(A\) and \(B\) are equal if they have the same number of rows and columns \(n\times m\) and if \(a_{ij}=b_{ij}\).

Definition 6.3

If \(A\) and \(B\) are \(n\times m\) matrices, the sum \(A+B\) is the \(n\times m\) matrix with entries \(a_{ij}+b_{ij}\).

Definition 6.4

If \(A\) is \(n\times m\) and \(\lambda\) a real number, the scalar multiplication \(\lambda A\) is the \(n \times m\) matrix with entries \(\lambda a_{ij}\).


The two shapes that elimination produces are worth naming. An upper triangular matrix has zeros below the diagonal and a lower triangular matrix has zeros above it: \[ U = \begin{bmatrix} \times & \cdots & & \times \\ 0 & \times & & \vdots \\ \vdots & & \ddots & \vdots \\ 0 & \cdots & 0 & \times \end{bmatrix}, \qquad L = \begin{bmatrix} \times & 0 & \cdots & 0 \\ \times & \times & & \vdots \\ \vdots & & \ddots & 0 \\ \times & \cdots & & \times \end{bmatrix}. \]

Properties
Theorem 6.1

Let \(A,B,C\) be \(n\times m\) matrices, \(\lambda,\mu\) real numbers.

  1. \(A+B=B+A\)
  2. \((A+B)+C=A+(B+C)\)
  3. \(A+0=0+A=A\)
  4. \(A+(-A)=-A+A=0\)
  5. \(\lambda(A+B)=\lambda A + \lambda B\)
  6. \((\lambda+\mu)A=\lambda A + \mu A\)
  7. \(\lambda(\mu A) = (\lambda \mu) A\)
  8. \(1 A = A\)

Matrix Multiplication
Definition 6.5

Let \(A\) be \(n\times m\) and \(B\) be \(m\times p\). The matrix product \(C=AB\) is the \(n\times p\) matrix with entries \[ \begin{aligned} c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} = a_{i1}b_{1j} + a_{i2}b_{2j}+\cdots + a_{im}b_{mj} \end{aligned} \]


Proof of associativity, \(A(BC) = (AB)C\).

First check that both sides even make sense. If \(A\) is \(n\times m\), \(B\) is \(m\times k\) and \(C\) is \(k\times p\), then

The shapes line up either way: contracting m first or k first, the result is n\times p.
Figure 6.3: The shapes line up either way: contracting \(m\) first or \(k\) first, the result is \(n\times p\).

\[ \underbrace{A}_{n\times m}\underbrace{(BC)}_{m\times p} = n\times p, \qquad \underbrace{(AB)}_{n\times k}\underbrace{C}_{k\times p} = n\times p, \] so both products are \(n\times p\) and can be compared entrywise.

Expanding the left side, \[ \text{LHS}_{ij} = \bigl[A(BC)\bigr]_{ij} = \sum_{s=1}^{m} A_{is}(BC)_{sj} = \sum_{s=1}^{m} A_{is}\sum_{\ell=1}^{k}B_{s\ell}C_{\ell j} = \sum_{s=1}^{m}\sum_{\ell=1}^{k} A_{is}B_{s\ell}C_{\ell j}, \] and the right side, \[ \text{RHS}_{ij} = \bigl[(AB)C\bigr]_{ij} = \sum_{\ell=1}^{k}(AB)_{i\ell}C_{\ell j} = \sum_{\ell=1}^{k}\left(\sum_{s=1}^{m}A_{is}B_{s\ell}\right)C_{\ell j} = \sum_{\ell=1}^{k}\sum_{s=1}^{m} A_{is}B_{s\ell}C_{\ell j}. \]

The two double sums have the same terms; only the order of summation differs, and a finite sum does not care. Hence \(\bigl[(AB)C\bigr]_{ij} = \bigl[A(BC)\bigr]_{ij}\) for every \(i, j\). ■

Special Matrices
Definition 6.6
Definition 6.7

Properties
Theorem 6.2

Let \(A\) be \(n\times m\), \(B\) be \(m\times k\), \(C\) be \(k\times p\), \(D\) be \(m\times k\), and \(\lambda\) a real number.

  1. \(A(BC)=(AB)C\)
  2. \(A(B+D)=AB+AD\)
  3. \(I_mB=B\) and \(BI_k=B\)
  4. \(\lambda(AB)=(\lambda A)B = A(\lambda B)\)

The inverse

Matrix Inversion
Definition 6.8
Theorem 6.3

For any nonsingular \(n\times n\) matrix \(A\),

  1. \(A^{-1}\) is unique
  2. \(A^{-1}\) is nonsingular and \((A^{-1})^{-1}=A\)
  3. If \(B\) is nonsingular \(n\times n\), then \((AB)^{-1}=B^{-1}A^{-1}\)

Proof of uniqueness of the inverse.

Suppose \(B\) and \(C\) are both inverses of \(A\): \[ AB = I, \quad BA = I, \qquad AC = I, \quad CA = I . \] Then \[ C = CI = C(AB) = (CA)B = IB = B, \] using associativity in the middle step. So \(B = C\): there is only one inverse, and we may write \(A^{-1}\). ■

Proof of \((A^{-1})^{-1} = A\).

From \(A^{-1}A = I\) we see that \(A\) is an inverse of \(A^{-1}\). By uniqueness it is the inverse, so \((A^{-1})^{-1} = A\). ■

Proof of \((AB)^{-1} = B^{-1}A^{-1}\).

Multiply out, cancelling from the inside: \[ \bigl(B^{-1}A^{-1}\bigr)(AB) = B^{-1}\bigl(A^{-1}A\bigr)B = B^{-1}IB = B^{-1}B = I . \] So \(B^{-1}A^{-1}\) is an inverse of \(AB\), and by uniqueness it is the inverse. Note the order reverses. ■

Matrix Transpose
Definition 6.9
Theorem 6.4
  1. \((A^t)^t = A\)
  2. \((A+B)^t = A^t + B^t\)
  3. \((AB)^t=B^t A^t\)
  4. if \(A^{-1}\) exists, then \((A^{-1})^t = (A^t)^{-1}\)

Proof of \((AB)^{t} = B^{t}A^{t}\).

Working entrywise, and using that transposing swaps indices, \[ \bigl[(AB)^{t}\bigr]_{ij} = (AB)_{ji} = \sum_{s=1}^{k} A_{js}B_{si} = \sum_{s=1}^{k}\bigl(A^{t}\bigr)_{sj}\bigl(B^{t}\bigr)_{is} = \sum_{s=1}^{k}\bigl(B^{t}\bigr)_{is}\bigl(A^{t}\bigr)_{sj} = \bigl(B^{t}A^{t}\bigr)_{ij}. \] ■

Proof of \((A^{-1})^{t} = (A^{t})^{-1}\).

Using the previous result, \[ \bigl(A^{t}\bigr)\bigl(A^{-1}\bigr)^{t} = \bigl(A^{-1}A\bigr)^{t} = I^{t} = I, \] so \((A^{-1})^{t}\) is an inverse of \(A^{t}\), and by uniqueness it is the inverse. ■

Computing an inverse

Finding \(A^{-1}\) means finding \(B\) with \(AB = I_n\), which is \(n\) linear systems sharing the same matrix — one for each column of \(I\). They can be solved together by augmenting with the whole identity: \[ \bigl(A \mid I\bigr) \xrightarrow{\ \text{elimination}\ } \bigl(U \mid Y\bigr) \xrightarrow{\ \text{back-substitution}\ } B . \]

Example 6.4

The inverse of a \(2\times 2\) matrix.

Let \[ A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, \qquad ad - bc \ne 0, \] and look for \(B = \begin{pmatrix} e & f \\ g & h \end{pmatrix}\). Assuming \(a \ne 0\), one elimination step gives \[ \left(\begin{array}{cc|cc} a & b & 1 & 0 \\ c & d & 0 & 1 \end{array}\right) \xrightarrow{\ \ } \left(\begin{array}{cc|cc} a & b & 1 & 0 \\ 0 & d - \frac{cb}{a} & -\frac{c}{a} & 1 \end{array}\right). \]

Reading off the second column of \(B\) from the second system, then the first: \[ g = \frac{-\frac{c}{a}}{\,d - \frac{cb}{a}\,} = \frac{-c}{ad-bc}, \qquad h = \frac{1}{\,d - \frac{cb}{a}\,} = \frac{a}{ad-bc}, \] and then \[ e = \frac{1 - bg}{a} = \frac{1 + \frac{bc}{ad-bc}}{a} = \frac{\frac{ad-bc+bc}{ad-bc}}{a} = \frac{ad}{a(ad-bc)} = \frac{d}{ad-bc}, \] \[ f = \frac{-bh}{a} = \frac{-b}{ad-bc}. \]

Collecting these, \[ A^{-1} = B = \frac{1}{ad-bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}, \] the formula worth memorising — and note where the hypothesis \(ad-bc \ne 0\) was needed.

6.4 The Determinant of a Matrix

Determinants
Definition 6.10
  1. If \(A=[a]\) is a \(1\times 1\) matrix, then \(\det A=a\)
  2. If \(A\) is \(n\times n\), the minor \(M_{ij}\) is the determinant of the \((n-1)\times (n-1)\) submatrix deleting row \(i\) and column \(j\) of \(A\)
  3. The cofactor \(A_{ij}\) associated with \(M_{ij}\) is \(A_{ij}=(-1)^{i+j}M_{ij}\)
  4. The determinant of \(n\times n\) matrix \(A\) for \(n>1\) is \[ \begin{aligned} \det A = \sum_{j=1}^n a_{ij} A_{ij} =\sum_{j=1}^n (-1)^{i+j} a_{ij}M_{ij} \end{aligned} \] or \[ \begin{aligned} \det A = \sum_{i=1}^n a_{ij} A_{ij} =\sum_{i=1}^n (-1)^{i+j} a_{ij}M_{ij} \end{aligned} \]

The determinant is defined by cofactor expansion, recursively in the size: \[ \det[a] = a, \qquad \det\begin{bmatrix} a & b \\ c & d\end{bmatrix} = (-1)^{1+1}ad + (-1)^{1+2}bc = ad - bc, \] and for \(3\times 3\), \[ \det\begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix} = a(ei - fh) - b(di - fg) + c(dh - eg) = aei + bfg + cdh - afh - bdi - ceg . \]

That is \(3! = 6\) terms. For \(4\times 4\) it is \(4! = 24\) terms, and in general \(n!\) — hopeless beyond very small \(n\).

Properties
Theorem 6.5
  1. If any row or column of \(A\) has all zeros, then \(\det A=0\)
  2. If \(A\) has two rows or two columns equal, then \(\det A=0\)
  3. If \(\tilde{A}\) comes from \((E_i)\leftrightarrow(E_j)\) on \(A\), then \(\det \tilde{A}=-\det A\)
  4. If \(\tilde{A}\) comes from \((\lambda E_i)\leftrightarrow(E_i)\) on \(A\), then \(\det \tilde{A}=\lambda \det A\)
  5. If \(\tilde{A}\) comes from \((E_i+\lambda E_j)\leftrightarrow(E_i)\) on \(A\), with \(i\ne j\), then \(\det \tilde{A}=\det A\)
  6. If \(B\) is also \(n\times n\), then \(\det AB=\det A \det B\)
  7. \(\det A^t = \det A\)
  8. When \(A^{-1}\) exists, \(\det A^{-1} = (\det A)^{-1}\)
  9. If \(A\) is upper/lower triangular or diagonal, then \(\det A = \prod_{i=1}^n a_{ii}\)

The practical method uses elimination instead. Row operations of the form “subtract a multiple of one row from another” leave the determinant unchanged, and the determinant of a triangular matrix is the product of its diagonal.

Example 6.5

A determinant by elimination.

\[ A = \begin{bmatrix} 1 & 2 & 0 \\ 2 & 1 & -1 \\ 3 & 1 & 1 \end{bmatrix} \xrightarrow{\ \ } \begin{bmatrix} 1 & 2 & 0 \\ 0 & -3 & -1 \\ 0 & -5 & 1 \end{bmatrix} \xrightarrow{\ \ } \begin{bmatrix} 1 & 2 & 0 \\ 0 & -3 & -1 \\ 0 & 0 & 1 - \frac{5}{3}(-1) \end{bmatrix} = U, \] where the last pivot is \(1 + \frac53 = \frac83\). Hence \[ \det A = \det U = 1\cdot(-3)\cdot\frac{8}{3} = -8 . \] This costs \(O(n^3)\) operations rather than \(O(n!)\).

Linear Systems and Determinants
Theorem 6.6

The following statements are equivalent for any \(n\times n\) matrix \(A\):

  1. The equation \(A\mathbf{x}=\mathbf{0}\) has the unique solution \(\mathbf{x}=\mathbf{0}\)
  2. The system \(A\mathbf{x}=\mathbf{b}\) has a unique solution for any \(\mathbf{b}\)
  3. The matrix \(A\) is nonsingular; that is, \(A^{-1}\) exists
  4. \(\det A\ne 0\)
  5. Gaussian elimination with row interchanges can be performed on the system \(A\mathbf{x}=\mathbf{b}\) for any \(\mathbf{b}\)

6.5 Matrix Factorization

LU Factorization

The \(k\)th Gaussian transformation matrix is defined by \[ \begin{aligned} M^{(k)} = \begin{bmatrix} 1 & 0 & & \cdots & & \cdots & & 0 \\ 0 & \ddots & \ddots & & & & & \vdots \\ \vdots & \ddots & \ddots & \ddots & & & & \vdots \\ \vdots & & 0 & \ddots & \ddots & & & \vdots \\ \vdots & & \vdots & -m_{k+1,k} & \ddots & \ddots & & \vdots \\ \vdots & & \vdots & \vdots & 0 & \ddots & & \vdots \\ \vdots & & \vdots & \vdots & \vdots & \ddots & \ddots & 0\\ 0 & \cdots & 0 & -m_{n,k} & 0 & \cdots & 0 & 1\\ \end{bmatrix} \end{aligned} \]


Gaussian elimination without pivoting does more than solve one system — it computes a factorization of \(A\).

Elimination without pivoting factors A into a lower triangular L, whose diagonal is all ones, and the upper triangular U it leaves behind.
Figure 6.4: Elimination without pivoting factors \(A\) into a lower triangular \(L\), whose diagonal is all ones, and the upper triangular \(U\) it leaves behind.

Once \(A = LU\) is known, solving \(A\mathbf{x} = \mathbf{b}\) means solving \(LU\mathbf{x} = \mathbf{b}\) in two triangular stages:

  1. set \(\mathbf{y} = U\mathbf{x}\) and solve \(L\mathbf{y} = \mathbf{b}\) — \(L\) is lower triangular, so this is a forward solve;
  2. solve \(U\mathbf{x} = \mathbf{y}\) — \(U\) is upper triangular, a back solve.

Each stage costs \(O(n^2)\), against \(O(n^3)\) for the factorization. So for many right-hand sides sharing one matrix, \[ A\mathbf{x} = \mathbf{b}_1, \qquad A\mathbf{x} = \mathbf{b}_2, \qquad \ldots \] the expensive work is done once and reused.

Elimination as matrix multiplication

LU Factorization

Gaussian elimination can be written as \[ \begin{aligned} A^{(n)} = M^{(n-1)}\cdots M^{(1)}A = \begin{bmatrix} a_{11}^{(1)} & a_{12}^{(1)} & \cdots & a_{1n}^{(1)} \\ 0 & a_{22}^{(2)} & \ddots & \vdots \\ \vdots & \ddots & \ddots & a_{n-1,n}^{(n-1)} \\ 0 & \cdots & 0 & a_{nn}^{(n)} \end{bmatrix} \end{aligned} \]


Each elimination step is itself a matrix multiplication. Subtracting \(m_1\) times row 1 from row 3 and \(m_2\) times row 1 from row 4, for instance, is left multiplication by a matrix that differs from the identity only in column 1: \[ \begin{bmatrix} 1 & & & \\ & 1 & & \\ -m_1 & & 1 & \\ -m_2 & & & 1 \end{bmatrix} \begin{bmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ 13 & 14 & 15 & 16 \end{bmatrix} = \begin{bmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9-5m_1 & 10-6m_1 & 11-7m_1 & 12-8m_1 \\ 13-5m_2 & 14-6m_2 & 15-7m_2 & 16-8m_2 \end{bmatrix}. \]

Example 6.6

A complete \(LU\) factorization.

Take \[ A = \begin{bmatrix} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{bmatrix}. \]

First column. The multipliers are \(m_{21} = \frac21 = 2\) and \(m_{31} = \frac31 = 3\), so \[ M^{(1)} = \begin{bmatrix} 1 & 0 & 0 \\ -2 & 1 & 0 \\ -3 & 0 & 1\end{bmatrix}, \qquad A^{(2)} = M^{(1)}A = \begin{bmatrix} 1 & 4 & 7 \\ 0 & -3 & -6 \\ 0 & -6 & -12 \end{bmatrix}. \]

Second column. Now \(m_{32} = \frac{-6}{-3} = 2\), so \[ M^{(2)} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -2 & 1\end{bmatrix}, \qquad U = A^{(3)} = M^{(2)}A^{(2)} = \begin{bmatrix} 1 & 4 & 7 \\ 0 & -3 & -6 \\ 0 & 0 & 0 \end{bmatrix}. \]

Undoing the steps. We have \(M^{(2)}M^{(1)}A = U\), so \[ A = \left[M^{(2)}M^{(1)}\right]^{-1}U = \underbrace{\left[M^{(1)}\right]^{-1}\left[M^{(2)}\right]^{-1}}_{\textstyle L}U , \] the order reversing by the rule of §6.3. Inverting an elimination matrix just flips the sign of its multipliers — adding back what was subtracted — so \[ L = \begin{bmatrix} 1 & 0 & 0 \\ m_{21} & 1 & 0 \\ m_{31} & m_{32} & 1\end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 2 & 1 & 0 \\ 3 & 2 & 1\end{bmatrix}, \] and therefore \[ A = LU = \begin{bmatrix} 1 & 0 & 0 \\ 2 & 1 & 0 \\ 3 & 2 & 1\end{bmatrix} \begin{bmatrix} 1 & 4 & 7 \\ 0 & -3 & -6 \\ 0 & 0 & 0\end{bmatrix}. \]

The multipliers land in \(L\) exactly where they were used, which is why elimination can overwrite \(A\) with both factors in place.

Proof of the sign flip, \(\left[M^{(k)}\right]^{-1}\).

Check it directly for the two steps above: \[ \begin{bmatrix} 1 & & \\ -2 & 1 & \\ -3 & & 1\end{bmatrix} \begin{bmatrix} 1 & & \\ 2 & 1 & \\ 3 & & 1\end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1\end{bmatrix} = I, \] \[ \begin{bmatrix} 1 & & \\ & 1 & \\ & -2 & 1\end{bmatrix} \begin{bmatrix} 1 & & \\ & 1 & \\ & 2 & 1\end{bmatrix} = I . \] Multiplying the two inverses in the right order rebuilds \(L\): \[ \left[M^{(1)}\right]^{-1}\left[M^{(2)}\right]^{-1} = \begin{bmatrix} 1 & & \\ 2 & 1 & \\ 3 & & 1\end{bmatrix} \begin{bmatrix} 1 & & \\ & 1 & \\ & 2 & 1\end{bmatrix} = \begin{bmatrix} 1 & & \\ 2 & 1 & \\ 3 & 2 & 1\end{bmatrix}. \] Note that the multipliers do not interfere — that is special to this order, and it is what makes the construction work. ■

LU Factorization

Reversing the elimination steps gives the inverses: \[ \begin{aligned} L^{(k)} = [M^{(k)}]^{-1} = \begin{bmatrix} 1 & 0 & & \cdots & & \cdots & & 0 \\ 0 & \ddots & \ddots & & & & & \vdots \\ \vdots & \ddots & \ddots & \ddots & & & & \vdots \\ \vdots & & 0 & \ddots & \ddots & & & \vdots \\ \vdots & & \vdots & m_{k+1,k} & \ddots & \ddots & & \vdots \\ \vdots & & \vdots & \vdots & 0 & \ddots & & \vdots \\ \vdots & & \vdots & \vdots & \vdots & \ddots & \ddots & 0\\ 0 & \cdots & 0 & m_{n,k} & 0 & \cdots & 0 & 1\\ \end{bmatrix} \end{aligned} \] and we have \[ \begin{aligned} LU&=L^{(1)}\cdots L^{(n-1)}\cdots M^{(n-1)}\cdots M^{(1)} A \\ &= [M^{(1)}]^{-1}\cdots [M^{(n-1)}]^{-1}\cdots M^{(n-1)} \cdots M^{(1)} A = A \end{aligned} \]


LU Factorization
Theorem 6.7

If Gaussian elimination can be performed on the linear system \(A\mathbf{x}=\mathbf{b}\) without row interchanges, \(A\) can be factored into the product of lower-triangular \(L\) and upper-triangular \(U\) as \(A=LU\), where \(m_{ji}=a_{ji}^{(i)}/a_{ii}^{(i)}\): \[ \begin{aligned} U= \begin{bmatrix} a_{11}^{(1)} & a_{12}^{(1)} & \cdots & a_{1n}^{(1)} \\ 0 & a_{22}^{(2)} & \ddots & \vdots \\ \vdots & \ddots & \ddots & a_{n-1,n}^{(n-1)} \\ 0 & \cdots & 0 & a_{nn}^{(n)} \end{bmatrix},\ L= \begin{bmatrix} 1 & 0 & \cdots & 0 \\ m_{21} & 1 & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ m_{n1} & \cdots & m_{n,n-1} & 1 \end{bmatrix} \end{aligned} \]


Permutation matrices

Permutation Matrices

Suppose \(k_1,\ldots,k_n\) is a permutation of \(1,\ldots,n\). The permutation matrix \(P=(p_{ij})\) is defined by \[ \begin{aligned} p_{ij} = \begin{cases} 1, & \text{if } j=k_i,\\ 0, & \text{otherwise.} \end{cases} \end{aligned} \]

  1. \(PA\) permutes the rows of \(A\): \[ \begin{aligned} PA = \begin{bmatrix} a_{k_11} & \cdots & a_{k_1n} \\ \vdots & \ddots & \vdots \\ a_{k_n1} & \cdots & a_{k_nn} \end{bmatrix} \end{aligned} \]
  2. \(P^{-1}\) exists and \(P^{-1}=P^t\)

Gaussian elimination with row interchanges then becomes: \[ \begin{aligned} A=P^{-1}LU = (P^t L ) U \end{aligned} \]


Row exchanges are matrix multiplications too. A permutation matrix is the identity with its rows reordered, and multiplying by it on the left applies that reordering.

Example 6.7

Exchanging rows 2 and 4.

The permutation \((k_1, k_2, k_3, k_4) = (1, 4, 3, 2)\) gives \[ \underbrace{\begin{bmatrix} 1 & & & \\ & & & 1 \\ & & 1 & \\ & 1 & & \end{bmatrix}}_{\textstyle P} \underbrace{\begin{bmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ 13 & 14 & 15 & 16 \end{bmatrix}}_{\textstyle A} = \begin{bmatrix} 1 & 2 & 3 & 4 \\ 13 & 14 & 15 & 16 \\ 9 & 10 & 11 & 12 \\ 5 & 6 & 7 & 8 \end{bmatrix}. \]

With pivoting, then, elimination produces \(PA = LU\) rather than \(A = LU\).

6.6 Special Types of Matrices

Some matrices can be factored faster, or without pivoting, because of their structure. This section collects the cases worth recognising.

Diagonally dominant matrices

Diagonally Dominant Matrices
Definition 6.11

The \(n\times n\) matrix \(A\) is said to be strictly diagonally dominant when \[ \begin{aligned} |a_{ii}|>\sum_{j\ne i} |a_{ij}| \end{aligned} \]

Theorem 6.8

A strictly diagonally dominant matrix \(A\) is nonsingular, Gaussian elimination can be performed on \(A\mathbf{x}=\mathbf{b}\) without row interchanges, and the computations will be stable.


Example 6.8

Checking diagonal dominance.

\[ A = \begin{bmatrix} 5 & -3 & -2 \\ 1 & -2 & 0 \\ 0 & 3 & 3 \end{bmatrix} \] Row by row, comparing each diagonal entry against the sum of the others: \[ \begin{aligned} |5| &\ge |-3| + |-2| = 5, \\ |-2| &> |1| + |0| = 1, \\ |3| &\ge |0| + |3| = 3 . \end{aligned} \] All three hold, so \(A\) is diagonally dominant — and such a matrix needs no pivoting at all.

Positive definite matrices

Positive Definite Matrices
Definition 6.12

A matrix \(A\) is positive definite if it is symmetric and if \(\mathbf{x}^t A \mathbf{x} > 0\) for every \(\mathbf{x}\ne \mathbf{0}\).

Theorem 6.9

If \(A\) is an \(n\times n\) positive definite matrix, then

  1. \(A\) has an inverse
  2. \(a_{ii}>0\)
  3. \(\max_{1\le k,j\le n} |a_{kj}| \le \max_{1\le i \le n} |a_{ii}|\)
  4. \((a_{ij})^2<a_{ii}a_{jj}\) for \(i\ne j\)

A symmetric matrix is positive definite if \(\mathbf{x}^{t}A\mathbf{x} > 0\) for every \(\mathbf{x} \ne \mathbf{0}\). Three consequences follow by choosing \(\mathbf{x}\) cleverly.

Proof of nonsingularity.

Suppose \(A\mathbf{x} = \mathbf{0}\) for some \(\mathbf{x}\). Multiplying by \(\mathbf{x}^{t}\) gives \(\mathbf{x}^{t}A\mathbf{x} = 0\). But \(A\) is positive definite, so this forces \(\mathbf{x} = \mathbf{0}\). The only solution of \(A\mathbf{x} = \mathbf{0}\) is trivial, so \(A\) is nonsingular. ■

Proof of positive diagonal entries.

Take \(\mathbf{x} = \mathbf{e}_i\), the vector with \(1\) in position \(i\) and zeros elsewhere. Then \[ \mathbf{x}^{t}A\mathbf{x} = a_{ii} > 0 \] since \(A\) is positive definite. So every diagonal entry is positive. ■

Proof of the off-diagonal bound \(a_{ij}^2 < a_{ii}a_{jj}\).

For \(i \ne j\), take \(\mathbf{x}\) with \(\alpha\) in position \(i\), \(1\) in position \(j\) and zeros elsewhere. Then \[ \mathbf{x}^{t}A\mathbf{x} = a_{ii}\alpha^2 + 2\alpha a_{ij} + a_{jj} > 0 \] for every real \(\alpha\). A quadratic in \(\alpha\) that is never zero has no real roots, so its discriminant is negative: \[ 4a_{ij}^2 - 4a_{ii}a_{jj} < 0 \qquad\Longrightarrow\qquad a_{ij}^2 < a_{ii}a_{jj}. \] So no off-diagonal entry can be large compared with the diagonal — a positive definite matrix is diagonally weighted by necessity. ■

Principal submatrices

Principal Submatrices
Definition 6.13

A leading principal submatrix of a matrix \(A\) is a matrix of the form \[ \begin{aligned} A_k = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1k} \\ a_{21} & a_{22} & \cdots & a_{2k} \\ \vdots & \vdots & & \vdots \\ a_{k1} & a_{k2} & \cdots & a_{kk} \end{bmatrix} \end{aligned} \] for some \(1\le k \le n\).

Theorem 6.10

A symmetric matrix \(A\) is positive definite if and only if each of its leading principal submatrices has a positive determinant.


Example 6.9

Testing positive definiteness by leading minors.

\[ A = \begin{bmatrix} 4 & 2 & 0 \\ 2 & 8 & 1 \\ 0 & 1 & 1\end{bmatrix} \] is symmetric, so the test applies. Its leading principal submatrices are \[ A_1 = \begin{bmatrix} 4 \end{bmatrix}, \qquad A_2 = \begin{bmatrix} 4 & 2 \\ 2 & 8\end{bmatrix}, \qquad A_3 = A, \] with determinants \[ \det A_1 = 4 > 0, \qquad \det A_2 = 32 - 4 = 28 > 0, \qquad \det A_3 = 24 > 0 . \] All positive, so \(A\) is positive definite.

\(LDL^{t}\) and Cholesky factorization

SPD and Gaussian Elimination
Theorem 6.11

The symmetric matrix \(A\) is positive definite if and only if Gaussian elimination without row interchanges can be done on \(A\mathbf{x}=\mathbf{b}\) with all pivot elements positive, and the computations are then stable.

Corollary 6.1

The matrix \(A\) is positive definite if and only if it can be factored \(A=LDL^t\) where \(L\) is lower triangular with \(1\)’s on its diagonal and \(D\) is diagonal with positive diagonal entries.

Corollary 6.2

The matrix \(A\) is positive definite if and only if it can be factored \(A=LL^t\), where \(L\) is lower triangular with nonzero diagonal entries.


For a symmetric positive definite matrix the \(LU\) factorization can be made symmetric too, which halves both the work and the storage.

Example 6.10

The \(LDL^{t}\) factorization.

Run elimination on the same matrix: \[ A = \begin{bmatrix} 4 & 2 & 0 \\ 2 & 8 & 1 \\ 0 & 1 & 1\end{bmatrix} \xrightarrow[\;m_{31}=0\;]{\;m_{21}=\frac12\;} \begin{bmatrix} 4 & 2 & 0 \\ 0 & 7 & 1 \\ 0 & 1 & 1\end{bmatrix} \xrightarrow{\;m_{32}=\frac17\;} \begin{bmatrix} 4 & 2 & 0 \\ 0 & 7 & 1 \\ 0 & 0 & \frac67\end{bmatrix} = U . \]

The pivots \(4, 7, \frac67\) are all positive and \(A\) is symmetric, confirming that \(A\) is positive definite. The multipliers give \[ L = \begin{bmatrix} 1 & & \\ \frac12 & 1 & \\ 0 & \frac17 & 1\end{bmatrix}, \qquad A = LU . \]

Now split the pivots off \(U\). Defining \[ D = \begin{bmatrix} 4 & & \\ & 7 & \\ & & \frac67 \end{bmatrix}, \] the rows of \(U\) divided by their pivots are precisely \(L^{t}\): \[ U = D\underbrace{\begin{bmatrix} 1 & \frac12 & 0 \\ & 1 & \frac17 \\ & & 1 \end{bmatrix}}_{\textstyle L^{t}}, \] and therefore \[ A = LDL^{t}. \]

Example 6.11

Cholesky: \(A = \tilde L\tilde L^{t}\).

Because \(A\) is positive definite, every entry of \(D\) is positive and \(D^{1/2}\) makes sense. Setting \[ \tilde L = L\,D^{1/2} = L\begin{bmatrix} \sqrt4 & & \\ & \sqrt7 & \\ & & \sqrt{\frac67}\end{bmatrix} = \begin{pmatrix} 2 & 0 & 0 \\ 1 & \sqrt7 & 0 \\ 0 & \frac{1}{\sqrt7} & \sqrt{\frac67} \end{pmatrix}, \] we get \[ A = LDL^{t} = LD^{1/2}D^{1/2}L^{t} = \bigl(LD^{1/2}\bigr)\bigl(LD^{1/2}\bigr)^{t} = \tilde L\tilde L^{t}, \] using \(\left(D^{1/2}\right)^{t} = D^{1/2}\) since \(D\) is diagonal. This is the Cholesky factorization: one triangular factor instead of two, and it exists precisely for symmetric positive definite matrices.

Band matrices

Band Matrices
Definition 6.14

An \(n\times n\) matrix is called a band matrix if \(p,q\) exist with \(1<p,q<n\) and \(a_{ij}=0\) when \(p\le j-i\) or \(q\le i-j\). The bandwidth is \(w=p+q-1\).

A tridiagonal matrix has \(p=q=2\) and bandwidth \(3\).

Theorem 6.12

Suppose \(A=[a_{ij}]\) is tridiagonal with \(a_{i,i-1}a_{i,i+1}\ne 0\). If \(|a_{11}|>|a_{12}|\), \(|a_{ii}|\ge |a_{i,i-1}|+|a_{i,i+1}|\), and \(|a_{nn}|>|a_{n,n-1}|\), then \(A\) is nonsingular.

A band matrix has all its nonzeros confined to a narrow diagonal band: \(a_{ij} = 0\) whenever \(j - i \ge p\) or \(i - j \ge q\), so \(p\) bounds how far the band reaches above the diagonal and \(q\) how far below, giving bandwidth \(p + q - 1\).

A band matrix with p = q = 2. Only the diagonal and one neighbouring diagonal on each side can be nonzero.
Figure 6.5: A band matrix with \(p = q = 2\). Only the diagonal and one neighbouring diagonal on each side can be nonzero.

Elimination never creates a nonzero outside the band, so the work drops from \(O(n^3)\) to \(O(n)\) for fixed bandwidth — which is why the tridiagonal case (\(p = q = 2\)) made the cubic spline algorithm of §3.5 cheap.