In Linear Algebra 00 a matrix was only a compact way to write a system of equations. This post treats matrices as objects with their own algebra: they can be added, multiplied, transposed and — sometimes — inverted. Matrix multiplication is the operation that makes all of this interesting, so it gets four separate readings, each useful in a different situation. Then row operations become matrices themselves (elementary matrices), which turns Gaussian elimination into an algebraic statement: A=LUA = LU, a lower triangular matrix times an upper triangular one, or PA=LUPA = LU when rows must be exchanged. This factorization is how real software solves Ax=bA\mathbf{x} = \mathbf{b}, and it explains a rule every numerical programmer learns early: do not compute A−1A^{-1} to solve a linear system.

Series map: 00 Vectors & Linear Systems → 01 Matrix Algebra, Inverses & LU (this post) → 02 Vector Spaces, Basis & Dimension → 03 Linear Maps, Change of Basis & Determinants → 04 Eigenvalues & Diagonalization → 05 Inner Products, Spectral Theorem & SVD.


Learning Outcome

  • Multiply matrices in four ways — entry by entry, by columns, by rows, and as a sum of outer products — and know when each view is the helpful one.
  • Explain why AB≠BAAB \neq BA in general, and name other rules from ordinary algebra that fail for matrices.
  • Use the transpose rules, including (AB)T=BTAT(AB)^T = B^TA^T, and recognise symmetric, triangular and permutation matrices.
  • Multiply block (partitioned) matrices and do one step of block elimination.
  • Write each row operation as an elementary matrix and invert it.
  • Define the inverse, use the 2×22 \times 2 formula, and compute A−1A^{-1} by Gauss–Jordan on [ A∣I ][\,A \mid I\,].
  • State and prove the first version of the invertible matrix theorem.
  • Factor A=LUA = LU and PA=LUPA = LU by hand, prove that the LU factors are unique, and solve systems with two triangular solves.
  • Count the cost of elimination (about 23n3\tfrac23 n^3 flops) and explain why solving with A−1A^{-1} is slower and less reliable.

Chapter 1 — Matrix operations

Terminology

  • m×nm \times n matrix — a rectangular array of numbers with mm rows and nn columns. aija_{ij} is the entry in row ii, column jj.
  • Square matrix — m=nm = n. Its main diagonal is a11,a22,…,anna_{11}, a_{22}, \dots, a_{nn}.
  • Identity matrix InI_n — square, 1 on the main diagonal, 0 elsewhere. Inx=xI_n\mathbf{x} = \mathbf{x} for all x\mathbf{x}.
  • Zero matrix 00 — all entries 0.
  • Equal matrices — same size and the same entry in every position.

Addition and scalar multiplication work entry by entry, exactly as for vectors, and obey the same eight rules. Only matrices of the same size can be added.

The matrix product

If AA is m×nm \times n and BB is n×pn \times p, the product ABAB is the m×pm \times p matrix with entries

(AB)ij=∑k=1naikbkj=ai1b1j+ai2b2j+⋯+ainbnj.(AB)_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj} = a_{i1}b_{1j} + a_{i2}b_{2j} + \dots + a_{in}b_{nj}.

The inner sizes must match: (m×n)(n×p)=m×p(m \times n)(n \times p) = m \times p. The example used throughout this chapter:

A=(1234),B=(5678),AB=(19224350).A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \qquad B = \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}, \qquad AB = \begin{pmatrix} 19 & 22 \\ 43 & 50 \end{pmatrix}.

Four ways to read AB

1. Entry by entry (row times column). (AB)ij(AB)_{ij} is the dot product of row ii of AA with column jj of BB. For example (AB)12=1⋅6+2⋅8=22(AB)_{12} = 1\cdot 6 + 2 \cdot 8 = 22.

2. By columns. Column jj of ABAB is AA times column jj of BB:

AB=A(b1⋯bp)=(Ab1⋯Abp).AB = A\begin{pmatrix} \mathbf{b}_1 & \cdots & \mathbf{b}_p \end{pmatrix} = \begin{pmatrix} A\mathbf{b}_1 & \cdots & A\mathbf{b}_p \end{pmatrix}.

So every column of ABAB is a combination of the columns of AA. Here Ab1=5(1,3)+7(2,4)=(19,43)A\mathbf{b}_1 = 5(1,3) + 7(2,4) = (19, 43).

3. By rows. Row ii of ABAB is row ii of AA times BB, so every row of ABAB is a combination of the rows of BB. Here row 1 is 1⋅(5,6)+2⋅(7,8)=(19,22)1\cdot(5,6) + 2\cdot(7,8) = (19, 22). This is the view that explains elimination: row operations combine rows.

4. Columns times rows (sum of outer products). Multiply column kk of AA (an m×1m \times 1 matrix) by row kk of BB (a 1×p1 \times p matrix). Each such product is a full m×pm \times p matrix of rank at most one (Linear Algebra 02), and ABAB is their sum:

AB=∑k=1nakbk∗=(13)(56)+(24)(78)=(561518)+(14162832)=(19224350).AB = \sum_{k=1}^{n} \mathbf{a}_k \mathbf{b}^{*}_k = \begin{pmatrix} 1 \\ 3 \end{pmatrix}\begin{pmatrix} 5 & 6 \end{pmatrix} + \begin{pmatrix} 2 \\ 4 \end{pmatrix}\begin{pmatrix} 7 & 8 \end{pmatrix} = \begin{pmatrix} 5 & 6 \\ 15 & 18 \end{pmatrix} + \begin{pmatrix} 14 & 16 \\ 28 & 32 \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ 43 & 50 \end{pmatrix}.

Here bk∗\mathbf{b}^{*}_k denotes row kk of BB. This view reappears in the SVD (Linear Algebra 05), which writes a matrix as a sum of rank-one pieces ordered by importance.

All four give the same numbers because each one computes ∑kaikbkj\sum_k a_{ik}b_{kj} in position (i,j)(i,j); they only group the work differently.

Trick: pick the view that matches the question. "Is b\mathbf{b} in the column space?" — columns. "What does a row operation do?" — rows. "What is the rank of ABAB?" — outer products. "Just give me a number" — entries.

Algebraic rules — and what fails

For matrices of compatible sizes:

  • A(BC)=(AB)CA(BC) = (AB)C (associative), A(B+C)=AB+ACA(B + C) = AB + AC and (A+B)C=AC+BC(A + B)C = AC + BC (distributive), c(AB)=(cA)B=A(cB)c(AB) = (cA)B = A(cB), and ImA=A=AInI_mA = A = AI_n.

Proof of associativity. For a vector x\mathbf{x}, Bx=∑kxkbkB\mathbf{x} = \sum_k x_k\mathbf{b}_k, so A(Bx)=∑kxkAbk=(AB)xA(B\mathbf{x}) = \sum_k x_k A\mathbf{b}_k = (AB)\mathbf{x} by the column view. Apply this to each column cj\mathbf{c}_j of CC: column jj of A(BC)A(BC) is A(Bcj)=(AB)cjA(B\mathbf{c}_j) = (AB)\mathbf{c}_j, which is column jj of (AB)C(AB)C. ■\blacksquare

Three rules from ordinary algebra fail:

  1. Not commutative. BA=(23343146)≠ABBA = \begin{pmatrix} 23 & 34 \\ 31 & 46 \end{pmatrix} \neq AB. (Often only one of ABAB, BABA is even defined.)
  2. Zero divisors. With N=(0100)N = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}, N≠0N \neq 0 but N2=0N^2 = 0.
  3. No cancellation. AB=ACAB = AC does not imply B=CB = C, even when A≠0A \neq 0 (take A=NA = N, B=NB = N, C=0C = 0).

Common pitfall: (A+B)2=A2+AB+BA+B2(A + B)^2 = A^2 + AB + BA + B^2, not A2+2AB+B2A^2 + 2AB + B^2. The two agree only when AB=BAAB = BA.


Chapter 2 — Transpose and special matrices

Transpose

The transpose ATA^T of an m×nm \times n matrix is the n×mn \times m matrix with (AT)ij=aji(A^T)_{ij} = a_{ji}: rows become columns. Rules:

(AT)T=A,(A+B)T=AT+BT,(cA)T=cAT,(AB)T=BTAT.(A^T)^T = A, \qquad (A + B)^T = A^T + B^T, \qquad (cA)^T = cA^T, \qquad (AB)^T = B^TA^T.

Proof of the last rule. ((AB)T)ij=(AB)ji=∑kajkbki=∑k(BT)ik(AT)kj=(BTAT)ij((AB)^T)_{ij} = (AB)_{ji} = \sum_k a_{jk}b_{ki} = \sum_k (B^T)_{ik}(A^T)_{kj} = (B^TA^T)_{ij}. ■\blacksquare

The order reverses, just like taking off shoes and socks. The dot product is a matrix product: x⋅y=xTy\mathbf{x}\cdot\mathbf{y} = \mathbf{x}^T\mathbf{y} (a 1×11 \times 1 matrix).

Special matrices

Type Definition Useful facts
Diagonal aij=0a_{ij} = 0 for i≠ji \neq j products and powers act entry by entry on the diagonal
Upper triangular aij=0a_{ij} = 0 for i>ji > j product of two upper triangular is upper triangular
Lower triangular aij=0a_{ij} = 0 for i<ji < j same for lower; unit lower triangular has 1s on the diagonal
Symmetric AT=AA^T = A ATAA^TA and AATAA^T are always symmetric
Permutation the rows of II in some order P ⁣AP\!A reorders the rows of AA; P−1=PTP^{-1} = P^T

ATAA^TA is symmetric: (ATA)T=AT(AT)T=ATA(A^TA)^T = A^T(A^T)^T = A^TA. For example, with X=(123456)X = \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{pmatrix}, XTX=(35444456)X^TX = \begin{pmatrix} 35 & 44 \\ 44 & 56 \end{pmatrix}. This matrix is the heart of least squares (Linear Algebra 05).

Product of lower triangular matrices is lower triangular. If aik=0a_{ik} = 0 for k>ik > i and bkj=0b_{kj} = 0 for j>kj > k, then in (AB)ij=∑kaikbkj(AB)_{ij} = \sum_k a_{ik}b_{kj} a term can be nonzero only if j≤k≤ij \le k \le i. When i<ji < j there is no such kk, so (AB)ij=0(AB)_{ij} = 0. If both have unit diagonal, (AB)ii=aiibii=1(AB)_{ii} = a_{ii}b_{ii} = 1. ■\blacksquare

Permutation matrices. Each row and each column of PP has exactly one 1. The rows of PP are orthonormal, so PPT=IPP^T = I, which means P−1=PTP^{-1} = P^T.


Chapter 3 — Block matrices

A matrix can be cut by horizontal and vertical lines into blocks (submatrices). If the column cuts of AA match the row cuts of BB, then ABAB can be computed block by block, using the same formula as for numbers — but keeping the order of each product:

(A11A12A21A22)(B11B12B21B22)=(A11B11+A12B21A11B12+A12B22A21B11+A22B21A21B12+A22B22).\begin{pmatrix} A_{11} & A_{12} \\ A_{21} & A_{22} \end{pmatrix} \begin{pmatrix} B_{11} & B_{12} \\ B_{21} & B_{22} \end{pmatrix} = \begin{pmatrix} A_{11}B_{11} + A_{12}B_{21} & A_{11}B_{12} + A_{12}B_{22} \\ A_{21}B_{11} + A_{22}B_{21} & A_{21}B_{12} + A_{22}B_{22} \end{pmatrix}.

The four views of Chapter 1 are all special cases: the column view cuts BB into columns, the row view cuts AA into rows, and the outer-product view cuts AA into columns and BB into rows.

Block elimination and the Schur complement

Let M=(ABCD)M = \begin{pmatrix} A & B \\ C & D \end{pmatrix} with AA square and invertible. Eliminating the block CC is one block row operation — "block row 2 minus CA−1CA^{-1} times block row 1":

(I0−CA−1I)(ABCD)=(AB0D−CA−1B).\begin{pmatrix} I & 0 \\ -CA^{-1} & I \end{pmatrix} \begin{pmatrix} A & B \\ C & D \end{pmatrix} = \begin{pmatrix} A & B \\ 0 & D - CA^{-1}B \end{pmatrix}.

The block S=D−CA−1BS = D - CA^{-1}B is the Schur complement of AA in MM. When every block is 1×11 \times 1 this is exactly one step of ordinary elimination: d−(c/a)bd - (c/a)b. Schur complements appear in statistics (conditional covariance), in optimization and in domain-decomposition solvers.

Watch out: in block formulas every product must keep its order. CA−1BCA^{-1}B cannot be rewritten as A−1BCA^{-1}BC or BCA−1BCA^{-1}.


Chapter 4 — Elementary matrices

An elementary matrix is the result of one row operation on the identity. Multiplying AA on the left by EE performs that row operation on AA (by the row view: row ii of EAEA is row ii of EE times AA).

Using the 3×33 \times 3 system from Linear Algebra 00,

A=(121381041),E21=(100−310001),E32=(1000100−21).A = \begin{pmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{pmatrix}, \qquad E_{21} = \begin{pmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}, \qquad E_{32} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -2 & 1 \end{pmatrix}.

E21E_{21} subtracts 3 times row 1 from row 2; E32E_{32} subtracts 2 times row 2 from row 3. (No E31E_{31} is needed because a31a_{31} is already 0.) Then

E32E21A=(12102−2005)=U.E_{32}E_{21}A = \begin{pmatrix} 1 & 2 & 1 \\ 0 & 2 & -2 \\ 0 & 0 & 5 \end{pmatrix} = U.

Every elementary matrix is invertible, and its inverse is elementary of the same type: undo "subtract ℓ\ell times row jj" by "add ℓ\ell times row jj"; undo a swap by the same swap; undo scaling by cc by scaling by 1/c1/c. For example

E21−1=(100310001).E_{21}^{-1} = \begin{pmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}.

The product in the "wrong" order is messy

E32E21=(100−3106−21),E21−1E32−1=(100310021).E_{32}E_{21} = \begin{pmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 6 & -2 & 1 \end{pmatrix}, \qquad E_{21}^{-1}E_{32}^{-1} = \begin{pmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ 0 & 2 & 1 \end{pmatrix}.

The entry 6 in the first product appears because row 3 is changed using the new row 2, which already contains −3-3 times row 1; indeed 6=(−2)(−3)6 = (-2)(-3). The inverses, multiplied in the opposite order, do not interact at all: the multipliers 33 and 22 simply drop into place. That clean matrix is LL, and Chapter 7 is built on it. (The messy product E32E21E_{32}E_{21} is L−1L^{-1}.)


Chapter 5 — The inverse of a matrix

Definition and uniqueness

A square n×nn \times n matrix AA is invertible (or nonsingular) if there is a matrix CC with

CA=IandAC=I.CA = I \quad \text{and} \quad AC = I.

Then CC is called the inverse and written A−1A^{-1}. A square matrix without an inverse is singular.

The inverse is unique. If CA=ICA = I and AD=IAD = I, then C=CI=C(AD)=(CA)D=ID=DC = CI = C(AD) = (CA)D = ID = D. ■\blacksquare (This short argument even shows a left inverse and a right inverse must agree.)

Properties. If AA and BB are invertible n×nn \times n matrices, then

(A−1)−1=A,(AB)−1=B−1A−1,(AT)−1=(A−1)T.(A^{-1})^{-1} = A, \qquad (AB)^{-1} = B^{-1}A^{-1}, \qquad (A^T)^{-1} = (A^{-1})^T.

Proof. (AB)(B−1A−1)=A(BB−1)A−1=AA−1=I(AB)(B^{-1}A^{-1}) = A(BB^{-1})A^{-1} = AA^{-1} = I, and similarly in the other order. For the transpose, take the transpose of AA−1=IAA^{-1} = I: (A−1)TAT=I(A^{-1})^TA^T = I, and similarly AT(A−1)T=IA^T(A^{-1})^T = I. ■\blacksquare

If AA is invertible, Ax=bA\mathbf{x} = \mathbf{b} has exactly one solution for every b\mathbf{b}, namely x=A−1b\mathbf{x} = A^{-1}\mathbf{b}: it is a solution because A(A−1b)=bA(A^{-1}\mathbf{b}) = \mathbf{b}, and it is the only one because Ax=bA\mathbf{x} = \mathbf{b} implies x=A−1Ax=A−1b\mathbf{x} = A^{-1}A\mathbf{x} = A^{-1}\mathbf{b}.

The 2 × 2 formula

(abcd)−1=1ad−bc(d−b−ca),provided ad−bc≠0.\begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad - bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}, \qquad \text{provided } ad - bc \neq 0.

Proof. Multiply: (abcd)(d−b−ca)=(ad−bc00ad−bc)\begin{pmatrix} a & b \\ c & d \end{pmatrix}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix} = \begin{pmatrix} ad - bc & 0 \\ 0 & ad - bc \end{pmatrix}, and the same holds in the other order. Divide by ad−bcad - bc. If ad−bc=0ad - bc = 0, the same product shows AA times a matrix gives 00; Exercise 6 shows AA is then singular. ■\blacksquare

The number ad−bcad - bc is the determinant of the 2×22 \times 2 matrix (Linear Algebra 03 defines it for all sizes). For A=(1234)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}: ad−bc=4−6=−2ad - bc = 4 - 6 = -2, so

A−1=−12(4−2−31)=(−213/2−1/2).A^{-1} = -\frac12 \begin{pmatrix} 4 & -2 \\ -3 & 1 \end{pmatrix} = \begin{pmatrix} -2 & 1 \\ 3/2 & -1/2 \end{pmatrix}.

Gauss–Jordan on [ A | I ]

Why it works. Suppose row operations E1,…,EkE_1, \dots, E_k turn AA into II: Ek⋯E1A=IE_k \cdots E_1 A = I. Then Ek⋯E1E_k\cdots E_1 is a left inverse of AA, and (by the invertible matrix theorem below) it is A−1A^{-1}. Applying the same operations to II produces Ek⋯E1I=A−1E_k \cdots E_1 I = A^{-1}. So: row reduce the wide matrix [ A∣I ][\,A \mid I\,]; if the left half becomes II, the right half is A−1A^{-1}. If the left half develops a zero row, AA is singular.

Worked example. Take the "second difference" matrix

K=(2−10−12−10−12).K = \begin{pmatrix} 2 & -1 & 0 \\ -1 & 2 & -1 \\ 0 & -1 & 2 \end{pmatrix}.

Forward elimination: R2←R2+12R1R_2 \leftarrow R_2 + \tfrac12 R_1, then R3←R3+23R2R_3 \leftarrow R_3 + \tfrac23 R_2:

(2−1010003/2−11/210004/31/32/31).\left(\begin{array}{ccc|ccc} 2 & -1 & 0 & 1 & 0 & 0 \\ 0 & 3/2 & -1 & 1/2 & 1 & 0 \\ 0 & 0 & 4/3 & 1/3 & 2/3 & 1 \end{array}\right).

The pivots are 2,32,432, \tfrac32, \tfrac43. Backward elimination: R2←R2+34R3R_2 \leftarrow R_2 + \tfrac34 R_3, then R1←R1+23R2R_1 \leftarrow R_1 + \tfrac23 R_2:

(2003/211/203/203/43/23/4004/31/32/31).\left(\begin{array}{ccc|ccc} 2 & 0 & 0 & 3/2 & 1 & 1/2 \\ 0 & 3/2 & 0 & 3/4 & 3/2 & 3/4 \\ 0 & 0 & 4/3 & 1/3 & 2/3 & 1 \end{array}\right).

Divide each row by its pivot:

K−1=(3/41/21/41/211/21/41/23/4)=14(321242123).K^{-1} = \begin{pmatrix} 3/4 & 1/2 & 1/4 \\ 1/2 & 1 & 1/2 \\ 1/4 & 1/2 & 3/4 \end{pmatrix} = \frac14\begin{pmatrix} 3 & 2 & 1 \\ 2 & 4 & 2 \\ 1 & 2 & 3 \end{pmatrix}.

Two observations that matter later. KK is symmetric and so is K−1K^{-1} (Exercise 7). And KK is tridiagonal — mostly zeros — but K−1K^{-1} is completely full. Keep that in mind for Chapter 8.


Chapter 6 — The invertible matrix theorem

Theorem. For a square n×nn \times n matrix AA, the following are equivalent (all true or all false):

  1. AA is invertible.
  2. AA is row equivalent to InI_n.
  3. AA has nn pivot positions.
  4. Ax=0A\mathbf{x} = \mathbf{0} has only the trivial solution.
  5. The columns of AA are linearly independent.
  6. Ax=bA\mathbf{x} = \mathbf{b} has at least one solution for every b∈Rn\mathbf{b} \in \mathbb{R}^n.
  7. The columns of AA span Rn\mathbb{R}^n.
  8. There is an n×nn \times n matrix CC with CA=ICA = I.
  9. There is an n×nn \times n matrix DD with AD=IAD = I.
  10. ATA^T is invertible.
  11. AA is a product of elementary matrices.

Proof. (1) ⇒ (8) and (1) ⇒ (9): take C=D=A−1C = D = A^{-1}.

(8) ⇒ (4): if Ax=0A\mathbf{x} = \mathbf{0} then x=CAx=C0=0\mathbf{x} = CA\mathbf{x} = C\mathbf{0} = \mathbf{0}.

(4) ⇔ (5): this is the definition of independence (Linear Algebra 00, Chapter 8).

(4) ⇒ (3): only the trivial solution means no free variables, so every one of the nn columns is a pivot column.

(3) ⇒ (2): nn pivots in an n×nn \times n matrix means one pivot in every row and every column, on the diagonal, so the RREF is InI_n.

(2) ⇒ (11): Ek⋯E1A=IE_k\cdots E_1A = I gives A=E1−1⋯Ek−1A = E_1^{-1}\cdots E_k^{-1}, a product of elementary matrices.

(11) ⇒ (1): elementary matrices are invertible, and so is any product of invertible matrices.

(9) ⇒ (6): given b\mathbf{b}, the vector x=Db\mathbf{x} = D\mathbf{b} satisfies Ax=ADb=bA\mathbf{x} = AD\mathbf{b} = \mathbf{b}.

(6) ⇔ (7): AxA\mathbf{x} ranges over all combinations of the columns (Linear Algebra 00).

(6) ⇒ (3): if AA had fewer than nn pivots, its echelon form UU would have a zero last row. Choose c\mathbf{c} with last entry 1; then Ux=cU\mathbf{x} = \mathbf{c} is inconsistent, and undoing the row operations on c\mathbf{c} gives a b\mathbf{b} with Ax=bA\mathbf{x} = \mathbf{b} inconsistent, contradicting (6).

(1) ⇔ (10): if AA is invertible, (A−1)T(A^{-1})^T inverts ATA^T (Chapter 5); apply this to ATA^T for the converse.

Every statement is now linked to every other. ■\blacksquare

Corollary (one-sided is enough). If AA and BB are square and AB=IAB = I, then BA=IBA = I and B=A−1B = A^{-1}. Proof: AB=IAB = I is statement (9) for AA, so AA is invertible; multiply AB=IAB = I on the left by A−1A^{-1} to get B=A−1B = A^{-1}. ■\blacksquare

Watch out: the corollary needs square matrices. For A=(10)A = \begin{pmatrix} 1 & 0 \end{pmatrix} and B=(10)B = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, AB=(1)=I1AB = (1) = I_1 but BA=(1000)≠I2BA = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} \neq I_2.

Linear Algebra 02, 03 and 04 add more lines to this list: rank nn, null space {0}\{\mathbf{0}\}, det⁡A≠0\det A \neq 0, and 00 is not an eigenvalue.


Chapter 7 — LU factorization

From elimination to A = LU

Suppose elimination on AA needs no row exchanges. Then only replacement operations "row ii minus ℓij\ell_{ij} times row jj" (with i>ji > j) are used, and

(E32E31E21) A=U⟹A=(E21−1E31−1E32−1) U=LU(E_{32}E_{31}E_{21})\,A = U \qquad\Longrightarrow\qquad A = (E_{21}^{-1}E_{31}^{-1}E_{32}^{-1})\,U = LU

(written for n=3n = 3; larger nn is the same). UU is upper triangular with the pivots on its diagonal. LL is unit lower triangular, and as Chapter 4 showed, its entries below the diagonal are exactly the multipliers: Lij=ℓijL_{ij} = \ell_{ij}.

For the running example, the multipliers were ℓ21=3\ell_{21} = 3, ℓ31=0\ell_{31} = 0, ℓ32=2\ell_{32} = 2, so

(121381041)=(100310021)(12102−2005).\begin{pmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ 0 & 2 & 1 \end{pmatrix} \begin{pmatrix} 1 & 2 & 1 \\ 0 & 2 & -2 \\ 0 & 0 & 5 \end{pmatrix}.

Multiply it out to check: row 2 of LULU is 3(1,2,1)+(0,2,−2)=(3,8,1)3(1,2,1) + (0,2,-2) = (3, 8, 1), and row 3 is 2(0,2,−2)+(0,0,5)=(0,4,1)2(0,2,-2) + (0,0,5) = (0, 4, 1).

LU factorization of the 3 by 3 example: elimination with multipliers 3, 0 and 2 turns A into the upper triangular U with pivots 1, 2, 5; the multipliers drop straight into the unit lower triangular L, while the product E32 E21 mixes them into a 6

Solving with L and U

Ax=bA\mathbf{x} = \mathbf{b} becomes L(Ux)=bL(U\mathbf{x}) = \mathbf{b}. Put c=Ux\mathbf{c} = U\mathbf{x} and solve two triangular systems:

  1. Forward substitution Lc=bL\mathbf{c} = \mathbf{b} (top to bottom).
  2. Back substitution Ux=cU\mathbf{x} = \mathbf{c} (bottom to top).

With b=(2,12,2)\mathbf{b} = (2, 12, 2): c1=2c_1 = 2; 3c1+c2=123c_1 + c_2 = 12 gives c2=6c_2 = 6; 2c2+c3=22c_2 + c_3 = 2 gives c3=−10c_3 = -10. So c=(2,6,−10)\mathbf{c} = (2, 6, -10) — exactly the right-hand side that elimination produced in Linear Algebra 00. Then Ux=cU\mathbf{x} = \mathbf{c} gives z=−2z = -2, y=1y = 1, x=2x = 2, as before.

The point: the factorization is done once; each new right-hand side then costs only two cheap triangular solves.

LDU and the symmetric case

Divide each row of UU by its pivot to get A=LDU′A = LDU' with DD the diagonal matrix of pivots and U′U' unit upper triangular. For the example, D=diag⁡(1,2,5)D = \operatorname{diag}(1, 2, 5) and

U′=(12101−1001).U' = \begin{pmatrix} 1 & 2 & 1 \\ 0 & 1 & -1 \\ 0 & 0 & 1 \end{pmatrix}.

When AA is symmetric and has an LU factorization, U′=LTU' = L^T, so A=LDLTA = LDL^T. For a symmetric matrix with all pivots positive this becomes the Cholesky factorization A=(LD1/2)(LD1/2)TA = (LD^{1/2})(LD^{1/2})^T, which costs about half as much as LU.

Uniqueness

Theorem. If AA is invertible and A=L1U1=L2U2A = L_1U_1 = L_2U_2 with L1,L2L_1, L_2 unit lower triangular and U1,U2U_1, U_2 upper triangular, then L1=L2L_1 = L_2 and U1=U2U_1 = U_2.

Proof. Since AA is invertible, so are the UiU_i (and the unit-diagonal LiL_i always are). From L1U1=L2U2L_1U_1 = L_2U_2,

L2−1L1=U2U1−1.L_2^{-1}L_1 = U_2U_1^{-1}.

The left side is unit lower triangular (inverses and products of unit lower triangular matrices are unit lower triangular — Chapter 2 and Exercise 5), and the right side is upper triangular. A matrix that is both is diagonal, and its diagonal is all 1s from the left side. So both sides equal II, which gives L1=L2L_1 = L_2 and U1=U2U_1 = U_2. ■\blacksquare

Row exchanges: PA = LU

Elimination breaks down when a zero appears in a pivot position. Example:

A=(011121279).A = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 2 & 1 \\ 2 & 7 & 9 \end{pmatrix}.

The (1,1) entry is 0, so swap rows 1 and 2 first. If all the exchanges are done at the start, they form one permutation matrix PP, and PAPA factors without further trouble:

P=(010100001),PA=(121011279)=(100010231)(121011004).P = \begin{pmatrix} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix}, \qquad PA = \begin{pmatrix} 1 & 2 & 1 \\ 0 & 1 & 1 \\ 2 & 7 & 9 \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 2 & 3 & 1 \end{pmatrix} \begin{pmatrix} 1 & 2 & 1 \\ 0 & 1 & 1 \\ 0 & 0 & 4 \end{pmatrix}.

The multipliers were ℓ21=0\ell_{21} = 0, ℓ31=2\ell_{31} = 2 (row 3 becomes (0,3,7)(0, 3, 7)), then ℓ32=3\ell_{32} = 3 (row 3 becomes (0,0,4)(0, 0, 4)).

Theorem. For every invertible AA there is a permutation matrix PP such that PA=LUPA = LU with LL unit lower triangular and UU upper triangular with nonzero pivots. An invertible AA has an LU factorization with no exchanges (P=IP = I) exactly when every leading principal submatrix (the top-left k×kk \times k block, k=1,…,nk = 1, \dots, n) is invertible.

To solve Ax=bA\mathbf{x} = \mathbf{b} from PA=LUPA = LU: LUx=PbLU\mathbf{x} = P\mathbf{b}, so permute b\mathbf{b}, then do the two triangular solves.

Common pitfall: after factoring PA=LUPA = LU, forgetting to apply PP to b\mathbf{b}. The factorization is of PAPA, not of AA.


Chapter 8 — Cost, and why not to compute the inverse

Counting flops

A flop is one floating-point add, subtract, multiply or divide. At elimination step kk of an n×nn \times n matrix, each of the n−kn - k rows below the pivot needs one division (its multiplier) and a multiply and a subtract for each of the remaining n−kn - k entries. So step kk costs (n−k)(2(n−k)+1)(n - k)\bigl(2(n - k) + 1\bigr) flops, and in total

∑k=1n(2(n−k)2+(n−k))=23n3−12n2−16n≈23n3.\sum_{k=1}^{n} \bigl( 2(n-k)^2 + (n-k) \bigr) = \frac{2}{3}n^3 - \frac12 n^2 - \frac16 n \approx \frac23 n^3.

Each triangular solve costs about n2n^2 flops. So for n=1000n = 1000: roughly 6.7×1086.7 \times 10^8 flops to factor, then only about 2×1062 \times 10^6 per right-hand side.

Why solving with the inverse is the wrong way

  1. Speed. Forming A−1A^{-1} costs about 2n32n^3 flops — roughly three times the LU factorization — and then A−1bA^{-1}\mathbf{b} still costs 2n22n^2, the same as the two triangular solves it was supposed to replace. There is nothing to gain even with many right-hand sides, because LU is reusable too.
  2. Accuracy. Gaussian elimination with partial pivoting is backward stable in practice: the computed x\mathbf{x} exactly solves a system with a very slightly perturbed AA. Multiplying by a computed inverse does not have this guarantee in general, and its residual ∥b−Ax∥\lVert \mathbf{b} - A\mathbf{x} \rVert is typically larger (Higham, Chapters 9 and 14).
  3. Structure. A banded or sparse matrix has banded or sparse LU factors (without pivoting, a tridiagonal KK has bidiagonal LL and UU), but its inverse is usually full — as K−1K^{-1} in Chapter 5 showed. For large sparse problems the inverse may not even fit in memory.

In code this means numpy.linalg.solve(A, b) (which calls LAPACK's LU-based gesv), or scipy.linalg.lu_factor once and lu_solve for each right-hand side — never inv(A) @ b.

Trick: read A−1bA^{-1}\mathbf{b} in a formula as "the solution of Ax=bA\mathbf{x} = \mathbf{b}", not as an instruction to invert. The same holds for expressions like A−1BA^{-1}B (solve with many right-hand sides) and cTA−1b\mathbf{c}^TA^{-1}\mathbf{b} (one solve, then one dot product).


Practice Exercises

Exercise 1 — Order matters

Let A=(1021)A = \begin{pmatrix} 1 & 0 \\ 2 & 1 \end{pmatrix} and B=(3102)B = \begin{pmatrix} 3 & 1 \\ 0 & 2 \end{pmatrix}. Compute ABAB and BABA. Describe ABAB with the row view.

Solution

AB=(3164)AB = \begin{pmatrix} 3 & 1 \\ 6 & 4 \end{pmatrix} and BA=(5142)BA = \begin{pmatrix} 5 & 1 \\ 4 & 2 \end{pmatrix}, which differ. Row view: AA is an elementary matrix ("add 2 times row 1 to row 2"), so ABAB is BB with row 2 replaced by (0,2)+2(3,1)=(6,4)(0,2) + 2(3,1) = (6, 4).

Exercise 2 — Transpose of a triple product

Prove (ABC)T=CTBTAT(ABC)^T = C^TB^TA^T, and deduce that BTABB^TAB is symmetric whenever AA is symmetric.

Solution

(ABC)T=((AB)C)T=CT(AB)T=CTBTAT(ABC)^T = ((AB)C)^T = C^T(AB)^T = C^TB^TA^T. If AT=AA^T = A, then (BTAB)T=BTAT(BT)T=BTAB(B^TAB)^T = B^TA^T(B^T)^T = B^TAB.

Exercise 3 — Inverses

Find the inverse of (2513)\begin{pmatrix} 2 & 5 \\ 1 & 3 \end{pmatrix} with the 2×22 \times 2 formula, and of (123014560)\begin{pmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{pmatrix} by Gauss–Jordan.

Solution

ad−bc=6−5=1ad - bc = 6 - 5 = 1, so the first inverse is (3−5−12)\begin{pmatrix} 3 & -5 \\ -1 & 2 \end{pmatrix}.

For the 3×33 \times 3 matrix, row reducing [ A∣I ][\,A \mid I\,] gives

A−1=(−2418520−15−4−541).A^{-1} = \begin{pmatrix} -24 & 18 & 5 \\ 20 & -15 & -4 \\ -5 & 4 & 1 \end{pmatrix}.

Check one entry of AA−1AA^{-1}: row 3 of AA times column 1 of A−1A^{-1} is 5(−24)+6(20)+0=05(-24) + 6(20) + 0 = 0, as it should be.

Exercise 4 — LU by hand

Factor A=(2114−60−272)A = \begin{pmatrix} 2 & 1 & 1 \\ 4 & -6 & 0 \\ -2 & 7 & 2 \end{pmatrix} as LULU.

Solution

ℓ21=4/2=2\ell_{21} = 4/2 = 2 and ℓ31=−2/2=−1\ell_{31} = -2/2 = -1 give rows (0,−8,−2)(0, -8, -2) and (0,8,3)(0, 8, 3). Then ℓ32=8/(−8)=−1\ell_{32} = 8/(-8) = -1 gives row 3 =(0,0,1)= (0, 0, 1). So

L=(100210−1−11),U=(2110−8−2001).L = \begin{pmatrix} 1 & 0 & 0 \\ 2 & 1 & 0 \\ -1 & -1 & 1 \end{pmatrix}, \qquad U = \begin{pmatrix} 2 & 1 & 1 \\ 0 & -8 & -2 \\ 0 & 0 & 1 \end{pmatrix}.

Pivots 2,−8,12, -8, 1.

Exercise 5 — Inverse of a unit lower triangular matrix

Show that the inverse of a unit lower triangular matrix is unit lower triangular (this completes the uniqueness proof in Chapter 7).

Solution

A unit lower triangular LL reduces to II using only operations "row ii minus a multiple of row jj" with i>ji > j (no swaps, no scaling, since the pivots are already 1). Each such elementary matrix is unit lower triangular, so L−1L^{-1}, the product of these elementary matrices, is unit lower triangular by the Chapter 2 result.

Exercise 6 — A zero pivot that cannot be fixed

Show that if ad−bc=0ad - bc = 0 then A=(abcd)A = \begin{pmatrix} a & b \\ c & d \end{pmatrix} is singular. Also show that (0111)\begin{pmatrix} 0 & 1 \\ 1 & 1 \end{pmatrix} is invertible but has no LU factorization without a row exchange.

Solution

If A=0A = 0 it is singular. Otherwise M=(d−b−ca)≠0M = \begin{pmatrix} d & -b \\ -c & a \end{pmatrix} \neq 0 and AM=0AM = 0. If AA were invertible, M=A−1AM=0M = A^{-1}AM = 0, a contradiction.

For the second matrix, ad−bc=−1≠0ad - bc = -1 \neq 0, so it is invertible. If (0111)=(10ℓ1)(u11u120u22)\begin{pmatrix} 0 & 1 \\ 1 & 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ \ell & 1 \end{pmatrix}\begin{pmatrix} u_{11} & u_{12} \\ 0 & u_{22} \end{pmatrix}, the (1,1) entry forces u11=0u_{11} = 0, but then the (2,1) entry is ℓu11=0≠1\ell u_{11} = 0 \neq 1. Its first leading principal submatrix (0)(0) is singular, as the theorem predicts. With the swap, PA=(1101)=I⋅UPA = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix} = I \cdot U.

Exercise 7 — Symmetric inverse

Prove: if AA is symmetric and invertible, then A−1A^{-1} is symmetric.

Solution

(A−1)T=(AT)−1=A−1(A^{-1})^T = (A^T)^{-1} = A^{-1}, using the transpose rule for inverses from Chapter 5 and AT=AA^T = A.


Cheat-sheet

Topic Key fact
Product size (m×n)(n×p)=m×p(m \times n)(n \times p) = m \times p
Four views of ABAB entries, columns AbjA\mathbf{b}_j, rows, sum of outer products
Fails for matrices AB=BAAB = BA, cancellation, "no zero divisors"
Transpose (AB)T=BTAT(AB)^T = B^TA^T; ATAA^TA is symmetric
Block product same formula as scalars, order kept
Schur complement D−CA−1BD - CA^{-1}B
Elementary matrix row operation on II; multiply on the left
2×22 \times 2 inverse swap a,da, d; negate b,cb, c; divide by ad−bc≠0ad - bc \neq 0
Inverse rules (AB)−1=B−1A−1(AB)^{-1} = B^{-1}A^{-1}, (AT)−1=(A−1)T(A^T)^{-1} = (A^{-1})^T
Compute A−1A^{-1} Gauss–Jordan on [ A∣I ][\,A \mid I\,]
Square, AB=IAB = I then BA=IBA = I
A=LUA = LU LL unit lower with multipliers; UU upper with pivots
Row exchanges PA=LUPA = LU; solve LUx=PbLU\mathbf{x} = P\mathbf{b}
LU cost ≈23n3\approx \tfrac23 n^3 flops; each triangular solve ≈n2\approx n^2
Solve, do not invert solve(A, b) or lu_factor + lu_solve

What's next

Linear Algebra 02 steps back from matrices to the structures they act on. It defines a vector space by axioms (so polynomials, functions and matrices count), then subspaces, span, independence, basis and dimension — with a full proof that dimension is well defined (the Steinitz exchange lemma). It then studies the four fundamental subspaces of a matrix, proves that row rank equals column rank, and proves rank–nullity in matrix form.


References

  • Gilbert Strang, Introduction to Linear Algebra, 6th edition, Wellesley-Cambridge Press, 2023 — Chapter 2 (elimination matrices, inverses, A=LUA = LU, transposes and permutations).
  • David C. Lay, Steven R. Lay and Judi J. McDonald, Linear Algebra and Its Applications, 6th edition, Pearson, 2021 — Chapter 2 (matrix operations, the invertible matrix theorem, partitioned matrices, LU).
  • Lloyd N. Trefethen and David Bau III, Numerical Linear Algebra, SIAM, 1997 — Lectures 20–21 (Gaussian elimination, operation count, pivoting).
  • Gene H. Golub and Charles F. Van Loan, Matrix Computations, 4th edition, Johns Hopkins University Press, 2013 — Chapter 3 (LU and its variants).
  • Nicholas J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd edition, SIAM, 2002 — Chapter 9 (LU factorization and linear equations) and Chapter 14 (matrix inversion).
  • MIT OpenCourseWare, 18.06 Linear Algebra, Spring 2010 (Gilbert Strang) — Lectures 3–5: multiplication and inverses, A=LUA = LU, transposes and permutations.

Note: this post is in progress. Planned additions: a proof of the leading-principal-submatrix condition for LU without exchanges, a worked partial-pivoting example in three-digit arithmetic, and a short numerical demo comparing solve with inv(A) @ b on an ill-conditioned matrix.