Hyoungseo Son
Linear Algebra
Contents · Linear Algebra

Part 1 · Vectors & Spaces

Part 3 · Solving Systems

  • Solving Ax = b: Gaussian Elimination and LU

Part 4 · Orthogonality

Part 5 · Eigenvalues

Part 6 · Singular Value Decomposition

Part 3 · Solving Systems

Solving Ax = b: Gaussian Elimination and LU

7 min read

Almost every linear-algebra question that starts with a matrix ends up solving Ax=bA\mathbf{x} = \mathbf{b}. The method is Gaussian elimination: use row operations to turn AA into an upper-triangular matrix UU, then read off the unknowns by back-substitution. The multipliers you use along the way are not waste, they assemble into a lower-triangular LL, so the same work also produces the factorization A=LUA = LU.

Elimination reduces AA to UU

An elementary row operation adds a multiple of one row to another; it never changes the solution set. Work down the columns. At column jj the pivot is the diagonal entry ajja_{jj}, and for each row ii below it we subtract the pivot row scaled by the multiplier

ij=aijajj,RiRiijRj.\ell_{ij} = \frac{a_{ij}}{a_{jj}}, \qquad R_i \leftarrow R_i - \ell_{ij}\,R_j .

That choice of ij\ell_{ij} is exactly what drives the entry under the pivot to zero. After clearing every entry below every pivot, AA has become upper triangular:

A    U=[u11u12u1n0u22u2n00unn].A \;\longrightarrow\; U = \begin{bmatrix} u_{11} & u_{12} & \cdots & u_{1n} \\ 0 & u_{22} & \cdots & u_{2n} \\ \vdots & & \ddots & \vdots \\ 0 & 0 & \cdots & u_{nn} \end{bmatrix}.

Applying the same operations to b\mathbf{b} turns the system into Ux=cU\mathbf{x} = \mathbf{c}, which a triangular matrix solves from the bottom up:

xn=cnunn,xi=1uii(cik>iuikxk).x_n = \frac{c_n}{u_{nn}}, \qquad x_i = \frac{1}{u_{ii}}\Big(c_i - \sum_{k>i} u_{ik}\,x_k\Big).

A worked 3×33\times 3

Take the system with

A=[211312212],b=[8113],A = \begin{bmatrix} 2 & 1 & -1 \\ -3 & -1 & 2 \\ -2 & 1 & 2 \end{bmatrix}, \qquad \mathbf{b} = \begin{bmatrix} 8 \\ -11 \\ -3 \end{bmatrix},

so the augmented matrix is

[Ab]=[2118312112123].[\,A \mid \mathbf{b}\,] = \left[\begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ -3 & -1 & 2 & -11 \\ -2 & 1 & 2 & -3 \end{array}\right].

Column 1. The pivot is 22. For row 22 the multiplier is 21=3/2\ell_{21} = -3/2, so R2R221R1=R2+32R1R_2 \leftarrow R_2 - \ell_{21} R_1 = R_2 + \tfrac{3}{2}R_1. For row 33, 31=1\ell_{31} = -1, so R3R3+R1R_3 \leftarrow R_3 + R_1:

[21180121210215].\left[\begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ 0 & \tfrac{1}{2} & \tfrac{1}{2} & 1 \\ 0 & 2 & 1 & 5 \end{array}\right].

Column 2. The new pivot is 12\tfrac{1}{2}. For row 33 the multiplier is 32=2/12=4\ell_{32} = 2 / \tfrac{1}{2} = 4, so R3R34R2R_3 \leftarrow R_3 - 4R_2, which reaches UU:

[21180121210011].\left[\begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ 0 & \tfrac{1}{2} & \tfrac{1}{2} & 1 \\ 0 & 0 & -1 & 1 \end{array}\right].

Back-substitution. From the bottom row up,

x3=11=1,x2=112(1)12=3,x1=8(1)(3)(1)(1)2=2,x_3 = \frac{1}{-1} = -1, \qquad x_2 = \frac{1 - \tfrac{1}{2}(-1)}{\tfrac{1}{2}} = 3, \qquad x_1 = \frac{8 - (1)(3) - (-1)(-1)}{2} = 2,

giving x=(2,3,1)\mathbf{x} = (2, 3, -1). Step through the same numbers below: each Step performs one row operation and shows the resulting matrix, then the Solve steps run back-substitution.

Gaussian elimination on a 3×3interactive
x1x2x3b
2.001.00-1.008.00
-3.00-1.002.00-11.00
-2.001.002.00-3.00
x =x1 = ?x2 = ?x3 = ?
forward elimination ← here
back-substitution
solved
press Step
Step through the elimination to see the numbers.
Forward elimination drives the entries below each pivot (highlighted) to zero, producing an upper-triangular matrix. Then back-substitution reads off x from the bottom row up. Solution: x = (2, 3, -1).

Elimination is LULU factorization

Collect the multipliers used above into a unit lower-triangular matrix, placing ij\ell_{ij} in position (i,j)(i,j). That matrix is LL, and together with UU it reconstructs AA:

L=[1003210141],U=[21101212001],A=LU.L = \begin{bmatrix} 1 & 0 & 0 \\ -\tfrac{3}{2} & 1 & 0 \\ -1 & 4 & 1 \end{bmatrix}, \qquad U = \begin{bmatrix} 2 & 1 & -1 \\ 0 & \tfrac{1}{2} & \tfrac{1}{2} \\ 0 & 0 & -1 \end{bmatrix}, \qquad A = LU .

The reason LL works out this way is that each elimination step is left multiplication by a matrix that differs from the identity in a single entry, and the inverse of such a matrix just flips the sign of that entry. Multiplying those inverses back together stacks the multipliers directly into LL.1

The factorization is where the payoff sits. Once A=LUA = LU is known, solving Ax=bA\mathbf{x} = \mathbf{b} splits into two triangular solves:

Ly=b(forward),Ux=y(back).L\mathbf{y} = \mathbf{b} \quad (\text{forward}), \qquad U\mathbf{x} = \mathbf{y} \quad (\text{back}).

For this system the forward solve gives y=(8,1,1)\mathbf{y} = (8, 1, 1), which is exactly the transformed right-hand side from the elimination above. A second right-hand side then costs only the two triangular solves, not another elimination.

Pivots, exchanges, and cost

The whole scheme rests on nonzero pivots. If a pivot comes out zero, you cannot divide by it, and you swap in a row below that has a nonzero entry in that column: an exchange, recorded by a permutation matrix PP, so the factorization becomes PA=LUPA = LU.2 In floating point the same idea, partial pivoting, chooses the largest available pivot to keep multipliers bounded and the solve stable. If no row supplies a nonzero pivot, that column is dependent and AA is singular, so Ax=bA\mathbf{x} = \mathbf{b} has either no solution or infinitely many.

The cost is dominated by the forward elimination. Clearing column jj touches an (nj)×(nj)(n-j)\times(n-j) block, and summing those blocks gives about 23n3\tfrac{2}{3}n^{3} floating-point operations.2 Each triangular solve is only O(n2)O(n^{2}), which is why factoring once and reusing LL and UU is the right move when several right-hand sides share the same AA.

Footnotes

  1. Strang, Introduction to Linear Algebra (5th ed., 2016).

  2. Trefethen & Bau, Numerical Linear Algebra (1997). 2