Every row operation is multiplication by an elementary matrix, so row-reducing A to I builds A⁻¹ along the way.
On Day 3 you used three row operations to solve systems, and yesterday you met A−1, the matrix that undoes A. Yesterday's formula only works for 2×2 matrices, so today asks how to find the inverse of a matrix of any size. The answer connects those two ideas: each row operation is itself a matrix, and running row reduction on A and I side by side computes A−1.
Each section below opens with a problem. Try it before you open the walkthrough, even if you only get partway. You will need Day 6's row rule, rowi(EA)=rowi(E)A, more than once.
Elementary matrices
Start with the identity I=[1001] and do the row operation "subtract 2 times row 1 from row 2". Call the result E. Then compute EA for A=[1237] and enter it row by row. How does it compare with doing the same row operation to A directly?
Walk through the solutionHide the walkthrough
Row 1 of I stays (1,0). Row 2 becomes (0,1)−2(1,0)=(−2,1). So
E=[1−201].
To compute EA we use Day 6's row rule, which says each row of EA is a row of E times A. A row times A is a combination of the rows of A, with the row's entries as weights.
1
Row 1 of E is (1,0), so row 1 of EA is 1⋅(1,3)+0⋅(2,7)=(1,3). Row 1 of A is unchanged.
2
Row 2 of E is (−2,1), so row 2 of EA is −2⋅(1,3)+1⋅(2,7)=(−2+2,−6+7)=(0,1).
3
So EA=[1031]. Doing "subtract 2 times row 1 from row 2" to A directly gives the same matrix.
Row 2 of E is a recipe that says "take −2 of row 1 and 1 of row 2". Multiplying by E follows that recipe on whatever matrix sits to its right.
Elementary matrix
An elementary matrix is a matrix you get by doing one elementary row operation to an identity matrix. There is one kind for each row operation: replacement, interchange and scaling.
If you do a row operation to an m×n matrix A, the result is EA, where E is the m×m elementary matrix made by doing the same operation to Im.
Writing a row operation as a matrix turns row reduction into ordinary matrix algebra. Day 9 uses that to factor A=LU, and Day 26 uses it to track how each row operation changes a determinant.
Try writing a recipe yourself. The picture draws each row of A=[1325] as an arrow, and row 2 of E says how much of each to mix.
The rows of A are drawn as arrows. Set row 2 of E so that row 2 of EA becomes the ringed row (0,−1).
Row 2 of E is (−3,1), which is the recipe R2←R2−3R1. The first entry of the new row is now zero.
E=[1001]
EA=[1325]
Which row operation does E=10−4010001 perform?
As a transformation of the plane, each 2×2 elementary matrix is a simple move. The widget shows the grid after E, and its columns are where ^ and ^ land.
Find a row operation whose matrix sends ^ to the ringed point (1,−2) and leaves ^ where it is.
That is E=[1002], the replacement R2←2R2. Its inverse adds the multiple back.
E=[1002]R2←2R2
E−1=[10021]R2←21R2
Scaling by 0 flattens the plane, and nothing can undo it, so it is not a row operation.
Undoing a row operation
Which row operation undoes "subtract 2 times row 1 from row 2"? Write its elementary matrix F, enter it row by row, and check that FE=I for the E of Problem 1.
Walk through the solutionHide the walkthrough
Subtracting 2R1 from row 2 is undone by adding 2R1 back. Doing "add 2 times row 1 to row 2" to I gives
F=[1201].
Now check with the row rule. Row 1 of FE is row 1 of E, which is (1,0). Row 2 of FE is 2⋅(1,0)+1⋅(−2,1)=(0,1). So FE=I, and in the same way EF=I. That makes F=E−1.
Every elementary matrix is invertible
Every row operation can be undone by another row operation of the same kind, so every elementary matrix has an inverse that is elementary too. You can write it down without any computation.
A replacement is undone by flipping the sign of the multiple: [1−201]−1=[1201].
A swap undoes itself.
Scaling a row by c is undone by scaling it by c1. That is why scaling by 0 is not a row operation.
What is the inverse of the elementary matrix for R3←R3−4R1?
Inverting by row reduction
On Day 3, row reduction aimed for reduced echelon form so you could read off the solution. For an invertible square matrix that form is I. Here the goal is to reduce A all the way to I while keeping a record of the steps, because their product turns out to be A−1.
Reduce A=[1237] to I with two row replacements. Write the elementary matrix for each step, and multiply them together, putting the later step on the left. Enter the product row by row.
Walk through the solutionHide the walkthrough
Problem 1 already did the first step. E1 is "subtract 2 times row 1 from row 2", and it turned A into [1031].
To finish, we clear the 3 above the second pivot. E2 is "subtract 3 times row 2 from row 1", which gives row 1 as (1,3)−3(0,1)=(1,0) and leaves I. Its matrix is I with that step done to it:
E1=[1−201],E2=[10−31].
E1 acts first, so the product is E2E1. By the row rule, row 1 is 1⋅(1,0)−3⋅(−2,1)=(7,−3), and row 2 is 0⋅(1,0)+1⋅(−2,1)=(−2,1):
E2E1=[7−2−31].
Day 7's formula gives A−1=7−61[7−2−31], the same matrix. The product of the steps that reduce A to I is A−1.
Theorem 7
An n×n matrix A is invertible if and only if it is row equivalent to In. In that case, any sequence of row operations that reduces A to In also turns In into A−1.
The reason is the same as in Problem 3. If Ep⋯E1A=I, multiplying both sides on the right by A−1 gives Ep⋯E1=A−1. To collect that product without multiplying matrices, write I next to A and do every operation to the whole row of [AI]. When the left half reaches I, the right half is Ep⋯E1I=A−1.
Here is the example from the video, with A=[2111]. Each step says which entry it is trying to fix.
1
We want a 1 in the top-left corner, and row 2 already starts with 1, so swap the rows (E1: R1↔R2).
[21111001]∼[12110110]
2
Clear the 2 below the pivot by subtracting 2 times row 1 from row 2 (E2). Row 2 becomes (2,1,1,0)−2(1,1,0,1)=(0,−1,1,−2).
∼[101−1011−2]
3
Turn the −1 into a pivot of 1 by scaling row 2 by −1 (E3).
∼[10110−112]
4
Clear the 1 above the second pivot by subtracting row 2 from row 1 (E4). Row 1 becomes (1,1,0,1)−(0,1,−1,2)=(1,0,1,−1).
∼[10011−1−12]
5
The left half is I, so the teal block is A−1. Check with one multiplication: [2111][1−1−12]=[2−11−1−2+2−1+2]=I.
Try it yourself on a different matrix. The slider sets the number c that the buttons use.
Use row operations to turn the left half into I. Each one acts on the whole row, so the right half changes too.
The left half is I, so the right half is A−1=[1001], the product of your elementary matrices.
[01211001]
Last step none yet
Right half =I
Products of elementary matrices
The reduction steps take A to I. Running them backwards, last one first, should take I back to A.
In Problem 3, E2E1A=I. Write A as a product of two elementary matrices, and check your answer by multiplying.
Walk through the solutionHide the walkthrough
We want A alone, so we remove E2 first, because it sits farthest to the left. Multiply both sides on the left by E2−1, then by E1−1:
E1A=E2−1⟹A=E1−1E2−1.
Each inverse flips the sign of its multiple, so
A=[1201][1031]=[1233⋅2+1]=[1237].
The order is the reverse of the reduction, with E1−1 on the left. It matches Day 7's socks and shoes rule.
Now do the same with the video's four steps. Each button applies one undo move to the grid.
Start from the square grid and apply the four undo moves, one at a time, so the green and red arrows land in the rings where the columns of A sit.
You rebuilt the grid of A, so A=E1−1E2−1E3−1E4−1. The last reduction step had to be undone first.
That order builds a different grid. Start over and undo the last reduction step first.
Invertible means a product of elementary matrices
If Ep⋯E1A=I, then A=E1−1E2−1⋯Ep−1, and every factor is elementary. In the other direction, a product of elementary matrices is always invertible, because each factor is. So A is invertible exactly when it is a product of elementary matrices. Geometrically, every invertible move of the plane is a chain of shears, swaps and stretches. Day 27 uses this fact to prove that det(AB)=(detA)(detB).
When there is no inverse
Try to row reduce [BI] for B=[1122]. What goes wrong?
Walk through the solutionHide the walkthrough
The natural first step clears the 1 below the first pivot by subtracting row 1 from row 2:
[11221001]∼[10201−101]
The left half now has a row of zeros. Every later row operation only mixes the rows (1,2) and (0,0), so every row it can produce is a multiple of (1,2). The row (0,1) of I is not such a multiple, so the left half can never become I. By Theorem 7, B has no inverse, and we can stop here. Its determinant 1⋅2−2⋅1=0 agrees.
A zero row on the left is the signal to stop. Geometrically, B flattens the plane onto a line, and no sequence of invertible moves can unflatten it.
One column of the inverse
Sometimes you need only part of A−1. Because AA−1=I, column j of A−1 is the vector that A sends to ej, which is exactly what Day 7 found with the pink columns.
For A=[1237], find the second column of A−1 by row reducing [Ae2].
Walk through the solutionHide the walkthrough
The second column solves Ax=e2=(0,1), so we row reduce A with only that one column beside it, using the same two steps as Problem 3:
[123701]∼[103101]∼[1001−31]
The second column of A−1 is (−3,1), which matches the second column of the A−1 found in Problem 3.
Tomorrow the same record of steps, stopped at an echelon form instead of at I, gives the factorization A=LU, which solves Ax=b quickly for many different b.
Practice
Warm-up
Write the 3×3 elementary matrix for R3←R3+5R1, row by row.
Show the solutionHide the solution
Do the operation to I3. Rows 1 and 2 stay the same, and row 3 becomes (0,0,1)+5(1,0,0)=(5,0,1):
105010001
Write the inverse of [10−61], row by row, without computing.
Show the solutionHide the solution
The matrix performs R1←R1−6R2. Its inverse puts the 6R2 back, R1←R1+6R2, which is [1061].
Which row operation does 001010100 perform?
Show the solutionHide the solution
Row i of E says which rows of A build row i of EA. Here row 1 of EA is row 3 of A, and row 3 of EA is row 1 of A.
Core
Find the inverse of A=[2153] by row reducing [AI], and enter it row by row. (Modeled on Lay §2.2 #29.)
Show a hintHide the hint
Swapping the rows first puts a 1 in the top-left corner and avoids fractions.
The first step used R2←R2−2R1 and then R3←R3+R2. The second used R2←R2+R3 and R1←R1−2R3. The third column is (−2,1,1). Check: A−211=−2+2−4+1+3−1+2=001.
Find the full inverse of the same A=12001−1232, row by row. (Modeled on Lay §2.2 #31.)
Show a hintHide the hint
Use the same four row operations as the previous check, but carry all three columns of I along.
Check: R2+3R1 turns row 2 into (−3+3,−5+6)=(0,1). Then R1−2R2 turns row 1 into (1,0).
The inverse of 111011001 is 1−1001−1001. Guess the last row of the inverse of the 4×4 matrix with 1s on and below the diagonal and 0s above it. (Modeled on Lay §2.2 #33.)
Show a hintHide the hint
Row reducing the lower-triangular matrix of 1s takes one step per row: subtract the row above. What does each of those steps record in the right half?
Show the solutionHide the solution
The pattern is 1s on the diagonal and −1s just below it, so the last row is (0,0,−1,1). To see why, call the 4×4 matrix A and the guess B. Row 4 of BA is −row3(A)+row4(A)=−(1,1,1,0)+(1,1,1,1)=(0,0,0,1), which is row 4 of I. Each row of B subtracts the row above it, and every row of A differs from the one above by a single 1.
Row operations reduce A=[2001] to I. Do the same row operations reduce A−1 to I? (Modeled on Lay §2.2 #10.)
Show a hintHide the hint
Multiply out what the steps do. If Ep⋯E1=A−1, what is Ep⋯E1A−1?
Show the solutionHide the solution
Ep⋯E1A−1=A−1A−1. To reduce A−1 to I you need steps whose product is (A−1)−1=A instead.