3.1 Gaussian Elimination & Row Echelon Forms
We have seen how to write systems of equations in the matrix form . But how do we actually find the values of programmatically or systematically?
We use Gaussian Elimination. This is a step-by-step algorithm that uses simple row operations to simplify a matrix until the solution becomes obvious. Let's learn how it works.
1. The Augmented Matrix
To solve a system of equations, we stack the coefficient matrix and the target vector together into a single grid called the augmented matrix, written as .
Let's look at this system:
We write it as:
2. Allowed Row Operations
During Gaussian elimination, we can perform three basic row operations. Crucially, these operations do not change the solution of the system:
- Swap: Switch the position of two rows ().
- Scale: Multiply or divide an entire row by a non-zero number ().
- Pivot Addition: Add or subtract a multiple of one row to another row ().
Our goal is to use these operations to create zeros below the diagonal, making the equations easy to solve.
3. Step-by-Step Walkthrough
Let's solve our augmented matrix step-by-step:
Step 1: Create a Pivot of 1 in the top-left corner
We divide Row 1 by 2 ():
Step 2: Create a 0 below our pivot
We subtract Row 1 from Row 2 ():
Step 3: Create a Pivot of 1 in the second row
We multiply Row 2 by -1 ():
We are now in Row Echelon Form (REF)!
A matrix is in Row Echelon Form (REF) if:
- All rows of zeros (if any) are at the bottom.
- The leading coefficient (the first non-zero number from the left, called the pivot) of a row is always to the right of the pivot above it.
- All entries in a column below a pivot are zero.
From REF, we can read the second row as: . We can plug back into the first row to solve: . This process is called back-substitution.
Step 4: Go further to Reduced Row Echelon Form (RREF)
Instead of back-substitution, we can keep using row operations to clear the numbers above the pivots as well. This leads to Reduced Row Echelon Form (RREF).
Let's eliminate the above our second pivot. We subtract from Row 1 ():
Now, we can read the solutions directly from the matrix:
- Row 1:
- Row 2:
The solution is !
4. REF vs. RREF: A Quick Comparison
Row Echelon Form (REF) Reduced Row Echelon Form (RREF)
(Zeros below main diagonal) (Main diagonal is 1, zeros elsewhere)
┌ 1 2 3 │ 6 ┐ ┌ 1 0 0 │ 1 ┐
│ 0 1 1 │ 2 │ │ 0 1 0 │ 1 │
└ 0 0 1 │ 1 ┘ └ 0 0 1 │ 1 ┘
5. Computing Systems in Machine Learning
While Gaussian elimination is the standard method we teach on paper, it is computationally expensive for computers.
- Gaussian elimination requires operations. If you have a matrix with features, it would take trillions of calculations to solve.
- In machine learning libraries (like Python's
numpy.linalg.solveor PyTorch), computers use more efficient matrix factorizations like LU Decomposition or QR Factorization to solve linear systems quickly and stable.