Session 02 · Unit 1

Elimination with Matrices


How systems of equations actually get solved — not by determinants, but by elimination, the method inside every software package. A 3x3 system is reduced to triangular form, back substitution finishes it off, and then the real point of the lecture lands. Every elimination step is a matrix multiplication, each step is an elementary matrix E, and undoing a step gives the first glimpse of an inverse.

Solving Ax = b the way software does

The method of solution will not be determinants — those come later. The method is elimination, “the way every software package solves equations.” Gauss thought of it before we did, Strang notes, “but only because he was born earlier.” If the matrix AA is a good one, elimination succeeds and gets the answer efficiently. And as long as we’re watching it work, it’s always good to ask: how could it fail? Elimination itself will decide whether the matrix is good or has problems.

The example for the whole lecture is three equations in three unknowns:

x+2y+z=23x+8y+z=124y+z=2A=[121381041],b=[2122]\begin{aligned} x + 2y + z &= 2 \\ 3x + 8y + z &= 12 \\ 4y + z &= 2 \end{aligned} \qquad A = \begin{bmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{bmatrix}, \quad \mathbf{b} = \begin{bmatrix} 2 \\ 12 \\ 2 \end{bmatrix}

Writing the equal signs and pluses over and over gets to be a pain — “it’s that matrix that totally matters. Everything is in that matrix.” So elimination works on AA directly.

But the deeper agenda is the second half of the lecture: expressing elimination in matrix language. All the key ideas of the course get expressed as matrix operations, not as words.

Forward elimination: from A to U

Accept the first equation as it is. Its leading coefficient is the key number:

Step (2,1): the first pivot is the 11 in position (1,1)(1,1). To knock out the 33 below it, the multiplier is 33: subtract 3×3 \times row one from row two. Three 22s away from the 88 leaves 22; three 11s away from 11 leaves 2-2. Row three has a 00 in column one already, so the (3,1)(3,1) step has multiplier 00 — nothing to do (though MATLAB would still look at that entry unless told in advance it was zero):

[121381041]    [121022041]\begin{bmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{bmatrix} \;\longrightarrow\; \begin{bmatrix} \boxed{1} & 2 & 1 \\ 0 & \boxed{2} & -2 \\ 0 & 4 & 1 \end{bmatrix}

With xx eliminated, we’re down to two equations in yy and zz, and “everything’s recursive” — just do it again. Step (3,2): the second pivot is the 22, the multiplier is 22. Subtract 2×2 \times row two from row three: 42(2)=04 - 2(2) = 0, and 12(2)=51 - 2(-2) = 5.

U=[121022005]U = \begin{bmatrix} \boxed{1} & 2 & 1 \\ 0 & \boxed{2} & -2 \\ 0 & 0 & \boxed{5} \end{bmatrix}

This matrix is UUU for upper triangular — and the whole purpose of elimination was to get from AA to UU. “Literally, that’s the most common calculation in scientific computing.” Three nonzero pivots appeared, 1,2,51, 2, 5, with no special maneuvers, so this matrix is great — invertible. And anticipating a later day: the determinant, which we never actually want, is just the product of the pivots, 125=101 \cdot 2 \cdot 5 = 10.

Step through the whole computation yourself — the same matrix, one elimination move at a time, pivots boxed and changed entries highlighted:

Try it — elimination, one move at a time

How elimination fails

By fail, Strang means: fail to come up with three pivots. Run the example again with unlucky numbers.

  • Trouble at the start. If the (1,1)(1,1) entry had been 00, there’d be no first pivot in place. Do we quit? No — exchange rows with a lower equation that has a nonzero there. Strang refuses the phrase “zero pivot”: there may be a 00 in the pivot position, but a pivot is never zero.
  • Temporary failure. If the 88 had been a 66, the second row after step one would read 0  0  20 \; 0 \; -2 — a 00 where the second pivot should be. But there’s a 44 below it, so a row exchange rescues us. You can get out of trouble whenever there’s a nonzero below the troublesome zero.
  • Complete failure. What entry in the (3,3)(3,3) spot would be unfixable? The 11 became a 55 because elimination added 44 to it. If that 11 had been 4-4, the same steps would produce a 00 in the third pivot position at the last minute — with nothing below it to exchange. No third pivot. The matrix would not be invertible.

So elimination itself is the test: temporary failure means a row exchange; complete failure — a zero in the pivot position with nothing below — means a singular matrix.

Back substitution: the augmented matrix

Now the right-hand side, which has been patiently waiting. (MATLAB actually finishes the left side first, then goes back for the right.) Tack b\mathbf{b} on as an extra column:

[1212381120412][121202260412][1212022600510]\left[\begin{array}{ccc|c} 1 & 2 & 1 & 2 \\ 3 & 8 & 1 & 12 \\ 0 & 4 & 1 & 2 \end{array}\right] \longrightarrow \left[\begin{array}{ccc|c} 1 & 2 & 1 & 2 \\ 0 & 2 & -2 & 6 \\ 0 & 4 & 1 & 2 \end{array}\right] \longrightarrow \left[\begin{array}{ccc|c} 1 & 2 & 1 & 2 \\ 0 & 2 & -2 & 6 \\ 0 & 0 & 5 & -10 \end{array}\right]

Step one: three 22s taken from 1212 leaves 66. Step two: two 66s taken from 22 leaves 10-10. Call the final column c\mathbf{c}, “once and forever”: c\mathbf{c} is what happens to b\mathbf{b}, just as UU is what happens to AA. The system is now Ux=cU\mathbf{x} = \mathbf{c}:

x+2y+z=22y2z=65z=10\begin{aligned} x + 2y + z &= 2 \\ 2y - 2z &= 6 \\ 5z &= -10 \end{aligned}

Back substitution solves these in reverse order, because the system is triangular. From the last equation, z=2z = -2. Go back upwards: 2y2(2)=62y - 2(-2) = 6 gives 2y+4=62y + 4 = 6, so y=1y = 1. Then x+2(1)+(2)=2x + 2(1) + (-2) = 2 gives x=2x = 2. That’s the whole solve: forward elimination, then the easy triangular sweep.

Matrices that act on rows

Now the second piece of the lecture: express those elimination operations as matrices. First, a point Strang singles out as especially important. Last time, the big picture was columns: a matrix times a vector is a combination of the columns —

[        A        ][345]=3(column 1)+4(column 2)+5(column 3)\begin{bmatrix} \; & \; & \; \\ \; & A & \; \\ \; & \; & \; \end{bmatrix} \begin{bmatrix} 3 \\ 4 \\ 5 \end{bmatrix} = 3(\text{column 1}) + 4(\text{column 2}) + 5(\text{column 3})

But elimination is row operations, so we need the parallel fact for rows.

Elimination matrices: E₂₁ and E₃₂

So: what matrix subtracts 3×3 \times row one from row two and leaves the other rows alone? Build it row by row. The first row of the answer should be one of row one and nothing else: 1  0  01\; 0\; 0. The last row: 0  0  10\; 0\; 1. (If the middle row were 0  1  00\; 1\; 0 we’d have the identity matrix II, which does absolutely nothing — “it’s like a one, like the number one, for matrices.”) But we want 3-3 of row one plus 11 of row two:

E21=[100310001],E21[121381041]=[121022041]E_{21} = \begin{bmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}, \qquad E_{21}\begin{bmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 2 & 1 \\ 0 & 2 & -2 \\ 0 & 4 & 1 \end{bmatrix}

This is an elementary matrix (or elimination matrix), “E for elementary,” indexed 2,12,1 because it fixes the (2,1)(2,1) position. Check one entry the entry-at-a-time way: the (2,3)(2,3) entry of the product is row two of E21E_{21} dotted with column three of AA(3)(1)+(1)(1)+(0)(1)=2(-3)(1) + (1)(1) + (0)(1) = -2. It works.

The second step subtracted 2×2 \times row two from row three, so its matrix is II with 2-2 — minus the multiplier — sitting in the (3,2)(3,2) position:

E32=[100010021],E32(E21A)=UE_{32} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -2 & 1 \end{bmatrix}, \qquad E_{32}\,(E_{21} A) = U

That one line is the whole lecture — “you see why I like matrix notation.”

Permutations, and a first look at inverses

One more type of elementary matrix, the one row exchanges need: a permutation matrix. To exchange the rows of [abcd]\begin{bmatrix} a & b \\ c & d \end{bmatrix}, exchange the rows of the identity and multiply on the left:

P=[0110],[0110][abcd]=[cdab]P = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}, \qquad \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} a & b \\ c & d \end{bmatrix} = \begin{bmatrix} c & d \\ a & b \end{bmatrix}

Could a matrix on the left exchange the columns? No — multiplying on the left does row operations. To exchange columns, put the permutation on the right: [abcd][0110]=[badc]\begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} = \begin{bmatrix} b & a \\ d & c \end{bmatrix}, one column at a time. In short: column operations multiply on the right, row operations on the left — and elimination is row operations.

Rather than multiplying out E32E21E_{32}E_{21}, Strang closes with the better way, “a little jump on what’s coming on Monday”: think not how to get from AA to UU, but how to get from UU back to AA. What matrix undoes E21E_{21}? In words first: if the step subtracted 3×3 \times row one from row two, the inverse step adds it back:

E1E=[100310001][100310001]=[100010001]=IE^{-1}E = \begin{bmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} = I

The matrix that multiplies EE to give the identity is the inverse, written E1E^{-1}. Every matrix on the board today has one — “I didn’t write any bad matrices down.”

Problems

Elimination by hand, then elimination as matrices — everything comes from the lecture’s example.

Problem 2.1 Elimination and back substitution

Solve by elimination and back substitution, keeping the right-hand side along as an augmented column:

x+3y+z=52x+7y+5z=162y+6z=10\begin{aligned} x + 3y + z &= 5 \\ 2x + 7y + 5z &= 16 \\ 2y + 6z &= 10 \end{aligned}

Box the three pivots.

Show solution

Augmented matrix, then step (2,1)(2,1) with multiplier 22, then step (3,2)(3,2) with multiplier 22:

[13152751602610][1315013602610][131501360002]\left[\begin{array}{ccc|c} 1 & 3 & 1 & 5 \\ 2 & 7 & 5 & 16 \\ 0 & 2 & 6 & 10 \end{array}\right] \longrightarrow \left[\begin{array}{ccc|c} 1 & 3 & 1 & 5 \\ 0 & 1 & 3 & 6 \\ 0 & 2 & 6 & 10 \end{array}\right] \longrightarrow \left[\begin{array}{ccc|c} \boxed{1} & 3 & 1 & 5 \\ 0 & \boxed{1} & 3 & 6 \\ 0 & 0 & \boxed{0} & -2 \end{array}\right]

Trouble! The third pivot position is 00 with nothing below — and the equation reads 0z=20z = -2, which is impossible. This system has no solution: elimination exposed a singular case. (If the last right-hand entry had been 1212 instead of 1010, we’d get 0=00 = 0 and infinitely many solutions — but that story comes later. The point here: elimination itself delivers the verdict.)

Problem 2.2 Which entry causes failure?

For the matrix

A=[12138104c]A = \begin{bmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & c \end{bmatrix}

(the lecture’s matrix with the corner entry replaced by cc), which value of cc produces complete failure — no third pivot and no rescue by row exchange? For that cc, write out UU.

Show solution

Elimination proceeds as in lecture: after the (2,1)(2,1) step with multiplier 33, rows are 1  2  11\;2\;1, 0  2  20\;2\;-2, 0  4  c0\;4\;c. The (3,2)(3,2) step subtracts 2×2 \times row two from row three: the corner becomes c2(2)=c+4c - 2(-2) = c + 4.

This is 00 when c=4c = -4 — exactly the number Strang identified. Then

U=[121022000]U = \begin{bmatrix} 1 & 2 & 1 \\ 0 & 2 & -2 \\ 0 & 0 & 0 \end{bmatrix}

Only two pivots, a 00 in the third pivot position, and no row below to exchange with: the matrix is not invertible.

Problem 2.3 Elimination as matrices

For the system in the lecture, with A=[121381041]A = \begin{bmatrix} 1 & 2 & 1 \\ 3 & 8 & 1 \\ 0 & 4 & 1 \end{bmatrix}, multiply out E=E32E21E = E_{32}E_{21} — the single matrix that does all of elimination in one shot. Verify that EA=UEA = U.

Show solution
E=E32E21=[100010021][100310001]=[100310621]E = E_{32}E_{21} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -2 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 6 & -2 & 1 \end{bmatrix}

(Row three of EE is 2-2 of row two of E21E_{21} plus 11 of row three: 2(3,1,0)+(0,0,1)=(6,2,1)-2(-3, 1, 0) + (0, 0, 1) = (6, -2, 1).)

Check EAEA row by row: row one of EAEA is row one of AA: 1  2  11\;2\;1. Row two is 3(row 1)+(row 2)=0  2  2-3(\text{row 1}) + (\text{row 2}) = 0\;2\;-2. Row three is 6(row 1)2(row 2)+(row 3)=(66+0,  1216+4,  62+1)=0  0  56(\text{row 1}) - 2(\text{row 2}) + (\text{row 3}) = (6 - 6 + 0,\; 12 - 16 + 4,\; 6 - 2 + 1) = 0\;0\;5. So EA=UEA = U with pivots 1,2,51, 2, 5. By the associative law, (E32E21)A=E32(E21A)(E_{32}E_{21})A = E_{32}(E_{21}A) — the same UU either way.

Problem 2.4 Left vs right multiplication

Let P=[0110]P = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} and B=[1429]B = \begin{bmatrix} 1 & 4 \\ 2 & 9 \end{bmatrix}. Compute PBPB and BPBP. Which one exchanges rows and which exchanges columns? Is PB=BPPB = BP?

Show solution
PB=[0110][1429]=[2914],BP=[1429][0110]=[4192]PB = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 1 & 4 \\ 2 & 9 \end{bmatrix} = \begin{bmatrix} 2 & 9 \\ 1 & 4 \end{bmatrix}, \qquad BP = \begin{bmatrix} 1 & 4 \\ 2 & 9 \end{bmatrix}\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} = \begin{bmatrix} 4 & 1 \\ 9 & 2 \end{bmatrix}

PP on the left does a row operation — it exchanges the rows of BB. PP on the right does a column operation — it exchanges the columns. And PBBPPB \neq BP: a concrete reminder that the commutative law is false for matrices.

Problem 2.5 Undoing a step

Write the elementary matrix EE that subtracts 55 times row one from row three of a 3×3 matrix. Then write E1E^{-1}, say in words what it does, and verify E1E=IE^{-1}E = I.

Show solution
E=[100010501],E1=[100010501]E = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ -5 & 0 & 1 \end{bmatrix}, \qquad E^{-1} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 5 & 0 & 1 \end{bmatrix}

In words: what EE subtracted away, E1E^{-1} adds back — it adds 55 times row one to row three. Check the product row by row: rows one and two of E1EE^{-1}E are rows one and two of EE, i.e. 1  0  01\;0\;0 and 0  1  00\;1\;0. Row three is 5(row 1 of E)+(row 3 of E)=(5,0,0)+(5,0,1)=(0,0,1)5(\text{row 1 of } E) + (\text{row 3 of } E) = (5, 0, 0) + (-5, 0, 1) = (0, 0, 1). So

E1E=[100010001]=IE^{-1}E = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} = I