TL;DR
Gaussian elimination solves a system of linear equations by a fixed, mechanical procedure. You subtract multiples of one equation from the others to remove a variable from them, repeat until each equation has fewer unknowns than the one above, and then solve from the bottom up. The same steps work for two equations or for two thousand. The method also reveals whether a system has one solution, none, or infinitely many.
Where you'll see it: solving the equations behind a circuit, a structural load, a mixing problem or a least-squares fit, and inside the numerical routines that compute a matrix inverse or a Determinant.
Intuition
Solving by hand
Suppose two numbers satisfy these two conditions: their sum is 5, and their difference is 1. You can find them without any new theory. Add the two conditions and the disappears, leaving . So , and then .
That move is the whole idea. You combine equations so that one unknown drops out of all but one of them. Each equation you then have is simpler, so you can solve it. Gaussian elimination is this move written as a routine that works on any number of equations, and that does not need you to notice which combination to try.
A procedure a computer can follow
The routine has three stages, shown below. First you write the equations as a grid of numbers. Then you clear the entries under each "pivot" position, one column at a time, moving left to right. Finally you read off the unknowns from the bottom equation up.
flowchart TD A[Write the system as a grid of numbers] --> B[Choose a pivot in the current column] B --> C[Clear the entries below the pivot] C --> D[More columns left?] D -->|yes| B D -->|no| E[Solve from the last equation upward]
Nothing in the procedure needs insight. That is why it became the default method for solving linear systems on computers.
The math
The system and its grid
A linear system is a set of equations in which each unknown appears only multiplied by a number and added to the others. We write it compactly as
where is a Matrix of coefficients, is the Vector of unknowns we want, and is the vector of right-hand sides. The augmented matrix puts the right-hand sides in an extra column, so the whole system fits in one grid. For example,
Three allowed moves
Gaussian elimination uses three row operations. You may:
- swap two rows;
- multiply a row by a nonzero number;
- add a multiple of one row to another row.
Each move leaves the set of solutions unchanged. Swapping equations changes nothing. Scaling an equation by a nonzero number gives an equivalent statement. Adding a multiple of one equation to another keeps every solution, because whatever values satisfy both original equations also satisfy the new combination. Since each move can be undone, no solution is gained or lost.
Row echelon form
The goal of the forward pass is row echelon form. In that form, each row starts with more zeros than the row above it, and every entry below a pivot (the first nonzero entry of a row) is zero. A system in this shape is easy to solve from the bottom up.
To get there, use the pivot in each column to zero the entries beneath it. If the entry you want to use as pivot is zero, swap in a lower row that has a nonzero entry in that column. The update for row using pivot row is
where is the entry in row and the pivot column , and is the pivot. To avoid fractions you can instead use , which gives the same zero and a row that is a multiple of the old one.
Back substitution
Once the grid is in row echelon form, solve the last equation first, then substitute its answer into the one above, and continue upward. This step is back substitution. Each equation then has only one new unknown, so it is solved directly.
Three possible outcomes
Elimination tells you how many solutions the system has.
- Exactly one solution: every column has a pivot. For a square system this is the usual case.
- No solution: elimination produces a row of the form with nonzero. The equations contradict each other.
- Infinitely many solutions: some column has no pivot. The variable in that column is a free variable and can be set to any value, and the others follow from it.
The number of pivots is the rank of , so the rank tells you which of the three cases applies.
Cost
For a system with equations and unknowns, elimination takes about arithmetic operations, most of them in the forward pass. The exact constant matters less than the cubic growth: doubling the size of the system multiplies the work by about eight. This is why solving very large systems requires special structure, as discussed below.
Worked examples
Solve and .
- Write the augmented matrix: .
- Use the first row's pivot, 2, to clear the entry under it. Replace row 2 by . The new row 2 is .
- The grid is now , which is row echelon form.
- Solve the last row: , so .
- Substitute into the first row: , so .
Interpretation: . Check: and , both correct. Both pivots, 2 and , are nonzero, so the solution is unique.
Solve the system
- Augmented matrix: .
- Clear column 1. Replace row 2 by . Replace row 3 by .
- Clear column 2 using the pivot in row 2. Replace row 3 by . The entry becomes , the entry , and the right-hand side . So row 3 is .
- Solve row 3: , so .
- Row 2: , so and .
- Row 1: , so .
Interpretation: . Check the first equation: . Each column had a pivot (1, , ), so the answer is the only one. Note that step 3 needed no fraction: multiplying a row by a nonzero number is allowed, and keeping integers makes the arithmetic easier to check by hand.
A lab wants 100 mL of solution containing 25 g of salt. It has three stock solutions: 10%, 20% and 50% salt by mass (treat 1 mL as 1 g for this exercise). Let , and be the millilitres of each stock. The recipe must use 2 times as much of the 20% stock as of the 50% stock.
- Multiply the middle equation by 10 to clear decimals: .
- Augmented matrix: .
- Replace row 2 by .
- Replace row 3 by .
- Solve the last row: , so .
- From : .
- From : .
Interpretation: mix 25 mL of the 10% stock, 50 mL of the 20% stock and 25 mL of the 50% stock. Check the salt: grams. All three pivots are nonzero, so the recipe is the only one that meets all three conditions.
Tradeoffs and failure modes
Elimination is reliable on paper, but a computer running it on floating-point numbers (real numbers stored with a limited number of digits, so each operation rounds slightly) can go wrong in ways that are not visible from the algebra.
| Situation | Problem | Better choice |
|---|---|---|
| A pivot is exactly zero | Dividing by it is impossible | Swap in a lower row with a nonzero entry (partial pivoting) |
| A pivot is tiny but not zero | Rounding error is multiplied by a huge factor and swamps the answer | Partial pivoting: pick the largest entry in the column as the pivot |
| Many unknowns but most coefficients are zero | Elimination fills in the zeros and wastes memory and time | A sparse-aware ordering, or an iterative method |
| Same , many different right-hand sides | Elimination is repeated from scratch each time | Factor once into a lower triangular and an upper triangular matrix (all entries above, respectively below, the diagonal are zero), called an LU factorisation, and reuse it |
| More equations than unknowns | Usually no exact solution | Least squares (the choice that makes the total squared error smallest), as in Linear Regression |
Two failure modes need extra care. First, the algebra can be correct while the numbers are not: a near-zero pivot in floating point can give an answer with no correct digits. Use pivoting, and check the residual (how far the computed answer is from satisfying the equations) after solving. Second, a system with free variables has many solutions, and a routine that silently picks one may mislead you. Report the rank and the free variables, not just one vector that happens to solve the equations.
History
Methods equivalent to elimination are much older than the name. The Nine Chapters on the Mathematical Art, a Chinese mathematical text compiled over the first centuries of the common era, solves systems of linear equations by exactly this kind of column-by-column subtraction. Carl Friedrich Gauss used the procedure in 1809 to compute the orbit of the asteroid Ceres from noisy observations, which is where the name comes from.
In the late 19th century, Wilhelm Jordan published a variant that also clears the entries above each pivot, and the combined name "Gauss–Jordan elimination" is now common. In 1948, Alan Turing analysed how rounding errors grow during elimination, which laid groundwork for pivoting and for the factorisation methods used in software today.
It caught on because it is mechanical, it works for any size of system, and it became straightforward to code. Most of the numerical linear algebra in science and engineering is built on it.
Recap
A linear system is written as a grid, and row operations that keep its solutions unchanged reduce the grid to row echelon form, with a pivot in each column. Back substitution then reads off the unknowns, and the presence or absence of pivots tells you whether the solution is unique, absent or one of infinitely many. The number of pivots is the rank, and the product of the pivots, adjusted for row swaps, gives the Determinant. Those links lead on to the inverse and to the Schur complement, which applies the same elimination to a system split into blocks.
Check yourself
QuestionWhy does adding a multiple of one equation to another not change the solution set?Show answer
Any values that satisfy both original equations also satisfy their combination, since that combination is built from two statements that are both true. Conversely, the original pair can be recovered by reversing the operation, so no solution is gained or lost. This is why the row operations are allowed.
QuestionSolve and by elimination. Show the pivot and the result of clearing the entry under it.Show answer
Use the pivot 1 in row 1. Replace row 2 by . So gives , and gives . Check: and , both correct.
QuestionIn a system with three equations and three unknowns, elimination produces the row . What does this mean, and what would change if the last entry were 0?Show answer
The row says , which no values can satisfy, so the system has no solution. If the last entry were 0, the row would say , which is always true and gives no information. Then the third column has no pivot, the variable it belongs to is free, and the system has infinitely many solutions.
QuestionYou must solve the same 1000-equation system for 500 different right-hand sides . Why is it wasteful to run full elimination every time, and what would you do instead?Show answer
Full elimination costs on the order of operations, and most of that work depends only on , not on . Factor once into lower and upper triangular parts, then for each new do only two cheap triangular solves. This costs on the order of operations per right-hand side after the one-time factorisation.
Sources
- Wikipedia, Gaussian elimination: https://en.wikipedia.org/wiki/Gaussian_elimination
- Trefethen and Bau, Numerical Linear Algebra (SIAM, 1997): https://epubs.siam.org/doi/book/10.1137/1.9780898719574
- Gilbert Strang, Introduction to Linear Algebra: https://math.mit.edu/~gs/linearalgebra/