Index Ai Academy
Foundation · Foundation mathVectors and matrices

Determinant and inverse

About 42 minLooking ahead: some prerequisites aren't done yet

Why this matters

Lesson 58 showed a matrix as a movement of the plane. Two questions follow. How much does the movement grow or shrink areas? And can it be undone, so every point can be sent back where it came from? One number answers both, the determinant. It's the area factor, and when it's 0 the plane has been squashed flat onto a line, which no matrix can unsquash. When it isn't 0, the undoing matrix, the inverse, exists, and it's how a system of equations gets its one answer. In ML, a zero determinant is the warning sign of two features that say the same thing, which leaves a model with no single best answer.

  • Compute a 2 × 2 determinant, ad − bc, and see it as the area of the parallelogram the unit square lands on
  • Know that a determinant of 0 means the plane is flattened and nothing can undo it
  • Find a 2 × 2 inverse by hand, with np.linalg.inv and with torch.linalg.inv, and check that A⁻¹A = I
  • Spot a redundant feature from a zero determinant: a problem with no single answer
Quick check
Have a guess before you start. A matrix doubles every x and triples every y. A square of area 1 is moved by it. What is its new area?

The math: the area factor, and undoing

Purpose. Can a movement be undone? First, how much does it scale area?

The determinant of a 2 × 2 matrix is one number:

det⁡(abcd)=ad−bc\det \begin{pmatrix} a & b \\ c & d \end{pmatrix} = ad - bc

In plain words: multiply down the main diagonal, multiply across the other diagonal, and subtract.

It's the factor by which the matrix scales every area. diag(3, 2) has determinant 3 × 2 − 0 × 0 = 6, so the unit square becomes a rectangle of area 6. A shear, [[1, 1], [0, 1]], has determinant 1: it slants squares but keeps their area. A rotation also has determinant 1.