Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

 Open In Colab

The Intuition - solution by elimination.

Gaussian elimination is a formal algorithm for the most familiar and intuitive algebraic solution technique: substitution and elimination.

Let’s start with a classic problem:

You are organizing a fundraising event and need to buy chairs and tables. Chairs cost $20 each and tables cost $50 each. You have a budget of $700 and need a total of 20 pieces of furniture. How many chairs and tables should you buy?

Symbolic Manipulation

Let cc and tt be the number of chairs and tables respectively. We can define our two equations:

(1) 20c+50t=70020c + 50t = 700
(2) c+t=20c + t = 20

Solve (2) for cc:
c=20−tc = 20 - t

Substitute into (1):
20(20−t)+50t=700  ⟹  t=1020(20 - t) + 50t = 700 \implies t = 10

Substitute t=10t=10 back into (2) to find c=10c=10. This works easily because our first step carries the unknown symbol tt.

The Numerical Approach

Computers don’t like carrying symbols. Let’s solve it numerically using only the coefficients.

(1) 20c+50t=70020c + 50t = 700
(2) c+t=20c + t = 20

Multiply (2) by 20:
20c+20t=40020c + 20t = 400

Subtract from (1):

20c+50t=700−(20c+20t)=−40030t=300\begin{aligned} 20c + 50t &= 700 \\ -(20c + 20t) &= -400 \\ 30t &= 300 \end{aligned}

We eliminated cc from the second equation! It is now trivial to solve for tt, and then use back-substitution to find cc.

Transformation to Matrix Form

Notice how the linear system was fundamentally changed (without altering the final answer). In matrix form, we transformed it into:

(2050030)(ct)=(700300)\begin{pmatrix} 20 & 50 \\ 0 & 30 \end{pmatrix} \begin{pmatrix} c \\ t \end{pmatrix} = \begin{pmatrix} 700 \\ 300 \end{pmatrix}

The coefficient matrix A\mathbf{A} is now upper triangular! This is the core goal of Gaussian Elimination.

Upper Triangular Matrices

An upper triangular matrix U\mathbf{U} is a matrix whose elements below the main diagonal are exactly zero:

[u1,1u1,2u1,3u1,40u2,2′u2,3′u2,4′00u3,3′u3,4′000u4,4′]\begin{bmatrix} u_{1,1} & u_{1,2} & u_{1,3} & u_{1,4}\\ 0 & u_{2,2}' & u_{2,3}' & u_{2,4}'\\ 0 & 0 & u_{3,3}' & u_{3,4}' \\ 0 & 0 & 0 & u_{4,4}' \end{bmatrix}

This is incredibly useful because the system Ux=b′\mathbf{U}\mathbf{x} = \mathbf{b}' can be solved from the bottom-up in O(n2)\mathcal{O}(n^2) time via back-substitution.

The Gaussian Elimination Algorithm

Gaussian Elimination transforms Ax=b\mathbf{A}\mathbf{x} = \mathbf{b} into Ux=b′\mathbf{U}\mathbf{x} = \mathbf{b}'.

We build an augmented matrix Ab=[A∣b]\mathbf{Ab} = [ \mathbf{A} | \mathbf{b} ]. To eliminate variables, we make a sequence of passes row-by-row, choosing a pivot row to eliminate elements in the equations below it.

We are allowed the following fundamental row operations:

OperationEffect on solutionEffect on ∣A∣\lvert\mathbf{A}\rvert
Exchange 2 rowsNoneFlips sign
Multiply a row by scalar aaNoneMultiplied by aa
Subtract 2 rowsNoneUnchanged

(Note: While the solution x\mathbf{x} remains identical, the determinant, norm, and condition number of the matrix are actively changing during elimination!)

Example: Guassian elimination

Let’s use the algorithm to solve:

4x1+3x2−5x3=2−2x1−4x2+5x3=58x1+8x2=−3\begin{aligned} 4x_1 + 3x_2 - 5x_3 &= 2 \\ -2x_1 - 4x_2 + 5x_3 &= 5 \\ 8x_1 + 8x_2 &= -3 \end{aligned}

In the following, note the definition of coefficients mi,jm_{i,j} - they will be reference when we talk about LU decomposition.

Step 1: Get the augmented matrix [A∣b][\mathbf{A} | \mathbf{b}]

[A∣b]=[43−52−2−455880−3][\mathbf{A} | \mathbf{b}] = \begin{bmatrix} 4 & 3 & -5 & 2\\ -2 & -4 & 5 & 5\\ 8 & 8 & 0 & -3\\ \end{bmatrix}

First Elimination Pass

Step 2: Eliminate x1x_1 from Row 2 Choose Row 1 as the pivot. Multiply Row 1 by m2,1=−0.5m_{2,1} = -0.5 and subtract it from Row 2:

[43−520−2.52.56880−3]\begin{bmatrix} 4 & 3 & -5 & 2\\ 0 & -2.5 & 2.5 & 6\\ 8 & 8 & 0 & -3\\ \end{bmatrix}

Step 3: Eliminate x1x_1 from Row 3 Multiply Row 1 by m3,1=2m_{3,1} = 2 and subtract it from Row 3:

[43−520−2.52.560210−7]\begin{bmatrix} 4 & 3 & -5 & 2\\ 0 & -2.5 & 2.5 & 6\\ 0 & 2 & 10 & -7\\ \end{bmatrix}

Second Pass & Substitution

Step 4: Eliminate x2x_2 from Row 3 Now Row 2 is the pivot. Multiply Row 2 by m3,2=−0.8m_{3,2} = -0.8 and subtract it from Row 3: $$

[43−520−2.52.560012−2.2]\begin{bmatrix} 4 & 3 & -5 & 2\\ 0 & -2.5 & 2.5 & 6\\ 0 & 0 & 12 & -2.2\\ \end{bmatrix}

$$

A\mathbf{A} is now upper triangular!

Step 5: Back-substitution

  • Bottom row: 12x3=−2.2  ⟹  x3=−0.18312x_3 = -2.2 \implies x_3 = -0.183

  • Middle row: −2.5x2+2.5(−0.183)=6  ⟹  x2=−2.583-2.5x_2 + 2.5(-0.183) = 6 \implies x_2 = -2.583

  • Top row: 4x1+3(−2.583)−5(−0.183)=2  ⟹  x1=2.2084x_1 + 3(-2.583) - 5(-0.183) = 2 \implies x_1 = 2.208

Computational Complexity

If we analyze the two phases of standard Gaussian Elimination separately, we find:

  • Elimination Phase (Forward): Requires ≈n3/3\approx n^3/3 operations, meaning it scales as O(n3)\mathcal{O}(n^3).

  • Back Substitution: Requires ≈n2/2\approx n^2/2 operations, meaning it scales as O(n2)\mathcal{O}(n^2).

For massive systems (e.g., n=10,000n = 10,000), the elimination phase completely dominates the computational time.

Gauss-Jordan Elimination

An obvious extension is to conduct the elimination passes both downwards and upwards, normalizing the pivot rows to 1. This creates the reduced row echelon form (rref):

[1002.208010−2.583001−0.183]\begin{bmatrix} 1 & 0 & 0 & 2.208\\ 0 & 1 & 0 & -2.583\\ 0 & 0 & 1 & -0.183 \end{bmatrix}

Since the coefficient matrix is now the Identity matrix I\mathbf{I}, the answer is simply the right-hand vector!

Is Gauss-Jordan Faster? No.

Because Gauss-Jordan eliminates the need for back-substitution, one might think it is more efficient. Unfortunately, it is not:

  • The full up-and-down elimination phase requires ≈n3/2\approx n^3/2 operations.

  • Standard Gaussian Elimination requires ≈n3/3+n2/2\approx n^3/3 + n^2/2 operations.

Therefore, standard Gaussian Elimination is mathematically preferred for solving large systems.

Package Implementations

Because Gaussian Elimination has largely been surpassed by matrix decompositions (like LU decomposition), you will rarely use raw GE in numerical packages like numpy.

However, it is still incredibly useful for symbolic manipulation, and you will find it natively in sympy under rref():