You've got three equations and three unknowns. How do you actually solve them, by hand, without guessing and checking?
You could try substitution: solve one equation for , plug it into the other two, repeat. It works, but it gets messy fast, and the mess grows with every extra variable.
There's a cleaner way. You combine equations to cancel one variable at a time, until you're left with a staircase of simpler and simpler equations. Solve the simplest one first, then climb back up. That's Gaussian elimination.
Two equations first
Let's start small. Two lines, two unknowns:
Each equation is a line. The solution is wherever those lines cross, .
Now here's the trick that makes elimination work: you're allowed to replace one equation with a combination of it and another. Scale a row, add it to another row, and the new equation is still true for the same solution. The crossing point doesn't move.
Watch what happens when you slide row 2 toward row 1. The line rotates, but it always keeps passing through , because that point already satisfies both original equations, so it satisfies any combination of them too.
Drag the slider to combine row 2 with row 1 — watch line 2 pivot around the fixed solution point.
And hey, notice something at : the line goes flat. Its -coefficient hits zero, and you're left with . You just solved for directly, without ever isolating anything by hand. That flattening is elimination in miniature.
What you're actually allowed to do
Three moves keep a system's solution intact, and elimination only ever uses these:
- Swap two rows. Order doesn't matter, so this changes nothing.
- Scale a row by a nonzero number. Multiplying both sides of an equation by the same thing preserves it.
- Add a multiple of one row to another. This is the one from the animation above, and it's the workhorse.
We write the third one as , where is a number we pick on purpose, to make some entry vanish.
Scaling it up to three variables
With three equations, we do the same thing, just twice. First we use row 1 to knock out of rows 2 and 3. Then we use the new row 2 to knock out of row 3. What's left is a staircase: each row has one fewer variable than the row above it.
For the first step, row 1's -coefficient is , so the multiplier to clear row 2 is just , and for row 3 it's :
Do that, then repeat the same idea on the column below row 2's pivot, and you get a clean triangular system. Step through it below.
Press play and watch zeros creep in below the diagonal, one pivot at a time.
The original system, three equations tangled together.
By the last step, everything below the diagonal is zero. That's the entire goal of forward elimination — turn a tangled system into a staircase you can solve one step at a time.
In general, to clear the entry in row , column using the pivot in row , the multiplier is just their ratio:
But what if the pivot is zero?
...there's a snag. That formula divides by the pivot, . What happens if the pivot is zero?
You can't divide by zero, so the multiplier blows up, and the whole step falls apart. But the fix is simple: swap in a row below that doesn't have a zero there. The system is exactly the same, just reordered, so nothing about the solution changes. You're just picking a pivot that actually works.
Drag row 1's first entry down toward zero and watch the multiplier break, then hit swap.
Drag row 1's first entry toward zero and watch the multiplier break — then swap rows to fix it.
This is why real elimination algorithms always check the pivot first, and swap rows whenever it's zero (or even just uncomfortably small, for numerical stability). It's a small bookkeeping step that keeps the whole method from crashing.
Climbing back up
Once you've got a staircase, you're basically done. The bottom row has only one variable left, so solve it directly. Then plug that answer into the row above, which now has only one unknown too. Keep climbing.
This last stage has a name: back-substitution. It's the payoff for all that elimination work, since every row from here on only ever has one unknown to solve.
Press play to solve from the last row up, substituting each answer into the row above.
The staircase system, ready to solve from the bottom up.
Putting it together
That's the whole method, and it's really just two phases stitched together:
- Forward elimination: use row operations to zero out everything below the diagonal, one column at a time, building a staircase.
- Back-substitution: solve the staircase from the bottom row up, substituting each answer into the row above it.
No guessing, no trial and error. Just a fixed recipe of scaling and subtracting rows, applied one column at a time, that works for any system with a unique solution, no matter how many variables you throw at it.
The interactive visuals above are built with plain SVG and React, no external math libraries required.