Gaussian Elimination: Solving Linear Systems
3868 words
19 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Gaussian Elimination: Solving Linear Systems ## ๐ฏ Learning Objectives After this topic you will be able to: - Identify row echelon form (REF) and reduced row echelon form (RREF) - Perform the three elementary row operations - Carry out Gaussian elimination to transform any matrix to REF - Carry out Gauss-Jordan e...

Gaussian Elimination: Solving Linear Systems
๐ฏ Learning Objectives
After this topic you will be able to:
- Identify row echelon form (REF) and reduced row echelon form (RREF)
- Perform the three elementary row operations
- Carry out Gaussian elimination to transform any matrix to REF
- Carry out Gauss-Jordan elimination to transform any matrix to RREF
- Determine whether a linear system has zero, one, or infinitely many solutions
- Express solution sets in parametric form using free variables
- Compute the rank of a matrix from its RREF
๐ Prerequisites
- Matrices Introduction (Week 1) โ matrix notation, matrix-vector multiplication
- Determinants (Week 1) โ testing invertibility
- Vectors Introduction (Week 1) โ column vectors and linear combinations
- Gaussian elimination is the master algorithm of linear algebra โ it underlies finding bases, ranks, null spaces, and inverses
1. The Problem: Solving Ax=b
1.1 Intuition: From Messy to Clean
Imagine you have a system of equations. The equations are messy โ coefficients everywhere. We want to transform them into something clean where the solution is obvious.
Row operations are like legal algebraic moves (swap equations, multiply an equation by a non-zero constant, add a multiple of one equation to another). They don't change the solution set.
We systematically apply these moves until the system is in a form we can read the answer from directly.
(Diagram)
2. Row Echelon Form (REF)
2.1 Definition
A matrix is in row echelon form if:
- All non-zero rows are above any zero rows
- The leading (first non-zero) entry of each row is to the right of the leading entry in the row above
- All entries below a leading entry are zero The leading entry (or pivot) is the first non-zero element in a row. In REF, pivots are typically normalised to 1 for convenience (though the definition doesn't require it).
2.2 Examples
โ REF (correct):
โ Not REF (violation):
2.3 Reduced Row Echelon Form (RREF)
โ100โ200โ010โ720โโA matrix is in RREF if it is in REF and additionally:
- The leading entry in each non-zero row is 1
- Each leading 1 is the only non-zero entry in its column โ RREF (correct):
3. Elementary Row Operations
There are exactly three operations that preserve the solution set:
| Operation | Notation | Example | Effect |
|---|---|---|---|
| Swap | RiโโRjโ | Swap rows 1 and 2 | Changes order |
| Scale | RiโโcRiโ , c๎ =0 | Multiply row 2 by 31โ | Simplifies entries |
| Add multiple | RiโโRiโ+cRjโ | R2โโR2โโ2R1โ | Eliminates entries |
Key insight: Adding a multiple of one row to another preserves the determinant. Swapping flips its sign. Scaling scales the determinant by c.
4. Gaussian Elimination Algorithm
4.1 Forward Elimination (to REF)
Given an mรn matrix A:
- Start with the leftmost non-zero column (pivot column)
- Find a pivot: select a non-zero entry in this column. If none exists, move to the next column
- Swap (if needed): bring the pivot row to the top
- Scale (optional): make the pivot 1
- Eliminate below: use row operations to create zeros below the pivot
- Repeat: ignore the pivot row and repeat steps 1-5 on the remaining submatrix
>โฉโจโงโx+2y+z=82x+4yโz=โ13x+2yโ2z=โ1โ>Example 1: Gaussian elimination (3 equations, 3 unknowns)Solve:
>โ123โ242โ1โ1โ2โ8โ1โ1โโ>Augmented matrix:
>R2โโR2โโ2R1โ,R3โโR3โโ3R1โ>Step 1: Already have pivot (1,1)=1.Step 2: Eliminate column 1 below pivot:
>โ100โ20โ4โ1โ3โ5โ8โ17โ25โโ>
>โ100โ2โ40โ1โ5โ3โ8โ25โ17โโ>Step 3: Next pivot is in column 2. Row 2 has a 0 in column 2, so swap R2โโR3โ:
>R2โโโ41โR2โ,R3โโโ31โR3โ>Step 4: Scale pivots (optional but helpful):
>โ100โ210โ145โ1โ8425โ317โโโ>
Step 5: Back substitution. From row 3: z=317โ.From row 2: y+45โz=425โโy=425โโ45โโ 317โ=1275โ85โ=โ1210โ=โ65โFrom row 1: x+2y+z=8โx=8โ2(โ65โ)โ317โ=8+35โโ317โ=324โ+35โโ317โ=312โ=4Solution: x=4, y=โ65โ, z=317โ.
4.2 Gauss-Jordan Elimination (to RREF)
Instead of stopping at REF and back-substituting, we continue eliminating above each pivot to get RREF:
- Perform forward elimination (to REF)
- Scale each row so pivots are 1
- Eliminate upward: for each pivot, use row operations to create zeros above it
>โ100โ210โ145โ1โ8425โ317โโโ>Example 2: Gauss-Jordan (same system)Start from REF:
>R2โโR2โโ45โR3โ,R1โโR1โโR3โ>Step 1: Eliminate above pivot in column 3:
>โ100โ210โ001โ37โโ65โ317โโโ>
>R1โโR1โโ2R2โ>Step 2: Eliminate above pivot in column 2:
>โ100โ010โ001โ4โ65โ317โโโ>
Solution is now read directly from the RREF: x=4,y=โ65โ,z=317โ.
5. Three Cases for Solution Sets
A linear system can have:
| Case | Condition | RREF Pattern | Example in R2 |
|---|---|---|---|
| Unique solution | rank = number of variables | Every column (except last) has a pivot | Two intersecting lines |
| No solution | A row like $[0;0;\dots;0; | ;c] with c \neq 0$ | Inconsistent row |
| Infinitely many solutions | rank < number of variables | At least one column without a pivot (free variable) | Two coincident lines |
Rank = number of non-zero rows (pivots) in RREF.
5.1 Case 1: Unique Solution (already seen in Example 1)
5.2 Case 2: No Solution (Inconsistent)
>{x+y=22x+2y=5โ>Example 3: Inconsistent system
>[12โ12โ25โ]R2โโR2โโ2R1โโ[10โ10โ21โ]>Augmented matrix and row reduction:
Row 2 says 0x+0y=1, which is impossible. No solution.
5.3 Case 3: Infinitely Many Solutions
>{x+2yโz=12x+4yโ2z=2โ>Example 4: Infinitely many solutions
>[12โ24โโ1โ2โ12โ]R2โโR2โโ2R1โโ[10โ20โโ10โ10โ]>Augmented matrix:
>[10โ20โโ10โ10โ]>RREF:
>โxyzโโ=โ100โโ+yโโ210โโ+zโ101โโ>Columns 1 and 3 have pivots? Actually column 2 has no pivot (free variable). Column 1 has pivot. Column 3 has no pivot.Wait โ let me re-check. We have pivots in column 1 only. So columns 2 and 3 are free.Solution: x=1โ2y+z, where y,z are free variables (can be any real number).In parametric vector form:
6. Rank of a Matrix
rank(A)=numberย ofย pivotsDefinition (Rank). The rank of a matrix A is the number of non-zero rows in its RREF (equivalently, the number of pivots).
Properties:
- rank(A)โคmin(m,n) for Amรnโ
- rank(A)=rank(AT)
- rank(A)=dim(columnย spaceย ofย A)
- rank(AB)โคmin(rank(A),rank(B))
>A=โ123โ246โ369โโR2โโ2R1โ,R3โโ3R1โโโ100โ200โ300โโ>Example 5: Finding rank
Rank = 1 (only one pivot).
7. Homogeneous Systems (Ax=0)
Definition (Homogeneous). A system Ax=0 (all right-hand sides are zero) is homogeneous. Key facts:
- Always has at least the trivial solution x=0
- Has non-trivial solutions iff there is at least one free variable (i.e., rank < number of columns)
- The solution set is a vector space (the null space of A)
>{x+2yโz=02x+4y+z=0โ>Example 6: Homogeneous system
>[12โ24โโ11โ]R2โโ2R1โโ[10โ20โโ13โ]31โR2โโ[10โ20โโ11โ]>
>R1โ+R2โโ[10โ20โ01โ]>
>โxyzโโ=yโโ210โโ>Pivots in columns 1 and 3. Column 2 is free.x=โ2y, z=0, y free.Solution:
.
8. Algorithm Summary
(Diagram)
9. Edge Cases & Gotchas
| Situation | What Happens |
|---|---|
| Pivot is zero | Need to swap with a row below; if none, move to next column |
| All-zero row in coefficient matrix | Either redundant (consistent) or impossible (inconsistent depending on RHS) |
| Free variables | Indicate infinitely many solutions; parameterise them |
| **Rectangular matrix m<n ** | Always have free variables (more unknowns than equations) |
| Numerical precision | Floating-point arithmetic can create near-zero pivots; use partial pivoting |
10. Common Pitfalls
โ Pitfall 1: Arithmetic errors in elimination
Track every operation carefully. Use fractions or rational arithmetic. Double-check that RiโโRiโ+cRjโ (adding c times row j to row i) leaves row j unchanged.
โ Pitfall 2: Forgetting to apply operations to the RHS
When working with the augmented matrix, every row operation affects both the coefficient matrix and the right-hand side.
โ Pitfall 3: Misidentifying free variables after Gauss-Jordan
In RREF, a column without a pivot (except the last column) corresponds to a free variable. The pivot columns are basic variables.
โ Pitfall 4: Thinking REF requires pivots to be 1
REF does not require leading entries to be 1 (RREF does). Many textbooks normalise to 1 during forward elimination for convenience.
11. Formula Summary Table
| Concept | Description |
|---|---|
| REF | Each pivot right of previous pivot; zeros below pivots |
| RREF | REF + pivots are 1 + zeros above and below |
| Elementary row ops | Swap, scale ( c๎ =0 ), add multiple of another row |
| Rank | Number of pivots (non-zero rows in RREF) |
| Free variables | Columns without pivots (โ last column) |
| Homogeneous system | Ax=0 ; always at least trivial solution |
| Inconsistent system | Row of $[0;\dots;0; |
12. ๐ Practice Questions
>{x+y=32xโy=0โ>Q1: Simple elimination (unique solution)Solve using Gaussian elimination:
>[12โ1โ1โ30โ]R2โโ2R1โโ[10โ1โ3โ3โ6โ]>Strategy: Augmented matrix โ REF โ back substitute.Solution:
>{x+2y=52x+4y=9โ>From R2โ: โ3y=โ6โy=2. From R1โ: x+2=3โx=1.Solution: x=1, y=2. Q2: Inconsistent systemSolve:
>[12โ24โ59โ]R2โโ2R1โโ[10โ20โ5โ1โ]>Strategy: Check for inconsistency.Solution:
>{x+yโ2z=12x+2yโ4z=2โ>Row 2: 0x+0y=โ1 โ impossible. No solution. Q3: Infinitely many solutionsSolve:
>[12โ12โโ2โ4โ12โ]R2โโ2R1โโ[10โ10โโ20โ10โ]>Solution:
>โxyzโโ=โ100โโ+yโโ110โโ+zโ201โโ>Pivot in column 1 (basic variable x). y,z are free.x=1โy+2z, y,zโR.Parametric form:
>โฉโจโงโx+2y+z=02xโy+z=3xโy+z=1โ>. Q4: Gauss-Jordan eliminationSolve using Gauss-Jordan:
>โ121โ2โ1โ1โ111โ031โโ>Solution:
>โ100โ2โ5โ3โ1โ10โ031โโ>R2โโR2โโ2R1โ, R3โโR3โโR1โ:
>โ100โ21โ3โ151โ0โ0โ53โ1โโ>R2โโโ51โR2โ:
>โ100โ210โ151โ53โโ0โ53โโ54โโโ>R3โโR3โ+3R2โ:
>โ100โ210โ151โ1โ0โ53โโ34โโโ>R3โโ35โR3โ:
>โ100โ210โ001โ34โโ31โโ34โโโ>Eliminate above: R1โโR1โโR3โ, R2โโR2โโ51โR3โ:
>โ100โ010โ001โ2โ31โโ34โโโ>R1โโR1โโ2R2โ:
>โฉโจโงโx+2yโz=02x+3y+z=03x+5y+0z=0โ>Solution: x=2, y=โ31โ, z=โ34โ. Q5: Homogeneous system with free variablesFind all solutions to:
>โ123โ235โโ110โ000โโR2โโ2R1โ,R3โโ3R1โโโ100โ2โ1โ1โโ133โ000โโ>Solution:
>โ100โ2โ10โโ130โ000โโ>R3โโR3โโR2โ:
>โ100โ010โ5โ30โ000โโ>R2โโโR2โ, R1โโR1โโ2R2โ:
>โxyzโโ=zโโ531โโ>Pivots in columns 1, 2. z is free. x=โ5z, y=3z.Solution:
>A=โ121โ241โ360โ123โโ>, zโR. Q6: Rank from RREFFind the rank of
>โ121โ241โ360โ123โโR2โโ2R1โ,R3โโR1โโโ100โ20โ1โ30โ3โ102โโ>.Solution:
>โ100โ2โ10โ3โ30โ120โโ>Swap R2โโR3โ:
>{x1โ+2x2โ+x3โโx4โ=12x1โ+4x2โ+2x3โโ2x4โ=2โ>Rank = 2 (two pivots). Q7: Parameterising solution setSolve and parameterise:
>[12โ24โ12โโ1โ2โ12โ]R2โโ2R1โโ[10โ20โ10โโ10โ10โ]>Solution:
>โx1โx2โx3โx4โโโ=โ1000โโ+x2โโโ2100โโ+x3โโโ1010โโ+x4โโ1001โโ>Pivot in column 1. x1โ basic; x2โ,x3โ,x4โ free.x1โ=1โ2x2โโx3โ+x4โ, x2โ,x3โ,x4โโR.Parametric:
>{x+y=12x+ky=3โ>. Q8: System with parametersFor what value(s) of k does the system have (a) unique solution, (b) no solution, (c) infinitely many solutions?
>[12โ1kโ13โ]R2โโ2R1โโ[10โ1kโ2โ11โ]>Solution:
>โฉโจโงโx1โ+x2โ=10x2โโx3โ=5x1โ+x3โ=15โ>
- If k๎ =2, unique solution (y=kโ21โ, x=1โkโ21โ).
- If k=2, row 2 says 0x+0y=1 โ no solution.
- Infinitely many solutions are impossible here (2 equations, 2 unknowns, RHS not all zero). Q9: Rank of transpose
If A is 3ร4 with rank 2, what is the rank of AT?Solution: rank(AT)=rank(A)=2. Q10: Application โ network flowA network has nodes A, B, C with flow equations:
>โ101โ110โ0โ11โ10515โโR3โโR1โโโ100โ11โ1โ0โ11โ1055โโ>Does a unique flow exist?Solution:
>R3โโR3โ+R2โ:โ100โ110โ0โ10โ10510โโ>
Row 3 says 0=10 โ impossible. No solution exists (the equations are inconsistent).Wait โ let me recheck. The sum of equations 1 and 2 minus equation 3: (x1โ+x2โ)+(x2โโx3โ)โ(x1โ+x3โ)=10+5โ15โ2x2โโ2x3โ=0โx2โ=x3โ. Then eq 2: x2โโx3โ=0๎ =5. Indeed inconsistent.
๐ Cross-References
- Next topic: Cramer's Rule โ solving systems using determinants
- Week 3 (Vector Spaces): The solution set of Ax=0 is a vector space
- Week 4 (Basis & Dimension): Gaussian elimination finds bases for vector spaces
- Week 5 (Rank-Nullity): Rank from elimination feeds into the rank-nullity theorem
- BSCS2004 (ML Foundations): Solving normal equations in linear regression uses Gaussian elimination Join Discord Previous1.3 DeterminantsNext2.2 Cramer's Rule & Inverses