Skip to content

Gaussian Elimination

Gaussian elimination is the fundamental algorithm for solving Ax=bAx = b without ever computing A−1A^{-1}. It works by applying systematic row operations to transform AA into a triangular form. Once in triangular form, the system is easy to solve by simple substitution — each equation contains one fewer unknown than the one below it, so we can unwind the solution one variable at a time.


Triangular Matrices

Two special matrix shapes make substitution trivial.

A lower triangular matrix LL has zeros everywhere above the main diagonal:

L=[l110…0l21l22…0⋮⋮⋱⋮ln1ln2…lnn]L=\begin{bmatrix}l_{11}&0&\dots&0\\l_{21}&l_{22}&\dots&0\\\vdots&\vdots&\ddots&\vdots\\l_{n1}&l_{n2}&\dots&l_{nn}\end{bmatrix}

An upper triangular matrix UU has zeros everywhere below the main diagonal:

U=[u11u12…u1n0u22…u2n⋮⋮⋱⋮00…unn]U=\begin{bmatrix}u_{11}&u_{12}&\dots&u_{1n}\\0&u_{22}&\dots&u_{2n}\\\vdots&\vdots&\ddots&\vdots\\0&0&\dots&u_{nn}\end{bmatrix}


Forward Substitution

When the system Lx=bLx = b is lower triangular, we can solve it top-down: find x1x_1 from the first equation, substitute into the second to find x2x_2, and so on. This is called forward substitution.

Using a 4×44 \times 4 lower triangular system:

[l11000l21l2200l31l32l330l41l42l43l44][x1x2x3x4]=[b1b2b3b4]\begin{bmatrix}l_{11}&0&0&0\\l_{21}&l_{22}&0&0\\l_{31}&l_{32}&l_{33}&0\\l_{41}&l_{42}&l_{43}&l_{44}\end{bmatrix}\begin{bmatrix}x_{1}\\x_{2}\\x_{3}\\x_{4}\end{bmatrix}=\begin{bmatrix}b_{1}\\b_{2}\\b_{3}\\b_{4}\end{bmatrix}

Row 1: l11x1=b1l_{11}x_{1} = b_{1}

x1=b1l11(1 division)x_{1}=\frac{b_{1}}{l_{11}} \qquad \text{(1 division)}

Row 2: l21x1+l22x2=b2l_{21}x_{1}+l_{22}x_{2}=b_{2}

x2=b2−l21x1l22(1 div, 1 mult, 1 sub)x_{2}=\frac{b_{2}-l_{21}x_{1}}{l_{22}} \qquad \text{(1 div, 1 mult, 1 sub)}

Row 3: l31x1+l32x2+l33x3=b3l_{31}x_{1}+l_{32}x_{2}+l_{33}x_{3}=b_{3}

x3=b3−l31x1−l32x2l33(1 div, 2 mult, 2 sub)x_{3}=\frac{b_{3}-l_{31}x_{1}-l_{32}x_{2}}{l_{33}} \qquad \text{(1 div, 2 mult, 2 sub)}

Row 4: l41x1+l42x2+l43x3+l44x4=b4l_{41}x_{1}+l_{42}x_{2}+l_{43}x_{3}+l_{44}x_{4}=b_{4}

x4=b4−l41x1−l42x2−l43x3l44(1 div, 3 mult, 3 sub)x_{4}=\frac{b_{4}-l_{41}x_{1}-l_{42}x_{2}-l_{43}x_{3}}{l_{44}} \qquad \text{(1 div, 3 mult, 3 sub)}

Because we solve from x1x_1 down to xnx_n, this is called a top-down approach.


Operation Count

For the jj-th variable, we always need 1 division, (j−1)(j-1) multiplications, and (j−1)(j-1) subtractions. The total number of arithmetic operations across all nn variables is:

Total operations=∑j=1n[1+2(j−1)]\text{Total operations}=\sum_{j=1}^{n}\bigl[1+2(j-1)\bigr]

=∑j=1n(2j−1)=\sum_{j=1}^{n}(2j-1)

=2∑j=1nj−∑j=1n1=2\sum_{j=1}^{n}j-\sum_{j=1}^{n}1

=2⋅n(n+1)2−n=2\cdot\frac{n(n+1)}{2}-n

=n(n+1)−n=n(n+1)-n

=n2\boxed{= n^{2}}

Forward substitution on a lower triangular n×nn \times n system costs exactly n2n^2 arithmetic operations.


Applying Gaussian Elimination

To solve a general Ax=bAx = b, we first transform AA into upper triangular form using row operations. The key operation is: for each column kk, eliminate all entries below the diagonal by subtracting a scaled multiple of row kk from every row below it.

Starting from a general 4×44 \times 4 matrix, the column-by-column elimination looks like this:

[XXXXXXXXXXXXXXXX]→[XXXX0XXX0XXX0XXX]→[XXXX0XXX00XX00XX]→[XXXX0XXX00XX000X]\begin{bmatrix}X&X&X&X\\X&X&X&X\\X&X&X&X\\X&X&X&X\end{bmatrix}\rightarrow\begin{bmatrix}X&X&X&X\\0&X&X&X\\0&X&X&X\\0&X&X&X\end{bmatrix}\rightarrow\begin{bmatrix}X&X&X&X\\0&X&X&X\\0&0&X&X\\0&0&X&X\end{bmatrix}\rightarrow\begin{bmatrix}X&X&X&X\\0&X&X&X\\0&0&X&X\\0&0&0&X\end{bmatrix}

Each arrow represents one round of row operations that zeroes out one column below the diagonal. After n−1n-1 rounds the matrix is in upper triangular form and the system can be solved by back substitution (the top-down logic in reverse: solve xnx_n first, then substitute upward).

The diagonal element used to eliminate entries below it in each round is called the pivot. A non-zero pivot is required for each step to proceed.

The general formula for the multiplier used to eliminate entry aika_{ik} in column kk is:

mik=aikakkm_{ik} = \frac{a_{ik}}{a_{kk}}

And the row operation applied to row ii is:

Ri←Ri−mikRkR_i \leftarrow R_i - m_{ik} R_k


Worked Example: Augmented Matrix

Problem: Solve the following system using Gaussian elimination.

x1+2x2+x3=0x_{1}+2x_{2}+x_{3}=0

x1−2x2+2x3=4x_{1}-2x_{2}+2x_{3}=4

2x1+12x2−2x3=42x_{1}+12x_{2}-2x_{3}=4

Step 1 — Set up the augmented matrix

Write AA and bb side by side, separated by a vertical bar:

[12101−224212−24]\left[\begin{array}{ccc|c}1&2&1&0\\1&-2&2&4\\2&12&-2&4\end{array}\right]

Step 2 — First round of elimination (clear column 1 below the pivot)

The pivot is a11=1a_{11} = 1. Compute multipliers m21=a21a11=11=1m_{21} = \dfrac{a_{21}}{a_{11}} = \dfrac{1}{1} = 1 and m31=a31a11=21=2m_{31} = \dfrac{a_{31}}{a_{11}} = \dfrac{2}{1} = 2.

Apply R2←R2−m21 R1R_2 \leftarrow R_2 - m_{21}\,R_1 and R3←R3−m31 R1R_3 \leftarrow R_3 - m_{31}\,R_1:

[12100−41408−44]\left[\begin{array}{ccc|c}1&2&1&0\\0&-4&1&4\\0&8&-4&4\end{array}\right]

Step 3 — Second round of elimination (clear column 2 below the pivot)

The new pivot is a22=−4a_{22} = -4. Compute multiplier m32=a32a22=8−4=−2m_{32} = \dfrac{a_{32}}{a_{22}} = \dfrac{8}{-4} = -2.

Apply R3←R3−m32 R2R_3 \leftarrow R_3 - m_{32}\,R_2:

[12100−41400−212]\left[\begin{array}{ccc|c}1&2&1&0\\0&-4&1&4\\0&0&-2&12\end{array}\right]

The matrix is now upper triangular. The corresponding system is:

x1+2x2+x3=0x_1 + 2x_2 + x_3 = 0

−4x2+x3=4-4x_2 + x_3 = 4

−2x3=12-2x_3 = 12

Step 4 — Back substitution

Solve from the bottom equation upward.

From row 3:

−2x3=12  ⟹  x3=−6-2x_{3}=12 \implies x_{3}=-6

From row 2:

−4x2+x3=4  ⟹  −4x2+(−6)=4  ⟹  −4x2=10  ⟹  x2=−2.5-4x_{2}+x_{3}=4 \implies -4x_{2}+(-6)=4 \implies -4x_{2}=10 \implies x_{2}=-2.5

From row 1:

x1+2x2+x3=0  ⟹  x1+2(−2.5)+(−6)=0  ⟹  x1−11=0  ⟹  x1=11x_{1}+2x_{2}+x_{3}=0 \implies x_{1}+2(-2.5)+(-6)=0 \implies x_{1}-11=0 \implies x_{1}=11

Step 5 — Solution

x1=11,x2=−2.5,x3=−6\boxed{x_1 = 11,\quad x_2 = -2.5,\quad x_3 = -6}