Determinants, Matrix Inverse, and Trace
The determinant says how much a matrix stretches space, the inverse runs that stretch backwards, and the trace adds up the diagonal — which turns out to be the sum of the eigenvalues.
Why Does This Exist?
Every time a model solves for weights, normalises a Gaussian, or maps one coordinate frame to another, it leans on three facts about square matrices: how much they stretch space, whether that stretch can be undone, and what the diagonal adds up to. Covariance matrices must be invertible to write down a Gaussian density. Least-squares solutions exist exactly when the system matrix has a non-zero determinant. Rotations preserve volume because their determinant is 1.
Without these three numbers you cannot tell a harmless transformation from a collapsing one. A determinant of zero means the matrix flattens space — two different inputs land on the same output, and no inverse can separate them again. A tiny determinant means nearly the same thing in floating point: the math says invertible, the computer says garbage.
This page covers the three properties and how they lock together. The directions of the stretch belong to eigenvalues and eigenvectors; actually solving the systems belongs to linear systems and least squares.
The one idea you need first
A square matrix maps vectors to vectors: . Its two columns are images of the two basis vectors, so the columns show exactly where the grid lines go. Everything below is a fact about that mapping: how areas change, whether the mapping reverses, and what the diagonal sums to.
Think of It Like This
Printing on a rubber sheet, then rewinding
Draw a unit grid on a rubber sheet and stretch it so each square becomes a parallelogram three times larger. That stretching factor, 3, is the determinant: every area triples, and the sign tells you whether the sheet got flipped over.
Now film the stretch and play it backwards. That rewind is the inverse: it takes each stretched parallelogram back to its original square. If instead you had pressed the whole sheet flat onto a line, no rewind could recover the squares — information is gone, and that is a zero determinant.
Finally, add up how far the two printed edge-arrows moved along their own original directions. That sum is the trace. It does not care which way you hold the sheet: rotate the whole picture and the sum is the same, which hints at why it equals the sum of the eigenvalues.
Where the analogy stops: rubber stretches the same everywhere, while a general map stretches differently in different directions — the eigenvalues capture that, and the determinant is only their product.
How It Actually Works
For a matrix , where are the four entries:
In plain words: (determinant) is one number measuring signed volume scaling; (trace) is one number summing the diagonal entries; (inverse) is the matrix that undoes , and is the identity that leaves every vector unchanged. The inverse exists exactly when — a non-zero determinant means non-singular (invertible); zero means singular (flattening, no inverse).
Three relations tie them to the eigenvalues :
- Product: . The total stretch is the product of the per-direction stretches.
- Sum: . The diagonal sum is the eigenvalue sum, in any basis.
- Inverse flips both: , and the inverse has eigenvalues .
Worked example
Take , the matrix used in the diagram:
The characteristic equation is , which factors as . So the eigenvalues are and . Check the relations: product equals the determinant, and sum equals the trace. Both hold.
The inverse is:
Check it undoes : the top-left entry of is , the top-right is , and symmetrically the product is the identity. Its determinant is , exactly , and its trace is .
Geometrically, the columns and are the stretched grid lines: the unit square becomes a parallelogram of area 3, which is the determinant made visible.
Code
The point of this snippet is the round trip: build the matrix from the worked example, verify each number numerically, and confirm the inverse really returns the identity.
import numpy as np
A = np.array([[2.0, 1.0], [1.0, 2.0]])
print(round(float(np.linalg.det(A)), 6)) # -> 3.0print(float(np.trace(A))) # -> 4.0print(np.linalg.eigvalsh(A)) # -> [1. 3.]
Ainv = np.linalg.inv(A)print(np.round(Ainv, 3)) # -> [[ 0.667 -0.333] [-0.333 0.667]]print(np.allclose(A @ Ainv, np.eye(2))) # -> Trueprint(round(float(np.linalg.det(Ainv)), 6)) # -> 0.333333 (= 1/3)eigvalsh is used because the matrix is symmetric, so its eigenvalues are real and sorted. The determinant prints as 3.0 after rounding away the last binary digit of floating-point noise.
Watch Out For
Treating a tiny determinant as safely invertible
A determinant of is non-zero, so the inverse exists on paper — and is useless in practice. The matrix is nearly singular: solving amplifies rounding error by roughly the condition number, and the recovered can point anywhere.
Symptom: np.linalg.solve returns weights that explode or change wildly when you perturb one data point, while the determinant prints as some small-but-nonzero value that looks reassuring. Fix: check np.linalg.cond(A) instead of the determinant — a condition number above about in float64 means the system is numerically singular. Regularise, rescale features, or drop the dependent column rather than inverting.
Splitting determinants and traces across sums and products
Two formulas that look alike but behave oppositely: splits over products, while in general. Dually, splits over sums, while . What the trace does allow over products is cycling: .
Symptom: a derivation that distributes a determinant over a sum, or factorises a trace of a product, and concludes with eigenvalues that fail the product-sum check against a direct computation. Fix: run the product-sum check from the worked example on your own matrices — if or , the algebra upstream is wrong.
The Quick Version
- The determinant is the signed volume-scaling factor: for a 2 by 2 matrix.
- The inverse undoes the matrix and exists exactly when the determinant is non-zero.
- The trace sums the diagonal and equals the sum of the eigenvalues in any basis.
- Determinant is the eigenvalue product; trace is the eigenvalue sum; the inverse takes reciprocals of both.
- For : determinant 3, trace 4, eigenvalues 3 and 1, inverse determinant one third.
- A tiny determinant means numerically singular: check the condition number, not just non-zeroness.
- Determinants split over products, traces over sums — never the other way round.