Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Matrices

Systems of Linear Equations and Gaussian Elimination

The oldest algorithm in linear algebra, and still the workhorse. Solving Ax = b underlies regression, circuit and structure analysis, robot calibration, and every physics simulator.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Puzzles with hidden numbers

“Two numbers add up to 10, and one is 2 bigger than the other. What are they?” You can guess: 6 and 4. That’s a system of equations: several clues about the same hidden numbers.

At the shop. 3 apples and 2 bananas cost ₹35. 1 apple and 2 bananas cost ₹25. The first basket has 2 more apples and costs ₹10 more, so 2 apples cost ₹10, and one apple costs ₹5. Then 2 bananas cost ₹20, so one banana costs ₹10. You subtracted one clue from another to get rid of the bananas. That trick is the heart of Gaussian elimination.

Lines that cross

Each equation with two unknowns is a straight line on a graph. The answer is where the lines cross. Two lines usually cross at exactly one point. But parallel lines never cross (no answer), and the same line drawn twice “crosses” everywhere (endless answers).

📝 Quick check (Level 0)
0/3 answered
  1. 1. Two numbers add to 10 and differ by 2. The larger is…
  2. 2. Two parallel roads never meet. How many crossing points?
  3. 3. In the shop puzzle, what does one apple cost?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Writing a system as a matrix

x+y+z=62y+5z=−42x+5y−z=27⟺(11102525−1)⏟A(xyz)⏟x=(6−427)⏟b\begin{aligned} x + y + z &= 6\\ 2y + 5z &= -4\\ 2x + 5y - z &= 27\end{aligned} \qquad\Longleftrightarrow\qquad \underbrace{\begin{pmatrix}1&1&1\\0&2&5\\2&5&-1\end{pmatrix}}_{A}\underbrace{\begin{pmatrix}x\\y\\z\end{pmatrix}}_{\mathbf x} = \underbrace{\begin{pmatrix}6\\-4\\27\end{pmatrix}}_{\mathbf b}

Three allowed moves (row operations)

None of these changes the solutions:

  1. Swap two equations.
  2. Multiply an equation by a non-zero number.
  3. Add a multiple of one equation to another.

The method

Forward elimination: use these moves to make zeros below the diagonal, column by column. Back-substitution: then solve from the last equation upwards. Step through it:

Gaussian elimination, one step at a time
1116
025-4
25-127
Step 1 of 8: Start: the augmented matrix [A | b].

For the example above, you’ll find x=5,y=3,z=−2x = 5, y = 3, z = -2.

Three possible outcomes

Outcome What elimination shows Picture (2 unknowns)
One solution a pivot in every column lines cross once
No solution a row reading 0=c0 = c with c≠0c\ne0 parallel lines
Infinitely many fewer pivots than unknowns, no contradiction the same line
📝 Quick check (Level 1)
0/3 answered
  1. 1. Solve x + y = 5, x − y = 1. x = ?
  2. 2. Elimination produces the row [0 0 0 | 4]. The system has…
  3. 3. Which is NOT an allowed row operation?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

The rank test (Rouché–Capelli)

Compare the rank of AA with the rank of the augmented matrix [A∣b][A\mid\mathbf b]:

  • rank⁡A<rank⁡[A∣b]\operatorname{rank}A < \operatorname{rank}[A\mid\mathbf b]: no solution, because b∉im⁡A\mathbf b\notin\operatorname{im}A.
  • equal ranks, =n= n: a unique solution.
  • equal ranks, <n< n: infinitely many solutions, forming a (n−r)(n - r)-dimensional family (A2.1-6).

Partial pivoting: a must in practice

At each column, swap in the row with the largest absolute value in that column. Dividing by a tiny pivot multiplies rounding errors enormously. With pivot 10−2010^{-20}, the computed answer can be completely wrong, while the same system with pivoting is solved perfectly (Exercise 2). Every serious library pivots.

🐍 Exercise 1: Gaussian elimination with partial pivoting
Implement forward elimination with partial pivoting and back-substitution. Raise ValueError for a singular matrix.

Cost

Forward elimination on an n×nn\times n system costs about 23n3\tfrac23 n^3 floating-point operations. Back-substitution costs only n2n^2. Doubling nn makes elimination 8 times slower. A dense 10,000×10,00010{,}000\times10{,}000 system takes under a second on a laptop. A million unknowns needs sparsity or iterative methods.

Where linear systems appear

Field System
Data science least squares solves X⊤Xβ=X⊤yX^\top X\boldsymbol\beta = X^\top\mathbf y, a linear system (A2.4)
Robotics inverse kinematics steps JΔq=ΔxJ\Delta\mathbf q = \Delta\mathbf x. Statics: cable tensions or joint torques that balance a load
Calibration camera intrinsics and hand–eye calibration from many measurements
Simulation each time step of an implicit integrator, or every finite-element solve
Optimization each Newton step solves HΔ=−∇fH\Delta = -\nabla f (A6)
📝 Quick check (Level 2)
0/3 answered
  1. 1. rank A = 2 and rank [A | b] = 3. Solutions?
  2. 2. Partial pivoting picks as pivot the entry with…
  3. 3. Elimination on a 300 × 300 system costs about how many flops?

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Row operations preserve the solution set

Theorem

Each elementary row operation is multiplication by an invertible matrix EE. So Ax=bA\mathbf x = \mathbf b and EAx=EbEA\mathbf x = E\mathbf b have exactly the same solutions.

Proof. A swap, a scaling by c≠0c\ne0, or “add cc × row jj to row ii” is II with that operation applied, and each can be undone, so EE is invertible. If Ax=bA\mathbf x = \mathbf b, then EAx=EbEA\mathbf x = E\mathbf b. Conversely, multiply by E−1E^{-1}. ∎

Elimination is a factorization: A = LU

Record each multiplier lijl_{ij} used to clear entry (i,j)(i, j). Then forward elimination says

A=LU,L=unit lower triangular (the multipliers),U=the upper-triangular result.A = LU, \qquad L = \text{unit lower triangular (the multipliers)}, \quad U = \text{the upper-triangular result}.

With pivoting it’s PA=LUPA = LU. Once you have LULU, every new right-hand side costs only O(n2)O(n^2): solve Ly=bL\mathbf y = \mathbf b forwards, then Ux=yU\mathbf x = \mathbf y backwards. Also det⁡A=±∏uii\det A = \pm\prod u_{ii}. That’s how software computes determinants (A2.3).

Example. (2165)\begin{pmatrix}2&1\\6&5\end{pmatrix}: the multiplier is 6/2=36/2 = 3, giving L=(1031)L = \begin{pmatrix}1&0\\3&1\end{pmatrix} and U=(2102)U = \begin{pmatrix}2&1\\0&2\end{pmatrix}.

Sensitivity: the condition number

If b\mathbf b has a relative error δ\delta, the solution can have a relative error up to κ(A) δ\kappa(A)\,\delta, where κ(A)=∥A∥∥A−1∥\kappa(A) = \lVert A\rVert\lVert A^{-1}\rVert. Even a perfect algorithm loses about log⁡10κ\log_{10}\kappa digits. With float64 (about 16 digits) and κ=1012\kappa = 10^{12}, only about 4 digits survive. Backward stability (Wilkinson): Gaussian elimination with partial pivoting gives the exact solution of a slightly perturbed problem, which is the best any algorithm can promise in practice.

Exercise 3.1: Show that the elementary matrix for “R₂ ← R₂ − 3R₁” (2 × 2) is invertible, and find its inverse

E=(10−31)E = \begin{pmatrix}1&0\\-3&1\end{pmatrix} and E−1=(1031)E^{-1} = \begin{pmatrix}1&0\\3&1\end{pmatrix} (“add the 3·R₁ back”). Notice that E−1E^{-1} is exactly the LL of the LU example.

📝 Quick check (Level 3)
0/3 answered
  1. 1. For A = [[2, 1], [6, 5]], what is U₂₂?
  2. 2. κ(A) = 1000 and b has relative error 10⁻⁶. The worst-case relative error in x is about…
  3. 3. After computing A = LU once, each new right-hand side costs…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Pivoting: theory versus practice

Wilkinson (1961) showed that elimination with partial pivoting is backward stable, provided the growth factor, the largest entry that appears during elimination relative to the original, stays modest. In the worst case it can grow like 2n−12^{n-1}, yet on real matrices it almost never does. Why this happens was a long-standing puzzle. Smoothed analysis (Sankar, Spielman and Teng, 2006) explained part of it: tiny random perturbations make bad cases vanish with high probability.

🐍 Exercise 2 (research): why pivoting matters
Solve [[1e−20, 1], [1, 1]] x = [1, 2] with and without pivoting. The true answer is (1, 1).

Beyond direct elimination

  • Iterative solvers such as Jacobi, Gauss–Seidel and especially the conjugate gradient method (Hestenes and Stiefel, 1952) only need matrix–vector products. They are the tool of choice for huge sparse systems in simulation, graph problems and Gaussian processes (A2.4, A8).
  • Sparse direct solvers factor matrices with millions of unknowns by choosing elimination orders that limit fill-in. They’re inside SLAM back-ends like GTSAM and g2o (T3).
  • Mixed precision. Factor in fast low precision (fp16 or fp32) on GPUs, then recover full accuracy with a few rounds of iterative refinement in higher precision (Carson and Higham, 2018). The same mixed-precision idea is used for AI training.

References

  1. The Nine Chapters on the Mathematical Art (Chinese, c. 200 BC–100 AD), Chapter 8 “Fangcheng”: elimination on arrays of numbers.
  2. C. F. Gauss (1809). Theoria motus corporum coelestium. (Elimination for least-squares orbit determination.)
  3. M. Hestenes and E. Stiefel (1952). “Methods of conjugate gradients for solving linear systems.” Journal of Research of the National Bureau of Standards, 49(6).
  4. J. H. Wilkinson (1961). “Error analysis of direct methods of matrix inversion.” Journal of the ACM, 8(3).
  5. A. Sankar, D. Spielman, S.-H. Teng (2006). “Smoothed analysis of the condition numbers and growth factors of matrices.” SIAM Journal on Matrix Analysis and Applications, 28(2).
  6. E. Carson and N. Higham (2018). “Accelerating the solution of linear systems by iterative refinement in three precisions.” SIAM Journal on Scientific Computing, 40(2).
  7. L. Trefethen and D. Bau (1997). Numerical Linear Algebra. SIAM. Lectures 20–23.