← mapVectors & Matrices

Gaussian Elimination

⚗ Dr. Möbius, from the lab

In the Algebra stratum, you solved systems of two equations by hand, feeling like you were making it up as you went. You weren't — you were running Gaussian elimination without knowing it, you magnificent idiot. Today I'm going to show you the formal machine: a three-move algorithm that solves ANY linear system of any size, reads off the verdict (unique, none, infinite), and as a bonus will compute matrix inverses when you feed it the right thing. This is the Swiss army knife of computational linear algebra, and it fits in your pocket.

THE BIG IDEA

Gaussian elimination reduces any augmented matrix to row echelon form via three legal row operations, after which the solution (unique, none, or infinite) is read off directly.

Augmented matrices: the x's and y's are overhead

A system of equations like 2x+3y=52x + 3y = 5 4xy=14x - y = 1

carries around the variables xx, yy as pure decoration. All the mathematical content is in the coefficients and constants — the xx and yy are just labels dressed up as variables. Strip them off and you get the augmented matrix [Ab][A|\vec{b}]:

[235411]\left[\begin{array}{cc|c} 2 & 3 & 5 \\ 4 & -1 & 1 \end{array}\right]

Column 1 holds the coefficients of xx, column 2 holds the coefficients of yy, and the column after the bar holds the right-hand sides. The variables are implied by position. Everything that follows is pure matrix surgery.

The three legal row operations

The soul of the algorithm is this: each operation rewrites the system into an equivalent one — same solution set, different appearance. There are exactly three legal operations:

  1. Swap two rows: RiRjR_i \leftrightarrow R_j
  2. Scale a row by a nonzero constant: RicRiR_i \leftarrow c R_i (with c0c \ne 0)
  3. Add a multiple of one row to another: RiRi+cRjR_i \leftarrow R_i + c R_j

Why are these legal? Each corresponds to a valid equation manipulation:

  • Swapping equations: the ORDER of equations in a system is irrelevant.
  • Scaling an equation: multiplying both sides by the same nonzero constant.
  • Row-combining: adding the same thing (a multiple of another equation) to both sides.

Any sequence of these three operations preserves the solution set. This is the formal justification of everything you did informally in the Algebra stratum — you were doing row operations, and now they have names. The operations are sacred. Don't invent a fourth one; I will find out.

Forward elimination: building the staircase

Row Echelon Form (REF) is the target of forward elimination. A matrix is in REF when:

  • All zero rows are at the bottom.
  • Each nonzero row's pivot (leftmost nonzero entry) is strictly to the right of the pivot in the row above.

The picture is a staircase: each row's leading entry steps to the right compared to the previous one. Here's the forward-elimination procedure:

  1. Find the leftmost nonzero column. Its first nonzero entry becomes the pivot.
  2. If needed, swap rows to bring a nonzero entry to the pivot position.
  3. Use Row Operation 3 to zero out everything BELOW the pivot.
  4. Move to the submatrix below and to the right of the pivot; repeat.

Example: Solve 2x+yz=12x+y-z=1, 4xy+z=54x-y+z=5, 2x+2y+z=3-2x+2y+z=3.

[211141152213]\left[\begin{array}{ccc|c} 2 & 1 & -1 & 1 \\ 4 & -1 & 1 & 5 \\ -2 & 2 & 1 & 3 \end{array}\right]

R2R22R1R_2 \leftarrow R_2 - 2R_1: [44,12,1(2),52]=[0,3,3,3][4-4, -1-2, 1-(-2), 5-2] = [0,-3,3,3].

R3R3+R1R_3 \leftarrow R_3 + R_1: [2+2,2+1,1+(1),3+1]=[0,3,0,4][-2+2, 2+1, 1+(-1), 3+1] = [0,3,0,4].

[211103330304]\left[\begin{array}{ccc|c} 2 & 1 & -1 & 1 \\ 0 & -3 & 3 & 3 \\ 0 & 3 & 0 & 4 \end{array}\right]

R3R3+R2R_3 \leftarrow R_3 + R_2: [0+0,3+(3),0+3,4+3]=[0,0,3,7][0+0, 3+(-3), 0+3, 4+3] = [0,0,3,7].

[211103330037]\left[\begin{array}{ccc|c} 2 & 1 & -1 & 1 \\ 0 & -3 & 3 & 3 \\ 0 & 0 & 3 & 7 \end{array}\right]

This is REF. Three pivots visible.

Back-substitution and RREF

From REF, back-substitution solves the system bottom-up. The bottom row says 3z=7z=7/33z = 7 \Rightarrow z = 7/3. Middle row: 3y+3(7/3)=33y+7=3y=4/3-3y + 3(7/3) = 3 \Rightarrow -3y + 7 = 3 \Rightarrow y = 4/3. Top row: 2x+(4/3)(7/3)=12x1=1x=12x + (4/3) - (7/3) = 1 \Rightarrow 2x - 1 = 1 \Rightarrow x = 1.

Reduced Row Echelon Form (RREF) is the fully digested form: each pivot is 11, and every entry above AND below each pivot is 00. RREF requires additionally zeroing out above each pivot (more row operations), but gives you the solution directly without back-substitution.

Reading the verdict: three possible outcomes

After elimination, one of three things happens:

  1. Unique solution: The matrix has nn pivots for nn unknowns. No free variables. One solution.

  2. No solution: A row of the form [00k]\left[\begin{array}{ccc|c}0&0&\cdots&k\end{array}\right] with k0k \ne 0 appears. This says "0=k0 = k," which is false. Inconsistent system.

  3. Infinitely many solutions: Pivots are present, but fewer than the number of unknowns. The "free variables" (columns without pivots) can take any value, and the pivot variables are expressed in terms of them. Parametrized solution set.

The pivot count is the first sighting of what the Vector Spaces stratum will call rank. In the next stratum, rank + nullity = nn is the fundamental conservation law of linear algebra — and pivot counting is exactly how you compute rank from elimination. File that away: it's going to blow the lid off everything.

Finding A1A^{-1} by row-reducing [AI][A|I]

Here's a beautiful consequence of the same algorithm. Form the augmented matrix [AI][A|I] — the matrix AA side-by-side with the identity matrix. Run elimination on the whole thing until the left side becomes II. Whatever the right side becomes is A1A^{-1}.

Why does this work? Every row operation is multiplication by an elementary matrix on the left. So the sequence of operations that transforms AIA \to I is multiplication by EkE1E_k \cdots E_1, and EkE1A=IE_k \cdots E_1 A = I means EkE1=A1E_k \cdots E_1 = A^{-1}. Since we apply the same operations to II, the right side becomes A1I=A1A^{-1} I = A^{-1}. It's beautiful and it should make you a little furious that nobody explains it this way the first time.

Example: Find the inverse of A=(2153)A = \begin{pmatrix}2&1\\5&3\end{pmatrix}.

[21105301]\left[\begin{array}{cc|cc}2&1&1&0\\5&3&0&1\end{array}\right]

R2R252R1R_2 \leftarrow R_2 - \frac{5}{2}R_1: [55,35/2,05/2,10]=[0,1/2,5/2,1][5-5, 3-5/2, 0-5/2, 1-0] = [0, 1/2, -5/2, 1].

[211001/25/21]\left[\begin{array}{cc|cc}2&1&1&0\\0&1/2&-5/2&1\end{array}\right]

R22R2R_2 \leftarrow 2R_2: [0,1,5,2][0,1,-5,2].

R1R1R2R_1 \leftarrow R_1 - R_2: [2,0,6,2][2,0,6,-2].

R112R1R_1 \leftarrow \frac{1}{2}R_1: [1,0,3,1][1,0,3,-1].

[10310152]\left[\begin{array}{cc|cc}1&0&3&-1\\0&1&-5&2\end{array}\right]

So A1=(3152)A^{-1} = \begin{pmatrix}3&-1\\-5&2\end{pmatrix}. Check: det(A)=(2)(3)(1)(5)=1\det(A) = (2)(3)-(1)(5)=1, and the formula gives A1=(3152)A^{-1} = \begin{pmatrix}3&-1\\-5&2\end{pmatrix}. Agreement. Elimination eats the inverse problem too.

🔬 SPECIMENS (worked examples)

Worked example 1 — clean kill: unique solution via elimination

Solve the system x+2y=5x + 2y = 5, 3x+5y=123x + 5y = 12.

Set up augmented matrix: [1253512]\left[\begin{array}{cc|c}1&2&5\\3&5&12\end{array}\right]

Eliminate below pivot in column 1: R2R23R1R_2 \leftarrow R_2 - 3R_1: [33,56,1215]=[0,1,3][3-3, 5-6, 12-15] = [0,-1,-3].

[125013]\left[\begin{array}{cc|c}1&2&5\\0&-1&-3\end{array}\right]

This is REF. Two pivots — unique solution.

Back-substitution: Row 2: y=3y=3-y = -3 \Rightarrow y = 3. Row 1: x+2(3)=5x=1x + 2(3) = 5 \Rightarrow x = -1.

Solution: x=1x = -1, y=3y = 3.

Verify: (1)+2(3)=1+6=5(-1) + 2(3) = -1+6=5. 3(1)+5(3)=3+15=123(-1)+5(3)=-3+15=12. Both correct.

Worked example 2 — the system that lies to your face (inconsistent)

Solve x+2y=3x + 2y = 3, 2x+4y=72x + 4y = 7.

Augmented matrix: [123247]\left[\begin{array}{cc|c}1&2&3\\2&4&7\end{array}\right]

Eliminate: R2R22R1R_2 \leftarrow R_2 - 2R_1: [22,44,76]=[0,0,1][2-2, 4-4, 7-6] = [0,0,1].

[123001]\left[\begin{array}{cc|c}1&2&3\\0&0&1\end{array}\right]

Read the verdict: Row 2 says 0x+0y=10x + 0y = 1, i.e., 0=10 = 1. This is impossible. The system is inconsistent — no solution.

Geometric interpretation: x+2y=3x+2y=3 and 2x+4y=72x+4y=7 are parallel lines (both have slope 1/2-1/2, different intercepts). Parallel lines never intersect.

Worked example 3 — infinitely many solutions with free variable

Solve x+y+z=4x + y + z = 4, 2x+y+3z=92x + y + 3z = 9, xy+2z=1x - y + 2z = 1.

Augmented matrix: [111421391121]\left[\begin{array}{ccc|c}1&1&1&4\\2&1&3&9\\1&-1&2&1\end{array}\right]

Eliminate column 1 below row 1: R2R22R1R_2 \leftarrow R_2 - 2R_1: [0,1,1,1][0,-1,1,1]. R3R3R1R_3 \leftarrow R_3 - R_1: [0,2,1,3][0,-2,1,-3].

[111401110213]\left[\begin{array}{ccc|c}1&1&1&4\\0&-1&1&1\\0&-2&1&-3\end{array}\right]

Eliminate column 2 below row 2: R3R32R2R_3 \leftarrow R_3 - 2R_2: [00,2(2),12,32]=[0,0,1,5][0-0, -2-(-2), 1-2, -3-2] = [0,0,-1,-5].

[111401110015]\left[\begin{array}{ccc|c}1&1&1&4\\0&-1&1&1\\0&0&-1&-5\end{array}\right]

REF with three pivots (columns 1, 2, 3). Three unknowns, three pivots — unique solution.

Back-sub: Row 3: z=5z=5-z=-5 \Rightarrow z=5. Row 2: y+5=1y=4-y+5=1 \Rightarrow y=4. Row 1: x+4+5=4x=5x+4+5=4 \Rightarrow x=-5.

Solution: x=5x=-5, y=4y=4, z=5z=5.

Verify row 1: 5+4+5=4-5+4+5=4. Row 2: 2(5)+4+3(5)=10+4+15=92(-5)+4+3(5)=-10+4+15=9. Row 3: 54+10=1-5-4+10=1. All correct.

☠ KNOWN HAZARDS

  • Scaling a row by zero. Only nonzero scalars are allowed in Row Operation 2. Multiplying a row by 00 destroys information — you've deleted an equation — and produces a completely wrong system. This is an illegal operation.

  • Forgetting to apply row operations to the augmented column. When doing row operations on [Ab][A|\vec{b}], every operation must be applied to the entire augmented matrix, including the right-hand side column. Forgetting b\vec{b} is not a small error — it gives you a different system and a wrong answer that looks totally valid.

  • Stopping at REF and declaring no solution. Look at ALL rows after elimination. A row [0,0,,0k][0, 0, \ldots, 0 | k] with k0k \ne 0 signals inconsistency. A row [0,0,,00][0, 0, \ldots, 0 | 0] signals a free variable. Don't stop reading until you've processed every goddamn row.

  • Applying the [AI][A|I] trick to a singular matrix. If AA is not invertible, the left side will never reduce to II — you'll get a zero row on the left, which means AA has no inverse. The algorithm tells you this automatically: if elimination produces a zero row on the left of [AI][A|I], stop, the inverse doesn't exist.

TL;DR

  • The augmented matrix [Ab][A|\vec{b}] strips variables; three legal row operations (swap, scale, add-multiple) preserve the solution set.

  • Forward elimination builds row echelon form (staircase of pivots); back-substitution recovers the values, or continue to RREF for the direct answer.

  • Three possible verdicts after elimination: unique (full pivot count), no solution (0=k0=k row), infinitely many (free variables).

  • Pivot count = rank (the Vector Spaces stratum will formalize this); free variables = dimensions lost.

  • Row-reducing [AI][A|I] produces [IA1][I|A^{-1}] — the same algorithm computes matrix inverses.

unlocks