Skip to main content

Welcome to a Grasp lesson

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

Lesson 3

Determinants, Inverses, and Matrix Invertibility

Recommended resources

Hello! Welcome back to your journey into the mathematical foundations of computer vision.

In the last lesson, we explored the dot product and matrix multiplication. You learned how these operations are defined not just as arbitrary calculations, but as powerful tools to measure vector similarity and to represent the composition of linear transformations. This idea of a matrix as a transformation is central to everything we'll do.

Today, we'll address a critical question that follows from that idea: if a matrix transforms space, can we undo that transformation? The answer lies in two connected concepts: the determinant and the inverse of a matrix. This lesson will equip you to calculate the determinant and inverse of a square matrix and relate them to the concept of invertibility. Understanding this relationship is crucial for solving systems of linear equations and for comprehending the properties of many algorithms in machine learning.

1. The Determinant: A Measure of Scaling

Every square matrix has a special scalar value associated with it called the determinant. At its core, the determinant tells you by what factor the matrix scales space.

Let's start with the geometric intuition, which is the most powerful way to understand this concept. When a 2x2 matrix transforms a 2D space, it maps the standard unit square (formed by basis vectors and ) into a parallelogram. The determinant is the signed area of this parallelogram.

Geometric Interpretation of Determinant as Area of a Parallelogram
This image illustrates how a 2x2 matrix transforms the unit square (implicit on the left) into a parallelogram. The determinant of the matrix equals the signed area of this resulting parallelogram.
  • If , the transformation expands the area.
  • If , the transformation contracts the area.
  • If , the transformation preserves the area (e.g., a pure rotation).

The most important case for us is when the determinant is zero.

  • If , the transformation collapses the space into a lower dimension. The parallelogram becomes flat, with an area of zero. This means the entire 2D plane is squashed onto a single line or even a point.

This geometric view is explored in the following reading. It also provides the formulas for calculating the determinant of 2x2 and 3x3 matrices.

The Determinant and Invertibility - matrix

This resource, 'The Determinant and Invertibility', provides a clear geometric interpretation of the determinant and the formulas for its calculation. It directly addresses the core ideas of this part of our lesson.

Please read the sections 'Geometric Interpretation of the Determinant' and 'Calculating the Determinant'. Pay close attention to the connection between a zero determinant and the collapse of space. Notice how the 3x3 determinant is defined recursively using 2x2 determinants.

As you read, the calculation for a 2x2 matrix is:

For a 3x3 matrix, the method of cofactor expansion is used. For example, expanding along the first row:

Notice the alternating +, -, + pattern. Each smaller determinant is called a minor of the corresponding element.


2. The Critical Link: Determinant and Invertibility

Now we arrive at the central theme of this lesson. The geometric idea of "collapsing space" has a profound algebraic consequence. If a transformation squashes the plane onto a line, multiple input vectors get mapped to the same output vector. Such a transformation is not one-to-one and therefore cannot be uniquely reversed. This leads to the fundamental rule:

A square matrix is invertible if and only if its determinant is non-zero ().

  • A matrix with is called singular or non-invertible.
  • A matrix with is called non-singular or invertible.

The following reading states this principle clearly and explains its implications.

The Determinant and Invertibility - matrix

Let's return to the same resource to read the section that formalizes this connection.

Read the section 'The Link: Determinant and Invertibility'. This short section is the key takeaway of the entire lesson.

This concept is the primary tool for determining if a system of linear equations has a unique solution. If , then exists, and a unique solution can be found. If , you cannot use the inverse to solve the system.

Test your understanding!

Is the matrix invertible? You don't need to find the inverse, just determine if one exists. What does this tell you about the columns of the matrix?

Show answer

Let's calculate the determinant:

Since the determinant is zero, the matrix is not invertible (it is singular).

This means the transformation represented by collapses 2D space into a lower dimension. If you look at the columns, [2, 8] and [1, 4], you'll notice that the first column is exactly twice the second column. They are linearly dependent and point in the same direction. The parallelogram formed by these two vectors is completely flat—it has zero area.


3. Finding the Inverse

Now that we can determine if an inverse exists, how do we calculate it?

The inverse of a matrix , denoted , is the matrix that "reverses" the action of . It's defined by the property:

where is the identity matrix.

For a 2x2 matrix, the formula is simple:

Notice that this formula explicitly involves dividing by the determinant, which makes it immediately clear why the determinant cannot be zero.

For the general case, there is a formula based on the adjugate of a matrix. Given your interest in first principles, walking through this formal construction will be valuable. It gives a concrete, though computationally inefficient, method for finding any inverse.

The process involves three steps:

  1. Cofactor Matrix: Create a new matrix where each element is replaced by its cofactor. The cofactor is the determinant of the sub-matrix formed by removing row and column , multiplied by .
  2. Adjugate Matrix: Transpose the cofactor matrix. The result is the adjugate, denoted .
  3. Inverse Formula: The inverse is then given by:

The following resource provides a formal definition and a worked-out example.

3.2: Determinants and Matrix Inverses

The LibreTexts resource 'Determinants and Matrix Inverses' presents the formal method for calculating the inverse using the adjugate matrix. This aligns with your preference for understanding algorithms from their mathematical foundations.

Read the part of the article under the heading 'Adjugates'. Follow the definition of the cofactor matrix and adjugate matrix. Pay close attention to Example \PageIndex{6}, which computes the adjugate for a 3x3 matrix. Finally, read Theorem \PageIndex{4}: Adjugate Formula, which presents the final formula for A^{-1}. Note the author's important remark that this is a theoretical tool, not a practical one for large matrices.


4. Implementation in Python with NumPy

While the adjugate formula is theoretically elegant, in practice we rely on highly optimized numerical libraries. NumPy's linear algebra module, np.linalg, makes these calculations straightforward.

  • np.linalg.det(A) computes the determinant of matrix A.
  • np.linalg.inv(A) computes the inverse of matrix A.

Let's verify our earlier work and see this in action.

import numpy as np

# A non-singular (invertible) matrix
A = np.array([[3, 1], 
              [2, 4]])

# Calculate the determinant
det_A = np.linalg.det(A)
print(f"Matrix A:\n{A}")
print(f"Determinant of A: {det_A:.2f}") # Should be 3*4 - 1*2 = 10

# Calculate the inverse
if det_A != 0:
    inv_A = np.linalg.inv(A)
    print(f"\nInverse of A:\n{inv_A}")
    
    # Verify that A @ A_inv is the identity matrix
    identity = A @ inv_A
    print(f"\nVerification (A @ A_inv):\n{np.round(identity)}") # Use np.round for clean output
else:
    print("\nMatrix A is singular and has no inverse.")

print("-" * 20)

# A singular (non-invertible) matrix from our exercise
B = np.array([[2, 1], 
              [8, 4]])

det_B = np.linalg.det(B)
print(f"Matrix B:\n{B}")
print(f"Determinant of B: {det_B:.2f}") # Should be 0

# Trying to invert a singular matrix will raise an error
try:
    inv_B = np.linalg.inv(B)
except np.linalg.LinAlgError as e:
    print(f"\nError when inverting B: {e}")

A quick note on numerical computation: due to floating-point arithmetic, a determinant that is theoretically zero might be calculated as a very small number (e.g., 1.23e-17). In code, it's often better to check if the absolute value of the determinant is smaller than a tiny tolerance value rather than checking for exact equality with zero.


Conclusion

You've made excellent progress today, connecting the geometric act of transformation to the algebraic property of invertibility. This is a cornerstone of linear algebra.

Here are the key takeaways from this lesson:

  • The determinant of a square matrix is a scalar that represents the scaling factor of the area/volume under the matrix's transformation.
  • A zero determinant signifies that the transformation collapses space into a lower dimension.
  • A matrix is invertible (non-singular) if and only if its determinant is non-zero.
  • The inverse matrix reverses the transformation of , and it can be formally calculated using the adjugate formula: .

Preview of the Next Lesson:
We've spent a lot of time discussing the idea of a "matrix as a transformation." In the next lesson, we will make this the sole focus. You will learn to geometrically interpret different kinds of matrices—seeing how they perform rotations, reflections, scaling, and shearing operations on vectors and space. This will solidify the intuition you built today around determinants and transformations.