ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Linear Algebra Essentials for Machine Learning
Chapter 1: Vectors in Machine Learning
Vectors as Data Representations
Fundamental Vector Operations
Vector Magnitude and Direction
The Dot Product and Projections
Vector Norms: Measuring Length
Calculating Distances Between Vectors
Implementing Vector Operations with NumPy
Hands-on Practical: Feature Vector Manipulation
Quiz for Chapter 1
Chapter 2: Matrices: Data Representation and Transformations
Matrices for Organizing Data
Basic Matrix Operations
Matrix Multiplication Explained
Matrices as Linear Transformations
Common Types of Matrices
Representing Systems of Linear Equations
Implementing Matrix Operations with NumPy
Hands-on Practical: Transforming Data Points
Quiz for Chapter 2
Chapter 3: Solving Linear Systems and Matrix Inverses
Linear Systems in Machine Learning Models
Introduction to Gaussian Elimination
The Matrix Inverse
Calculating the Inverse of a Matrix
The Determinant and Invertibility
Solving Ax=b using the Inverse
Numerical Stability and Alternatives
Hands-on Practical: Solving for Model Coefficients
Quiz for Chapter 3
Chapter 4: Vector Spaces, Subspaces, and Linear Independence
Defining Vector Spaces
Understanding Subspaces
Linear Combinations and Span
Linear Independence of Vectors
Basis and Dimension
Column Space and Null Space
Rank of a Matrix
Hands-on Practical: Analyzing Feature Vector Sets
Quiz for Chapter 4
Chapter 5: Eigenvalues and Eigenvectors
Definition of Eigenvalues and Eigenvectors
Geometric Interpretation
The Characteristic Equation
Calculating Eigenvectors
Eigen-decomposition of a Matrix
Significance in Principal Component Analysis (PCA)
Calculating Eigenvalues/Eigenvectors with NumPy
Hands-on Practical: Eigen-decomposition Calculations
Quiz for Chapter 5
Chapter 6: Matrix Decompositions for Machine Learning
Introduction to Matrix Decompositions
Singular Value Decomposition (SVD)
Geometric Interpretation of SVD
SVD for Dimensionality Reduction
SVD Applications in Data Compression
Relationship between SVD and Eigen-decomposition
Overview of LU Decomposition
Overview of QR Decomposition
Implementing Decompositions with SciPy/NumPy
Hands-on Practical: Applying SVD
Quiz for Chapter 6

Introduction to Gaussian Elimination

While using the matrix inverse (which we'll cover next) provides a neat theoretical way to express the solution to Ax=bAx = bAx=b as x=A−1bx = A^{-1}bx=A−1b, it's often not the most computationally efficient or numerically stable way to actually find the solution xxx, especially for large systems. A more fundamental and often practical algorithm for solving systems of linear equations is Gaussian elimination. You might have encountered this method before, perhaps in a different context. Gaussian elimination is a systematic procedure for manipulating matrix equations.

The core idea behind Gaussian elimination is to transform the original system of equations into an equivalent system that is much easier to solve. "Equivalent" means the new system has the same solution set as the original one. We achieve this transformation by applying a sequence of elementary row operations to an augmented matrix.

The Augmented Matrix

First, let's represent the system Ax=bAx = bAx=b using an augmented matrix. This is simply the matrix AAA with the vector bbb appended as an extra column. We often draw a vertical line to separate them visually, though this is just a convention.

For a system like:

2x1+x2−x3=8−3x1−x2+2x3=−11−2x1+x2+2x3=−3\begin{alignedat}{4} 2x_1 & {}+{} & x_2 & {}-{} & x_3 & {}={} & 8 \\ -3x_1 & {}-{} & x_2 & {}+{} & 2x_3 & {}={} & -11 \\ -2x_1 & {}+{} & x_2 & {}+{} & 2x_3 & {}={} & -3 \end{alignedat}2x1​−3x1​−2x1​​+−+​x2​x2​x2​​−++​x3​2x3​2x3​​===​8−11−3​

The corresponding matrix equation Ax=bAx=bAx=b is:

[21−1−3−12−212][x1x2x3]=[8−11−3]\begin{bmatrix} 2 & 1 & -1 \\ -3 & -1 & 2 \\ -2 & 1 & 2 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 8 \\ -11 \\ -3 \end{bmatrix}​2−3−2​1−11​−122​​​x1​x2​x3​​​=​8−11−3​​

The augmented matrix for this system is:

[21−18−3−12−11−212−3]\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ -3 & -1 & 2 & -11 \\ -2 & 1 & 2 & -3 \end{array} \right]​2−3−2​1−11​−122​8−11−3​​

Elementary Row Operations

Gaussian elimination proceeds by applying three types of elementary row operations to this augmented matrix:

  1. Swapping two rows: Interchanging row iii and row jjj. (Corresponds to swapping two equations).
  2. Scaling a row: Multiplying all elements in row iii by a non-zero scalar ccc. (Corresponds to multiplying an equation by ccc).
  3. Adding a multiple of one row to another: Adding ccc times row iii to row jjj. (Corresponds to adding a multiple of one equation to another).

Crucially, none of these operations change the underlying solution set of the linear system.

The Goal: Row Echelon Form

The objective of applying these operations is to transform the coefficient part (the left side) of the augmented matrix into an upper triangular form, also known as row echelon form. A matrix is in row echelon form if:

  1. All rows consisting entirely of zeros are at the bottom.
  2. The first non-zero entry (the "leading entry" or "pivot") of each non-zero row is strictly to the right of the leading entry of the row above it.

For our example augmented matrix, a possible row echelon form might look like this (the exact values depend on the operations chosen):

[■∗∗∗0■∗∗00■∗]\left[ \begin{array}{ccc|c} \blacksquare & * & * & * \\ 0 & \blacksquare & * & * \\ 0 & 0 & \blacksquare & * \end{array} \right]​■00​∗■0​∗∗■​∗∗∗​​

where ■\blacksquare■ represents a non-zero pivot element and ∗*∗ represents any value (including zero).

The Process: Forward Elimination and Back Substitution

Gaussian elimination typically involves two phases:

  1. Forward Elimination: Systematically use the row operations to introduce zeros below the pivot in each column, moving from left to right. This achieves the row echelon form.
  2. Back Substitution: Once the matrix is in row echelon form, the corresponding system of equations is easy to solve. The last equation gives the value of the last variable directly. This value can then be substituted back into the second-to-last equation to solve for the second-to-last variable, and so on, moving upwards.

Let's illustrate with our example:

[21−18−3−12−11−212−3]\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ -3 & -1 & 2 & -11 \\ -2 & 1 & 2 & -3 \end{array} \right]​2−3−2​1−11​−122​8−11−3​​
  • Step 1: Target zeros below the first pivot (the '2' in row 1, column 1).
    • Add 32\frac{3}{2}23​ times Row 1 to Row 2: R2←R2+32R1R_2 \leftarrow R_2 + \frac{3}{2}R_1R2​←R2​+23​R1​
    • Add 111 times Row 1 to Row 3: R3←R3+R1R_3 \leftarrow R_3 + R_1R3​←R3​+R1​
    [21−1801/21/210215]\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ 0 & 1/2 & 1/2 & 1 \\ 0 & 2 & 1 & 5 \end{array} \right]​200​11/22​−11/21​815​​
  • Step 2: Target zero below the second pivot (the '1/2' in row 2, column 2).
    • Add −4-4−4 times Row 2 to Row 3: R3←R3−4R2R_3 \leftarrow R_3 - 4R_2R3​←R3​−4R2​
    [21−1801/21/2100−11]\left[ \begin{array}{ccc|c} 2 & 1 & -1 & 8 \\ 0 & 1/2 & 1/2 & 1 \\ 0 & 0 & -1 & 1 \end{array} \right]​200​11/20​−11/2−1​811​​

This matrix is now in row echelon form.

  • Step 3: Back Substitution. Convert back to equations: 2x1+x2−x3=812x2+12x3=1−x3=1\begin{alignedat}{4} 2x_1 & {}+{} & x_2 & {}-{} & x_3 & {}={} & 8 \\ & & \tfrac{1}{2}x_2 & {}+{} & \tfrac{1}{2}x_3 & {}={} & 1 \\ & & & & -x_3 & {}={} & 1 \end{alignedat}2x1​​+​x2​21​x2​​−+​x3​21​x3​−x3​​===​811​
    • From the last equation: −x3=1  ⟹  x3=−1-x_3 = 1 \implies x_3 = -1−x3​=1⟹x3​=−1.
    • Substitute x3=−1x_3=-1x3​=−1 into the second equation: 12x2+12(−1)=1  ⟹  12x2−12=1  ⟹  12x2=32  ⟹  x2=3\frac{1}{2}x_2 + \frac{1}{2}(-1) = 1 \implies \frac{1}{2}x_2 - \frac{1}{2} = 1 \implies \frac{1}{2}x_2 = \frac{3}{2} \implies x_2 = 321​x2​+21​(−1)=1⟹21​x2​−21​=1⟹21​x2​=23​⟹x2​=3.
    • Substitute x2=3x_2=3x2​=3 and x3=−1x_3=-1x3​=−1 into the first equation: 2x1+(3)−(−1)=8  ⟹  2x1+4=8  ⟹  2x1=4  ⟹  x1=22x_1 + (3) - (-1) = 8 \implies 2x_1 + 4 = 8 \implies 2x_1 = 4 \implies x_1 = 22x1​+(3)−(−1)=8⟹2x1​+4=8⟹2x1​=4⟹x1​=2.

So, the solution is x=[23−1]x = \begin{bmatrix} 2 \\ 3 \\ -1 \end{bmatrix}x=​23−1​​.

A simplified flowchart illustrating the main stages of Gaussian elimination: transforming the augmented matrix to row echelon form via row operations (Forward Elimination), followed by Back Substitution to find the solution vector.

Relevance and Limitations

Gaussian elimination provides a concrete algorithm for solving Ax=bAx=bAx=b. Understanding this process is helpful because:

  1. Foundation: It's the basis for many practical algorithms used in numerical linear algebra libraries, although implementations often use variations (like LU decomposition, which we'll touch upon later) for better efficiency and stability.
  2. Concept: It reinforces the idea of transforming a problem into an equivalent, simpler form.
  3. Analysis: It helps in understanding concepts like matrix rank and the existence/uniqueness of solutions (e.g., a row of zeros in the coefficient part but a non-zero value on the right side indicates no solution).

While performing Gaussian elimination by hand is feasible for small systems, it becomes tedious and prone to numerical errors (especially involving division by small numbers) for larger systems. In practice, we rely on optimized implementations available in libraries like NumPy and SciPy, which often use more advanced techniques derived from these principles.

In the next sections, we will explore the matrix inverse and how it provides an alternative, algebraic way to think about solving Ax=bAx=bAx=b, along with how to compute it using computational tools.

  • 18.06SC Linear Algebra, Gilbert Strang, 2011 (MIT OpenCourseWare) - Free online course materials covering Gaussian elimination through lectures, problem sets, and solutions, providing an accessible learning resource.

© 2026 ApX Machine Learning