Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 7

Solving Systems with Matrix Operations

Recommended resources

Hello! In our last lesson, we explored the determinant and its powerful geometric meaning. We saw that a non-zero determinant means a transformation preserves dimensionality, while a zero determinant signals a collapse into a smaller space. We ended with a crucial teaser: this single number is key to knowing if a system of linear equations has a unique solution.

Today, we'll put that theory into practice. This lesson is dedicated to the fundamental task of solving systems of linear equations using matrix operations. First, we will establish the geometric interpretation of such a system. Then, we will explore two primary methods for finding a solution: using the matrix inverse for well-behaved systems, and the robust algorithmic approach of Gaussian elimination, which can handle any case. This is a cornerstone skill that appears everywhere from engineering analysis to training machine learning models.

1. Understanding the Problem: From Equations to Geometry

A system of linear equations, like the one below, can seem like a simple accounting problem.

2x + y -  z = 8
-3x - y + 2z = -11
-2x + y + 2z = -3

However, by representing it in matrix form as , we unlock a powerful geometric perspective.

A system of linear equations can be compactly represented as a matrix equation AX=B, where A is the matrix of coefficients, X is the vector of variables, and B is the vector of constants.

The equation asks a geometric question: "What vector , when transformed by the matrix , lands on the vector ?" Let's build this intuition with a video from 3Blue1Brown.

Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra

This segment from "Essence of linear algebra" provides a brilliant visual interpretation of what it means to solve a system of linear equations.

Watch from the beginning of the main content. Focus on how the abstract system of equations is re-framed as a search for an input vector x that, after a transformation, becomes the output vector V (which we call B).

This geometric viewpoint is incredibly powerful. The question is no longer just about finding numbers that satisfy equations, but about reversing a spatial transformation.


2. The Cleanest Case: Solving with the Matrix Inverse

When the transformation represented by matrix doesn't collapse space—that is, when —a unique solution exists. In this case, we can reverse the transformation. This reverse transformation is represented by the inverse matrix, denoted .

If we have , we can solve for by applying the inverse transformation to :

where is the identity matrix.

This diagram shows the algebraic steps to isolate X by multiplying by the inverse matrix A⁻¹. The Python code snippet illustrates how this is done computationally using NumPy.

Let's return to the 3Blue1Brown video to see what this "reverse" transformation looks like.

Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra

This clip explains the concept of an inverse transformation and how it's used to solve for X.

Please watch from the non-zero determinant case. The key idea is that finding X is equivalent to "playing the transformation in reverse" and seeing where the vector V (or B) came from.

So, if a matrix has an inverse (i.e., its determinant is non-zero), we have a clear path to a unique solution. While computing the inverse manually can be tedious (we'll cover that in the next lesson), in practice, libraries like NumPy have highly optimized functions for this.

The recommended way to solve in Python is not by finding the inverse and then multiplying, but by using a dedicated solver function, which is more numerically stable and efficient.

import numpy as np




# Let's solve the system from the start of the lesson
A = np.array([[2, 1, -1],
              [-3, -1, 2],
              [-2, 1, 2]])

B = np.array([8, -11, -3])




# We can first check if a unique solution exists
det_A = np.linalg.det(A)
print(f"Determinant of A: {det_A:.1f}") # Output is -1.0, so it's invertible!




# Use the efficient linalg.solve function
X = np.linalg.solve(A, B)

print(f"Solution vector X: {X}") # Output: [ 2.  3. -1.]

This means , , and is the unique solution to our system.


3. The Complicated Cases: Zero, One, or Infinite Solutions

What happens if ? The transformation collapses space into a lower dimension (e.g., a plane into a line). In this case, there is no inverse transformation—you can't "un-squish" a line back into a plane with a simple function.

This leads to two possibilities for the solution to :

  1. No Solution: If the vector lies outside the collapsed space (the column space of ), then no vector could possibly land on it.
  2. Infinitely Many Solutions: If the vector is within the column space, then not only does at least one solution exist, but a whole line or plane of vectors (related to the null space of ) will also land on .

The following resources delve into these conditions more formally.

Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra

These segments build on the zero-determinant case, introducing the language needed to describe the conditions for a solution.

Watch the section discussing the zero determinant case to understand why no inverse exists. Then, watch the explanation of column space and null space to see how they determine if a solution exists and how many solutions there are.

To solidify these rules, let's watch a more direct explanation.

Linear Systems of Equations, Ax=b

This video by Steve Brunton clearly states the conditions for having no, one, or infinitely many solutions.

Focus on the key condition for a solution to exist: B must be in the column space of A. Next, understand how a non-trivial null space leads to infinitely many solutions. He provides a clear proof by showing that you can add any vector from the null space to a solution and still get a valid solution.

To summarize the conditions for solving :

  • Unique Solution: If B is in the column space of A AND the null space of A contains only the zero vector (which is true when ).
  • Infinite Solutions: If B is in the column space of A AND the null space of A is non-trivial (contains more than just the zero vector).
  • No Solution: If B is NOT in the column space of A.

This framework is conceptually complete, but how do we implement it algorithmically?


4. The Universal Tool: Gaussian Elimination

Gaussian elimination is a systematic procedure that transforms a system of equations into an "upper triangular" form, which is easy to solve. It works for any square system and, by its result, tells you which of the three cases you're in. The method consists of three stages.

[PDF] Solution by Gauss Elimination

This guide from the University of Sheffield provides a clear, step-by-step introduction to Gaussian elimination, complete with engineering examples that should resonate with your background.

First, read the introduction and the section "Solving three equations in three unknowns." This explains back-substitution, the simple final step of the process. Next, carefully study "The general system of three simultaneous linear equations." This section details the three core stages: Stage 1: Matrix Formulation (creating the augmented matrix [A|B]) Stage 2: Triangularisation (using elementary row operations to create zeros below the main diagonal) Stage 3: Back Substitution (solving the simplified system)

The key is using elementary row operations to simplify the augmented matrix [A|B] into row echelon form, where all elements below the main diagonal are zero. The allowed operations are:

  1. Swapping two rows.
  2. Multiplying a row by a non-zero constant.
  3. Adding a multiple of one row to another row.

These operations change the equations' appearance but not their underlying solution.

Once in row echelon form, the system is trivial to solve from the bottom up. For example, the augmented matrix

corresponds to the equations:

From the last equation, . You can then substitute this into the second equation to find , and so on.

The Solution by Gauss Elimination resource also explains what happens when you have infinite solutions (see Section 3, "Equations which have an infinite number of solutions"). The algorithm reveals this by producing a row of all zeros (e.g., 0 0 0 | 0), indicating a free variable. If it produces a contradiction (e.g., 0 0 0 | 5, which means ), there is no solution.


Conclusion

In this lesson, we moved from the abstract concept of a determinant to the concrete task of solving systems of linear equations. You now have a comprehensive framework for both understanding and solving the equation .

Key Takeaways:

  • Geometric View: Solving means finding the input vector that lands on the output vector after being transformed by .
  • The Invertible Case: If , the matrix is invertible. A unique solution exists and is given by .
  • The General Conditions: A solution exists if and only if is in the column space of . If, additionally, has a non-trivial null space, there are infinitely many solutions.
  • Gaussian Elimination: This is the standard algorithm for solving any system of linear equations. It uses row operations to transform the augmented matrix into an easy-to-solve upper triangular form and naturally reveals whether there is a unique solution, no solution, or infinite solutions.

In our next lesson, we will complete the story of the matrix inverse. We've used it conceptually today, and next time we will learn the computational steps for computing the inverse of an invertible matrix, which relies on an extension of the Gaussian elimination process you learned today.