Skip to the lesson
FixTheRobot Explore Robotics / Linear Algebra / M3 Linear Systems and Vector Spaces / M3-T2

Linear Algebra · Theory · M3

M3-T2 — Gaussian Elimination and Row Reduction

Gaussian elimination is how every linear solver starts: remove unknowns one at a time until the system can be solved from the bottom up.

  • Lesson 2 of 8
  • Module 3: Linear Systems and Vector Spaces
  • Linear systems
  • About 9 minutes to read

Whether a robot is allocating thrust or estimating a pose, the system of equations is solved by the same procedure. This lesson teaches it, proves why it is legitimate, shows the numerical hazard that makes pivoting mandatory, and explains how the finished form reveals when a system has no solution or many.

Learning objectives

After this lesson, you should be able to:

  • Apply the three row operations to reduce a system to upper triangular form and solve it by back substitution.
  • Justify why row operations do not change the solutions of a system.
  • Explain partial pivoting and the failure it prevents.
  • Read the number of solutions from the echelon form, including pivot and free variables.

Introduction and motivation

The determinant formula of the last lesson works for two equations and becomes hopeless for twenty. Elimination scales: it is the algorithm inside every numerical library that solves A x = b, from a thrust mixer to a SLAM back end. Understanding it by hand tells you what the software is doing, why it sometimes fails, and what a failure means physically.

The intuition

Solving a system by hand, you add a multiple of one equation to another to make an unknown disappear. Do that systematically: use the first equation to remove x₁ from all equations below it, use the second to remove x₂ from those below it, and so on. What remains is a staircase (upper triangular) system whose last equation has one unknown. Solve it, substitute into the one above, and climb back up.

Forward elimination on an augmented matrixThree snapshots of the augmented matrix of a three by three system. First row three has two times row one subtracted. Then one and a half times row two is subtracted, leaving an upper triangular system that is solved by back substitution.1116025−425−127start R3 − 2R1 1116025−403−315zero below the first pivot R3 − 1.5R2 1116025−400−10.521upper triangular: back substitute z = 21 / (−10.5) = −2, then y = 3, then x = 5
Forward elimination turns the augmented matrix into a staircase; back substitution finishes the job.

Interactive figure. Two straight lines, one for each equation. Where they cross is the solution. The readout lists the determinant and whether the solution is unique, absent or one of infinitely many. This figure needs JavaScript to be interactive.

For two unknowns, elimination is the algebra of moving one line until it meets the other. Watch how the cases appear: crossing lines (a pivot in every column), parallel lines (an inconsistent row 0 = non-zero), identical lines (a zero row).

Geometric and physical interpretation

Geometric view. Replacing equation 2 by “equation 2 minus a multiple of equation 1” swaps one line (or plane) for another that passes through the same intersection. Each row operation moves the planes without moving the point where they all meet, which is why the solution is unchanged. Physical view. Each step rewrites a physical requirement as a combination of requirements you already have, so the set of states that satisfy everything is exactly the same. After elimination the requirements are ordered so that each introduces only one new unknown.

The mathematics

[A | b]
the augmented matrix: A with the right-hand side b appended as a last column.
pivot
the first non-zero entry used to eliminate the entries below it (or above it, in reduced form).
Ri
row i of the augmented matrix.

The three row operations

  • Swap two rows: Ri ↔ Rj.
  • Scale a row by a non-zero number: Ri ← c Ri.
  • Add a multiple of one row to another: Rj ← Rj − ℓ Ri with the multiplier ℓ = (entry to eliminate)/(pivot).
forward elimination:   [A | b]  →  [U | c]     (U upper triangular)
back substitution:     xn = cn / unn,   then  xi = ( ci − Σj>i uij xj ) / uii

What it means. Forward elimination zeroes everything below the diagonal. Back substitution solves from the last unknown upward, each step needing only values already found.

Partial pivoting

at step k: swap into the pivot position the row (from k down) whose entry in column k is largest in absolute value

What it means. Dividing by a tiny pivot creates huge multipliers that amplify rounding error. Choosing the largest available pivot keeps every multiplier at most 1 in size.

Reading the result

  • Pivot in every column and a row for every unknown: unique solution.
  • A row of the form 0 0 … 0 | non-zero: inconsistent, no solution.
  • A column with no pivot (a free variable) and no inconsistent row: infinitely many solutions, parametrised by the free variables.

Row operations never change the solution set. Eliminate downward, back-substitute upward, and always pivot on the largest available entry.

Step-by-step derivation: row operations preserve solutions, and why pivoting matters

Row operations do not change the solutions. Each operation is multiplication of [A | b] on the left by an invertible matrix E, so the new system (EA) x = Eb has the same solutions:

  1. If A x = b, multiply both sides by E: (EA) x = Eb. Every old solution is a new solution.
  2. Conversely, if (EA) x = Eb, multiply by E⁻¹ to recover A x = b. Every new solution is an old one.
  3. The three operations have inverses of the same kind: swapping back, scaling by 1/c, and adding the multiple back. So each is invertible and the solution set is unchanged.

Why a tiny pivot is dangerous. Consider ε x + y = 1, x + y = 2 with ε = 10⁻²⁰. The exact solution is x ≈ 1, y ≈ 1. Without pivoting, the multiplier is ℓ = 1/ε = 10²⁰:

  1. Row 2 becomes (1 − ℓε) x + (1 − ℓ) y = 2 − ℓ, that is 0·x + (1 − 10²⁰) y = 2 − 10²⁰.
  2. In floating point 1 − 10²⁰ and 2 − 10²⁰ both round to −10²⁰, so y = 1. The ones were lost.
  3. Back substitution: ε x = 1 − y = 1 − 1 = 0, so x = 0. The computed answer is (0, 1) when the true answer is (1, 1): the error is of order 1.
  4. With pivoting, rows are swapped first so the pivot is 1 and the multiplier is ε = 10⁻²⁰: row 2 becomes (1 − ε) y = 1 − 2ε, giving y = 1 and then x = 2 − y = 1. Correct.

The lesson: the algorithm can be unstable even when the problem is perfectly fine. Pivoting repairs the algorithm.

A worked example: a 3 × 3 system, step by step

Solve x + y + z = 6, 2y + 5z = −4, 2x + 5y − z = 27. The augmented matrix is the left one in the figure.

  1. Column 1. The pivot is the 1 in row 1. Row 2 already has 0 below it. For row 3 the multiplier is 2: R3 ← R3 − 2R1 = (0, 3, −3 | 15).
  2. Column 2. The pivot is the 2 in row 2. For row 3 the multiplier is 3/2 = 1.5: R3 ← R3 − 1.5R2 = (0, 3 − 3, −3 − 7.5 | 15 + 6) = (0, 0, −10.5 | 21).
  3. Back substitution. −10.5 z = 21 gives z = −2. Then 2y + 5(−2) = −4 gives y = 3. Then x + 3 + (−2) = 6 gives x = 5.
  4. Check. 5 + 3 − 2 = 6, 2·3 + 5·(−2) = −4 and 2·5 + 5·3 − (−2) = 27. ✓ The solution is (5, 3, −2).
  5. Reading the cases. If instead the last row had come out as (0, 0, 0 | 21), the system would be inconsistent (no solution); as (0, 0, 0 | 0), it would have a free variable and infinitely many solutions.

The pivoting example. In double precision, eliminating [[10⁻²⁰, 1], [1, 1]] without pivoting gives (x, y) = (0, 1); with a row swap it gives (1, 1).

Robotics application

Allocation and constraint solving. The mixer of a UAV, the constraint solve of a legged robot's contact forces and the normal equations of a calibration are all solved by elimination (usually as LU, next lesson). The Navigation and SLAM tracks use the same solves inside optimisers; see nonlinear least squares, where each iteration solves a linear system built from the Jacobian.

Detecting redundancy and conflict. A zero row after elimination reveals a redundant constraint (for example two sensors reporting the same thing), and a row 0 = non-zero reveals a contradiction (two sensors disagreeing in an exactly noise-free model). Fault-detection logic often turns this observation into an automated check.

Pose-graph and bundle-adjustment solvers. Large sparse systems are solved by elimination on a clever ordering; the cost depends on how much fill-in the elimination creates, which is why ordering heuristics are a research topic. The principle is the one in this lesson.

Hand checks. When a solver returns surprising values, repeat the elimination on a tiny version of the problem. Hand elimination of a 3 × 3 is often enough to find a sign error in a model.

Engineering implications and limitations

Practical rules

  • Always pivot. Library routines use partial pivoting by default. Never write a production solver without it.
  • The cost is about n³/3 operations. Doubling the number of unknowns multiplies the work by about eight, which is why structure (sparsity, symmetry) matters for large problems.
  • Judge singularity numerically. A pivot that is tiny compared with the others signals a nearly singular system; the solution will be sensitive. Check the condition number.
  • Scale the equations. Rows with very different magnitudes make “largest pivot” a misleading rule. Normalise each row (equilibration) for stability.
  • Do not decide solvability from one pivot test. Whether an element is “zero” is a tolerance decision. Rank-revealing methods (SVD or QR with pivoting) are more reliable.

Limits

Elimination is exact in exact arithmetic and backward stable (with pivoting) in floating point, but the answer can still be inaccurate if the problem is ill-conditioned. Stability of the algorithm and conditioning of the problem are separate things; Module 5 returns to this.

Common misconceptions

“Row operations change the problem because they change the equations.”

They change the equations but not the solutions: every operation is reversible, so the old and new systems have exactly the same solution set.

“Pivoting is an optimisation for speed.”

It is about accuracy, not speed. Without it, a perfectly well-posed system can return an answer that is wrong by order one, as the 10⁻²⁰ example shows.

“A zero pivot means there is no solution.”

It means you must look further down the column for a non-zero entry and swap. Only if the entire column below is zero does that column have no pivot, which produces a free variable or an inconsistent row.

“If the answer looks reasonable the solver worked.”

Check the residual b − Ax. Small residuals with large errors can still occur for ill-conditioned systems (Module 5), and a large residual is an unmistakable red flag.

Engineering takeaways

  1. Gaussian elimination uses three row operations (swap, scale, add a multiple) to reach an upper triangular system, then back substitution.
  2. Row operations multiply by invertible matrices, so they never change the solution set.
  3. Partial pivoting (largest available pivot) is required for accuracy; a tiny pivot can ruin the answer.
  4. The echelon form tells you the cases: a pivot in every column (unique), a 0 = non-zero row (none), a pivotless column (infinitely many).
  5. Elimination costs about n³/3 operations, which motivates the factorisation of the next lesson.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

Reduce x + 2y = 5, 3x + 4y = 11 to triangular form and solve. What multiplier did you use, and what is the second pivot?

Explanation

The multiplier is 3: R2 ← R2 − 3R1 gives 0·x + (4 − 6) y = 11 − 15, i.e. −2y = −4, so y = 2. Then x + 4 = 5 gives x = 1. The second pivot is −2 (non-zero, so the solution is unique). Check: 3·1 + 4·2 = 11.

Question 2

After elimination a system in three unknowns ends with the rows (1, 2, 3 | 4), (0, 1, 1 | 2), (0, 0, 0 | 0). What does this say about the number of solutions? Which variable is free?

Explanation

There are only two pivots (columns 1 and 2) and the last row is 0 = 0, which is consistent, so there are infinitely many solutions. The third column has no pivot, so z is a free variable: choose z = t, then y = 2 − t and x = 4 − 2(2 − t) − 3t = −t. The solutions form a line in 3D.

Question 3

Why is dividing by a very small pivot harmful even though mathematically nothing is wrong?

Explanation

A tiny pivot produces a huge multiplier, so the subtraction involves numbers of wildly different size: the small, important information in the other entries is rounded away. The resulting error is large compared with the true answer. Swapping rows to use the largest available pivot keeps all multipliers at most 1 in magnitude and the error small.

What’s next

Elimination solves one system. If the same matrix appears with many right-hand sides, as it does in control loops and filters, redoing the elimination every time is wasteful. LU decomposition records it once.

Practice this lesson

Solve a Robot's Constraints

A mobile base has wheel and speed constraints: solve for the commands, and handle systems with no solution or many.

Next lesson

M3-T3 — LU Decomposition

Factor a matrix as L times U, reuse the factors for many right-hand sides, and explain why pivoting matters.

Nothing below is required to finish this lesson.