Hello! Welcome to the third lesson in our "Mathematical Foundations: Linear Algebra" module.
In our last lesson, we mastered the fundamental operations of matrix addition, subtraction, scalar multiplication, and the crucial concept of matrix multiplication. You learned how to perform these both by hand and efficiently using NumPy, paying special attention to the difference between element-wise * and true matrix multiplication @.
Today, we'll use these skills to tackle a cornerstone problem in linear algebra: solving systems of linear equations. This lesson directly addresses the learning outcome: Solve systems of linear equations using Gaussian elimination. This powerful and systematic algorithm is not just a theoretical tool; it's the foundation for how computers solve large-scale systems that appear everywhere in science, engineering, and machine learning.
1. The Problem: From Equations to Matrices
A system of linear equations is simply a collection of equations with multiple variables. For example:
Solving this by substituting variables can be messy, especially as systems get larger. Gaussian elimination provides a methodical approach. The first step is to encode all the necessary information—the coefficients of the variables and the constant terms—into a single structure called an augmented matrix.
An augmented matrix is formed by taking the matrix of coefficients () and appending the vector of constants () as an extra column. We often draw a vertical line to separate them, representing the equals signs.
For the system above, the augmented matrix is:
To see this conversion explained clearly, please watch the first part of the following video.
Gaussian Elimination & Row Echelon Form
This video by The Organic Chemistry Tutor provides a great introduction to Gaussian elimination, starting with how to set up the augmented matrix from a system of equations.
Watch from the beginning until 01:30. Focus on how the coefficients from each equation form the rows of the matrix.
2. The Goal: Row Echelon Form
The core idea of Gaussian elimination is to simplify the augmented matrix into a special form called Row Echelon Form (or more generally, an upper triangular form). A matrix is in row echelon form when all the non-zero elements are on or above the main diagonal, and all elements below the diagonal are zero.
For a 3x3 system, the goal is to transform the coefficient part of the matrix to look like this:
Here, • represents a non-zero number (called a pivot) and * can be any number.
Why is this form so useful? Because it represents a system of equations that is trivial to solve. The last row gives you the value of the last variable directly. You can then use that value in the second-to-last equation to find the next variable, and so on. This process is called back-substitution.
The following article explains this motivation and the concept of an upper triangular matrix very clearly.
[1/3] A Complete Guide to Gaussian Elimination
This article from Adam Dhalla's blog, 'A Complete Guide to Gaussian Elimination,' effectively explains why we want to achieve an upper triangular form.
Read the section 'The Upper Triangular'. Pay close attention to the example that shows how a system in this form can be easily solved with back-substitution.
This image provides a great visual summary of the entire process we're about to learn.

3. The Method: Elementary Row Operations
To transform a matrix into row echelon form without changing the solution to the system, we are allowed to perform three specific operations, called elementary row operations:
- Swap: Exchange the position of any two rows.
- Scale: Multiply all elements in a row by a non-zero constant.
- Replace: Replace a row with the sum of itself and a multiple of another row.
The third operation is the workhorse of elimination, as it's how we strategically create zeros below the diagonal. For a formal definition of these operations, you can refer to the start of the Jupyter Guide to Linear Algebra.
4. A Complete Walkthrough
Now, let's put it all together. We will use the row operations to get our matrix into row echelon form and then use back-substitution to find the solution.
The following video provides a clear, step-by-step walkthrough of this entire process on the same example we started with.
Gaussian Elimination & Row Echelon Form
Let's continue with The Organic Chemistry Tutor's video. It will now guide you through the row operations and the final back-substitution.
Watch from 01:30 to 09:33. Follow along as he: Uses the 'Replace' operation to create zeros in the first column below the pivot (the top-left '1'). Uses the 'Replace' operation again to create a zero in the second column below the second pivot. Uses the 'Scale' operation to make the pivots equal to 1 (this makes back-substitution neater). Converts the simplified matrix back into equations and solves for z, then y, then x.
Test your understanding!
Solve the following 2x2 system using Gaussian elimination by hand.
- Write the augmented matrix.
- Perform one 'Replace' operation to create a zero in the bottom-left position.
- Use back-substitution to find the values of and .
Show answer
-
The augmented matrix is:
-
We want to make the '2' a zero. We can do this by replacing Row 2 with (Row 2 - 2 * Row 1).
2*R1is[2, 6, 14]R2 - 2*R1is[2-2, 4-6, 10-14] = [0, -2, -4]
The new matrix is:
-
Convert back to equations:
- From Row 2:
- From Row 1:
The solution is .
5. Implementing Elimination in Python
Now for the practical part. While NumPy has a built-in function to solve linear systems directly (np.linalg.solve), implementing the row operations yourself is an excellent way to truly understand the algorithm. This is exactly the kind of foundational knowledge that is valuable for exams like GATE.
The resource below defines simple Python functions to perform each of the three elementary row operations on NumPy arrays and then uses them to solve a system.
Gaussian Elimination — Jupyter Guide to Linear Algebra
The 'Jupyter Guide to Linear Algebra' provides excellent Python code that mirrors the manual elimination process. This is a great way to bridge theory and practice.
Read from the beginning of the page down to the end of 'Example 1'. Skim the introduction to the three row operations. Carefully study the Python functions RowSwap, RowScale, and RowAdd. Understand what each one does. Follow the code in 'Example 1' where these functions are used step-by-step to transform the matrix into upper triangular form and then solved with back substitution.
6. When Elimination Breaks Down: Special Cases
Not every system of equations has a single, unique solution. Gaussian elimination neatly reveals two other possibilities.
-
No Solution (Inconsistent System): The elimination process results in a contradictory row, like
0x + 0y + 0z = c, wherecis a non-zero number (e.g.,0 = 5). This is impossible, so the system has no solution. -
Infinitely Many Solutions (Dependent System): The process results in an identity row, like
0x + 0y + 0z = 0. This is always true and provides no new information. It means you have fewer independent equations than variables. In this case, one or more variables can be chosen freely (they are called free variables), leading to an infinite number of solutions.
This video masterfully explains and demonstrates these three outcomes (unique, no solution, infinite solutions).
Gaussian Elimination (4 examples)
This video by blackpenredpen is excellent for understanding the three possible outcomes of solving a linear system.
I recommend watching all three examples to see how each case unfolds: Unique Solution (00:00 - 08:23): This will be a good review of the standard process. Infinitely Many Solutions (08:23 - 15:34): Pay close attention to how a row of zeros (0 = 0) appears and how he defines a 'free variable' (z) to describe all possible solutions. No Solution (15:34 - 20:55): Notice how a contradiction (0 = 31) appears, signaling that no solution exists.
A final practical issue is what to do when a zero appears in a pivot position. You can't use a zero to eliminate other entries in its column. The solution is simple: use a row swap to move a non-zero number from a lower row into the pivot position and continue. The "Jupyter Guide to Linear Algebra" discusses this in "Example 3: Finding pivots" if you're interested in the details.
Conclusion
In this lesson, you have learned one of the most fundamental algorithms in linear algebra. It's a systematic procedure that guarantees you can find the solution to any system of linear equations, or determine if one doesn't exist.
Key Takeaways:
- A system of linear equations can be represented as an augmented matrix.
- The goal of Gaussian elimination is to use elementary row operations (Swap, Scale, Replace) to transform this matrix into row echelon form.
- A system in row echelon form is easily solved using back-substitution.
- The process will always lead to one of three outcomes:
- A unique solution.
- No solution, identified by a contradiction (e.g.,
0 = 5). - Infinitely many solutions, identified by an identity (e.g.,
0 = 0) and the presence of free variables.
In our next lesson, we will explore the concepts of the determinant and inverse of a matrix. You'll discover that the determinant is a single number that can tell you ahead of time whether a system will have a unique solution, which is a powerful shortcut