The Determinant: One Number That Decides Invertibility
Here's a question. Given a matrix, how do you know upfront whether it can be inverted at all — before you go through the trouble of actually calculating the inverse?
The answer is a single number called the determinant. If it's zero, the matrix has no inverse. If it's anything else, it does.
That's the whole claim. Now let's take it apart and see why it's true.
Calculating the Determinant of a 2×2 Matrix
For a matrix
A = [ a b ]
[ c d ]
the determinant is a times d, minus b times c. Let's prove it with real numbers.
Take:
A = [ 2 3 ]
[ 1 4 ]
The determinant is 2 × 4 − 3 × 1 = 8 − 3 = 5. Since this isn't zero, A can be inverted.
Now take:
C = [ 2 4 ]
[ 1 2 ]
The determinant is 2 × 2 − 4 × 1 = 4 − 4 = 0. Look closely — row two is exactly half of row one. The rows are linearly dependent. Whenever the determinant is zero, the rows or columns of the matrix are linearly dependent, and the matrix has no inverse.
Why Zero Actually Breaks Things
A matrix represents a system of equations — Ax = b. Write out what C actually says:
2x + 4y = b1
x + 2y = b2
The second equation is just half of the first. It doesn't give you any new information — you effectively have one equation trying to solve for two unknowns.
That means one of two things happens. Either b2 happens to equal half of b1, and now infinitely many (x, y) pairs satisfy both equations. Or b2 doesn't match, and no solution exists at all.
Either way, there's no single, unique x that maps back to a given b — and an inverse only exists if every b has exactly one x. That's the actual reason a zero determinant means no inverse: linear dependence means you don't have enough independent information to pin down a unique answer.
Scaling Up: The 3×3 Determinant
This extends to bigger matrices too. For a 3×3 matrix
M = [ a b c ]
[ d e f ]
[ g h i ]
the determinant is:
a(ei − fh) − b(di − fg) + c(dh − eg)
Let's try it with:
M = [ 2 0 1 ]
[ 1 3 2 ]
[ 0 1 1 ]
That gives us 2 × (3×1 − 2×1) − 0 + 1 × (1×1 − 3×0), which is 2×1 + 1×1 = 3. Non-zero, so this matrix can be inverted.
You can see this gets tedious fast as matrices get bigger — which is exactly why we don't do this by hand in practice.
Doing It the Practical Way
Here's how to do it in NumPy. We define our matrix as a NumPy array, and use numpy.linalg.det to calculate it directly, for a matrix of any size.
import numpy as np
A = np.array([[2, 3],
[1, 4]])
print(np.linalg.det(A)) # -> 5.0
C = np.array([[2, 4],
[1, 2]])
print(np.linalg.det(C)) # -> 0.0
M = np.array([[2, 0, 1],
[1, 3, 2],
[0, 1, 1]])
print(np.linalg.det(M)) # -> 3.0
Where You'll Actually Run Into This
In machine learning, you'll run into the determinant when:
- Checking whether a covariance matrix is valid before using it.
- Working out if a system of equations has a unique solution before you try to invert anything.
- Computing the change-of-variables formula used in probability distributions.
In every one of these, the same idea holds: the determinant is the upfront check, before you commit to the more expensive operation.
What's Next
This fills in exactly the gap left open by the Matrix Inverse video — now you know how to check whether an inverse exists before you go looking for it.
Get the Code
This post is part of the "Linear Algebra for Machine Learning" series. It builds directly on the Matrix Inverse video.
Comments
Post a Comment