[MMD]
Linear Algebra Basics Chapter 1: Systems of Linear Equations and Matrix Singularity
Linear algebra is something you inevitably encounter when studying machine learning. What looks like abstract notation is actually the core mechanism behind how ML models represent and transform data using vectors and matrices. In this post, we'll work through systems of linear equations, matrix singularity, and determinants step by step.
This post is based on Week 1 of DeepLearning.AI's Mathematics for Machine Learning and Data Science.
What You'll Learn#
- Representing data as vectors and matrices, and understanding singularity, rank, and linear independence
- Key operations: dot product, inverse, and determinant
- How linear transformations, eigenvalues, and eigenvectors connect to machine learning
Why Linear Algebra Matters in Machine Learning#
Linear means something can be modeled with a straight line.
Linear Regression is the classic example — it models data with a line. Say you want to predict power output from wind speed. You need to find the ideal weight and bias :
When you have multiple features and multiple data points, you need to solve this equation simultaneously for all of them — and that's exactly what a System of Linear Equations is.
Once the model knows and , it can predict the target given any input feature .
Understanding Equation Systems Through Sentences#
A system of linear equations works a lot like a collection of sentences. Just as multiple sentences together convey more information than one alone, a system of equations works the same way.
| System Type | Description |
|---|---|
| Complete | Contains as much information as the number of equations |
| Redundant | Information is repeated |
| Contradictory | Equations contradict each other |
More information means more useful. A complete system is non-singular; a redundant or contradictory system is singular.
Equation System Examples#
Turning sentences into equations lets us solve the system mathematically.
Two-variable example
Solving gives .
Three-variable example
Solving gives .
Linear vs. Non-linear: An equation is linear only when all variables appear to the first power. Anything involving , , , etc. is non-linear.
Visualizing Equation Systems as Graphs#
In a 2D plane, two lines can relate in exactly three ways:
| Case | Number of Solutions | System Type |
|---|---|---|
| Two lines intersect at one point | Unique solution | Non-singular |
| Two lines are parallel | No solution | Singular |
| Two lines are identical | Infinitely many solutions | Singular |
In 3D, lines become planes:
- System 1: Three planes intersect at a single point → Non-singular (unique solution)
- System 2: Three planes share a common line → Singular (infinitely many solutions)
- System 3: Three planes coincide → Singular (the entire plane is the solution)
Singularity and the Role of Constants#
Interestingly, constants (the right-hand side values) do not affect singularity.
Both have the same coefficients, so singularity is determined entirely by the coefficients. When checking for singularity, you can safely set all constants to zero.
Matrix Singularity#
The coefficients of a linear system can be arranged into a matrix:
- Non-singular matrix: comes from a system with a unique solution
- Singular matrix: comes from a system with no solution or infinitely many solutions
Linear Independence and Dependence#
This is about the relationship between the rows of a matrix.
- Linearly Independent: no row can be expressed as a combination of the other rows
- Linearly Dependent: at least one row can be written as a combination of the others
Key rule:
- Linearly dependent → singular matrix
- Linearly independent → non-singular matrix
Determinant#
The determinant is a single number that tells you at a glance whether a matrix is singular or non-singular.
2×2 Determinant#
Examples:
3×3 Determinant (Sarrus' Rule)#
For a 3×3 matrix, use the diagonal products method:
Add the products of the left-to-right diagonals, then subtract the products of the right-to-left diagonals.
Example:
- Left-to-right diagonals:
- Right-to-left diagonals:
- → singular
Summary#
| Concept | Singular | Non-singular |
|---|---|---|
| Number of solutions | 0 or infinitely many | Exactly 1 |
| Lines / Planes | Parallel or overlapping | Intersect at a point |
| Row relationship | Linearly dependent | Linearly independent |
| Determinant | ||
| Inverse matrix | Does not exist | Exists |
Quiz#
Try these problems to check your understanding.
Q1. Find the determinant of the following 2×2 matrix and determine whether it is singular or non-singular.
Show answer
Since the determinant is 0, this is a singular matrix. The second row is of the first row, so the rows are linearly dependent.
Q2. Is the following system of equations complete, redundant, or contradictory?
Show answer
The second equation is exactly twice the first — it carries no new information. This is a redundant system, with infinitely many solutions. As a matrix, this is singular.
Q3. Find the determinant of the following 3×3 matrix.
Show answer
For a diagonal matrix, the determinant is the product of the diagonal entries.
Since the determinant is non-zero, this is a non-singular matrix.
Q4. Which of the following matrices is linearly independent?
Show answer
- Matrix : row 2 = row 1 × 3, so linearly dependent (, singular)
- Matrix : neither row is a multiple of the other → linearly independent (, non-singular)
Answer: D
In the next post, we'll cover Elimination as a method for solving systems of linear equations, Row Echelon Form, Gaussian elimination, and matrix Rank.
// Related Posts
Probability & Statistics in Practice: Inference Problems from the ML Trenches
From probability fundamentals and Bayes' theorem to distributions, MLE/MAP, confidence intervals, and hypothesis testing — a collection of practice problems grounded in real ML and data analysis scenarios.
Probability & Statistics Coding Assignments: Building ML Statistical Tools in Python
Bayesian updates, distribution simulation, CLT verification, MLE/MAP implementation, confidence intervals, hypothesis testing, and a full A/B test pipeline — implementing probability & statistics chapters 1–4 in code.
ML Probability & Statistics Chapter 4: Confidence Intervals and Hypothesis Testing
A complete guide to confidence intervals, the t-distribution, hypothesis testing fundamentals (null/alternative hypotheses, p-values, rejection regions, statistical power), various t-tests, and A/B testing.