4.8.18 · D2Numerical Methods

Visual walkthrough — Solving linear systems — Gaussian elimination with partial pivoting

2,792 words13 min readBack to topic

Step 1 — What is a system of equations, as a picture?

WHAT. A linear system is a set of equations where each unknown appears by itself, multiplied by a plain number (no squares, no products of unknowns). We write two of them:

WHY care about the picture. Each equation with two unknowns is a straight line in the plane. Solving the system means finding the single point that lies on both lines at once — where they cross.

PICTURE. Two lines, one blue, one orange; the green dot where they meet is the solution . That crossing point is the only thing we are hunting for.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

Step 2 — The one move that never changes the answer

WHAT. We are allowed exactly three moves on rows, called elementary row operations: (1) swap two rows, (2) scale a row by a nonzero number, (3) add a multiple of one row to another. The star of the show is move (3):

Read it aloud: "the new row is the old row minus copies of row ." Here is just some number we get to choose.

WHY it's legal. Each row is a line. Move (3) tilts line but keeps it passing through the same crossing point, because at the solution both equations already hold, so any combination of them still holds there.

PICTURE. The orange line rotates as we change , but it pivots around the green solution dot — the intersection never moves. That invariance is the entire licence for what follows.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

Step 3 — Choosing so a number becomes zero

WHAT. We want to erase the first unknown from the second equation — i.e. make the bottom-left number become . Using the naming rule, the pivot (top-left) entry is (row 1, column 1) and the one we want to kill is (row 2, column 1). After the move, the new bottom-left entry is:

Set that to zero and solve for :

WHY divide. The only value of that cancels exactly is "how many pivots fit into " — that's a division. We call this the multiplier.

PICTURE. A vertical bar of height next to a bar of height ; the fraction is the scaling factor that makes line up exactly with , so their difference is flush zero.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

Step 4 — Why the pivot must not be tiny (the whole reason for pivoting)

WHAT. Look again at . The pivot sits in the denominator. If is a tiny number like , then becomes enormous.

WHY that's dangerous. A huge multiplies every entry of the pivot row before subtracting. Your calculator only keeps a fixed number of digits (see Round-off Error in Floating Point), so a huge multiplier magnifies the little rounding smudges into large errors — the answer rots. This is the story of the parent note's cautionary example.

PICTURE. Two curves of against the pivot size: as the pivot shrinks toward zero, shoots up a vertical wall. The red danger zone is the tiny-pivot region we must avoid.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

Step 5 — The swap, in a picture

WHAT. In the system column 1 has and . The bigger magnitude is , sitting in row 2. So here the winning row is : partial pivoting says swap row and row so the strong pivot moves up top.

WHY the whole row. A row is one complete equation. If you swap only part of it, you've mixed two different equations — garbage. Bar included, always.

PICTURE. Two horizontal row-blocks trading places along a curved arrow; the strong pivot (green) rises to the diagonal, the weak (gray) drops down to be eliminated next.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

Step 6 — Eliminate: watch the zero appear

WHAT. With pivot and target , the multiplier is

Now update row 2 = row 2 row 1, every column (exact fractions first, decimal after):

WHY it works. By construction was chosen to make the first entry vanish; the other entries just come along for the ride.

PICTURE. The bottom row before and after: the leading number melts to (red → gray), and the row becomes an equation in alone. That is the staircase forming.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

Step 7 — Climb back up (back-substitution)

WHAT. The bottom equation now reads , which has one unknown. Solve it, then rise to the row above and plug the known value in.

Here (row 1, column 2) is the coefficient of the already-known in the top row, so the bracket is a pure number before we divide by the pivot.

WHY bottom-up. Only the last row is a one-unknown equation. Solve it first, then each higher row has exactly one new unknown left. Going top-down leaves unknowns trapped in the bracket.

PICTURE. A literal staircase: the bottom step is solved (), an upward arrow carries that value into the top step, which then yields . Check: top equation . ✓

Figure — Solving linear systems — Gaussian elimination with partial pivoting

Step 8 — The degenerate case: when the column is all zeros

WHAT. Suppose at some step every candidate entry in column (rows down to ) is . Then there is nothing to swap up: the largest magnitude available is itself, so the pivot is unavoidably . The matrix is then singular — see Determinants and Condition Number and Numerical Stability.

WHY it splits into two pictures. A zero pivot does not always mean "no answer". Look at what the offending row says after elimination. It has all-zero coefficients on the left, so it reads for some number . Two very different things can happen:

  • Coincident lines (infinitely many solutions): the row became . It is a true-but-empty statement carrying no new information. The two equations were the same line. The unknown that lost its pivot becomes a free variable — you may set it to any value , and the other unknowns follow. The answer is a whole line of points, written e.g. .
  • Inconsistent (no solution): the row became , e.g. . That is a flat lie — no numbers make it true. The lines are parallel but apart and never cross.

HOW to detect it. After forward elimination, scan for any row whose left part is all zeros: if its it signals a free variable (coincident); if its it signals inconsistency (no solution).

PICTURE. Left panel: two coincident lines lying exactly on top of each other — every point is a solution, the free variable slides along them. Right panel: two parallel lines apart — no crossing, the " nonzero" contradiction.

Figure — Solving linear systems — Gaussian elimination with partial pivoting

The one-picture summary

WHAT. One figure compressing the entire journey: start with a full square block ; partial pivoting pulls the biggest entry to the diagonal (green); elimination paints the below-diagonal region to zeros (gray triangle), turning into the triangular and into ; back-substitution climbs the staircase from the bottom to reveal . This is exactly the machinery behind LU Decomposition and the twin routines in Back-substitution and Forward-substitution.

Figure — Solving linear systems — Gaussian elimination with partial pivoting
Recall Feynman: the whole walkthrough in plain words

Picture a stack of number-rows, each one really an equation. Two equations are two lines on paper, and the answer is where they cross. First trick: I'm allowed to subtract one row from another as many times as I like — this tilts a line but keeps it going through the crossing point, so the answer never budges. I use that to erase the first variable from the lower rows: I subtract just the right amount, and the exact amount is "the number I want gone divided by the number on the diagonal." But dividing by a tiny diagonal number makes a giant multiplier, and a giant multiplier smears my calculator's few digits into big errors and wrecks the answer — so before dividing I look down the column, grab the biggest number, and swap its whole row up to the top. Biggest pivot means the multiplier is never larger than one, so nothing explodes. Repeat column by column until the block is a triangle of numbers with zeros in the lower-left — that triangle is , and the right-hand side it dragged along is . Now the bottom equation has only one unknown — solve it — then step up one row, plug in what I just found, solve the next, and keep climbing. If ever a whole column below the diagonal is all zeros, there's no pivot to grab: if the leftover row says the two lines are the same and one variable is free (a whole line of answers); if it says some nonzero number, the lines are parallel and there is no answer at all. That's Gaussian elimination with partial pivoting, start to finish.


Recall

After forward elimination, what shape is the matrix, and what do we call it? ::: Upper-triangular — zeros everywhere below the diagonal; we name that triangular block and its transformed right-hand side . Why must the pivot be the largest-magnitude entry in the column? ::: A tiny pivot makes a huge multiplier that amplifies round-off error; the biggest pivot keeps every . In Step 6, what multiplier zeroed the entry under pivot ? ::: (the decimal is rounded). What solution did the walkthrough give? ::: . A zero pivot with leftover row means what? ::: Coincident equations — a free variable and infinitely many solutions (a whole line). A zero pivot with leftover row nonzero means what? ::: An inconsistent system — parallel lines, no solution.