Linear Algebra
Determinant
A single number that says — does this matrix flip space, scale it, or collapse it?
The determinant of a square matrix is a single number that captures the "volume scaling" of its linear transformation. Det = 0 means the matrix collapses space (is singular, non-invertible). Det < 0 means it flips orientation. |det| equals the factor by which areas (2D) or volumes (3D) scale under the transformation. Used in solving linear systems, computing eigenvalues, and as the Jacobian for change of variables in calculus.
- 2×2 formuladet = ad − bc
- 3×3 formulaCofactor expansion or Sarrus rule
- Det = 0 meansMatrix is singular — no inverse, columns linearly dependent
- |det A| representsVolume-scaling factor of the transformation
- Sign representsOrientation — positive preserves, negative flips
- Computational costO(n³) via LU decomposition; O(n!) via cofactor expansion
Interactive visualization
Press play, or step through manually. The visualization is yours to drive — try it before reading on.
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
The formulas
| Size | Formula |
|---|---|
| 1×1 | det [a] = a |
| 2×2 | det [[a, b], [c, d]] = ad − bc |
| 3×3 | det [[a,b,c], [d,e,f], [g,h,i]] = a(ei − fh) − b(di − fg) + c(dh − eg) |
| n×n | Cofactor expansion or LU decomposition |
The 2×2 case is worth memorizing — it appears constantly. The 3×3 case is more involved but has the same pattern (alternating signs, products of opposite-corner entries). For n ≥ 4, the explicit formula is too complex for human computation; algorithms compute it.
Geometric meaning
For a 2×2 matrix A with columns v₁ and v₂:
- |det A| is the area of the parallelogram spanned by v₁ and v₂.
- det A > 0 if {v₁, v₂} is positively oriented (counterclockwise from v₁ to v₂ is < 180°).
- det A < 0 if the orientation is flipped.
- det A = 0 if v₁ and v₂ are parallel (collinear; "parallelogram" is degenerate).
For 3×3 — |det| is the volume of the parallelepiped spanned by the columns. For n×n — n-dimensional volume.
So a transformation A multiplies all areas (2D) / volumes (3D) by |det A|. If det A = 5, areas grow 5×. If det A = 0.5, areas shrink to half. If det A = 0, areas collapse to zero — the transformation flattens space onto a lower-dimensional subspace.
Properties
| Property | Statement |
|---|---|
| Multiplicative | det(AB) = det(A) · det(B) |
| Inverse | det(A⁻¹) = 1 / det(A) |
| Transpose | det(Aᵀ) = det(A) |
| Identity | det(I) = 1 |
| Diagonal / triangular | det = product of diagonal entries |
| Row swap | det negates |
| Row scale by c | det multiplied by c |
| Add multiple of one row to another | det unchanged |
| Eigenvalues | det = product of eigenvalues |
| Block diagonal | det = product of block determinants |
The "row operation" properties are the basis of LU decomposition — reduce A to triangular form via row operations, det of triangular is product of diagonal, track the row swaps and scales.
Worked examples
Example 1 — 2×2 determinant
A = [3 4]
[1 2]
det A = 3·2 − 4·1 = 6 − 4 = 2
Geometrically — the parallelogram with corners at (0,0), (3,1), (4,2), (7,3) has area 2.
Example 2 — singular matrix
A = [1 2]
[2 4]
det A = 1·4 − 2·2 = 0
Det = 0 — A is singular. Indeed, row 2 is twice row 1; the rows are linearly dependent. A maps every vector onto the line y = 2x — collapses 2D to 1D.
Example 3 — 3×3 via cofactor expansion
A = [1 2 3]
[0 1 4]
[5 6 0]
Expand along row 1:
det A = 1·det[[1,4],[6,0]] − 2·det[[0,4],[5,0]] + 3·det[[0,1],[5,6]]
= 1·(0 − 24) − 2·(0 − 20) + 3·(0 − 5)
= −24 + 40 − 15 = 1
JavaScript implementation
// 2x2
function det2(A) {
return A[0][0] * A[1][1] - A[0][1] * A[1][0];
}
// 3x3 — Sarrus / cofactor
function det3(A) {
const [[a, b, c], [d, e, f], [g, h, i]] = A;
return a*(e*i - f*h) - b*(d*i - f*g) + c*(d*h - e*g);
}
// General n×n via LU decomposition (efficient and stable)
function detN(A) {
const n = A.length;
const M = A.map(row => [...row]); // copy
let sign = 1;
for (let col = 0; col < n; col++) {
// Partial pivoting — find largest pivot
let pivotRow = col;
for (let r = col + 1; r < n; r++) {
if (Math.abs(M[r][col]) > Math.abs(M[pivotRow][col])) pivotRow = r;
}
if (pivotRow !== col) {
[M[col], M[pivotRow]] = [M[pivotRow], M[col]];
sign = -sign;
}
if (M[col][col] === 0) return 0;
// Eliminate
for (let r = col + 1; r < n; r++) {
const factor = M[r][col] / M[col][col];
for (let c = col; c < n; c++) {
M[r][c] -= factor * M[col][c];
}
}
}
// Det = sign × product of diagonals
let prod = sign;
for (let i = 0; i < n; i++) prod *= M[i][i];
return prod;
}
For real production code, use a numerical library (NumPy, LAPACK). They handle pivoting, scaling, and ill-conditioning more robustly than ad-hoc code.
Jacobian — det in calculus
For a coordinate change (u, v) → (x, y), the Jacobian determinant is:
J = det [[∂x/∂u, ∂x/∂v], [∂y/∂u, ∂y/∂v]]
And the change-of-variables formula in integration is:
∫∫ f(x, y) dx dy = ∫∫ f(x(u,v), y(u,v)) · |J| du dv
The |J| is the local area scaling — small u-v rectangles map to parallelograms in x-y, and J is the area ratio. Polar coordinates have J = r; cylindrical have J = r; spherical have J = r² sin(φ). These show up so often that they're memorized rather than re-derived.
Where determinants show up
- Solvability of linear systems. Ax = b has a unique solution iff det A ≠ 0. Cramer's rule expresses each solution component as a ratio of determinants.
- Eigenvalue computation. Characteristic polynomial — det(A − λI) = 0 — is solved for λ to get eigenvalues. The polynomial's coefficients all involve determinants of submatrices.
- Volume / area in computer graphics. Triangle area = (1/2) |det of [v₁; v₂]|. Used in rendering, collision detection, mesh quality measurement.
- Cross product in 3D. u × v = det of a "matrix" with i, j, k unit vectors and the components of u, v. Direction perpendicular to both, magnitude equal to the parallelogram area.
- Multivariable calculus. Jacobian determinant for change of variables. Appears in every multivariable integral and in differential forms.
- Determinant test for orientation. Whether a 3D triangle is "facing" you (normal toward camera) is a sign-of-determinant test. Used pervasively in graphics for backface culling.
Common mistakes
- Computing det of a non-square matrix. Determinants are defined only for square matrices. m×n with m ≠ n has no determinant; a "rank" is the appropriate generalization.
- Confusing det = 0 with the zero matrix. A nonzero matrix can have det = 0 (it's singular but not zero). The zero matrix has det = 0; the converse is not true.
- Sign errors in cofactor expansion. The signs alternate (-1)^(i+j) — it's easy to drop a minus sign. Double-check by expanding along a different row/column and verifying the same answer.
- Forgetting the multiplicative property's preconditions. det(AB) = det(A) · det(B) requires both A and B to be square AND of the same size. Doesn't apply to rectangular matrices.
- Naive recursion on large matrices. Cofactor expansion is O(n!) — infeasible for n > ~10. Use LU decomposition (O(n³)) for any real computation. Most numerical libraries do this automatically.
- Floating-point error giving a "near-zero" det. Numerical det of a near-singular matrix can be very small but nonzero due to rounding. Treat |det| < some tolerance as effectively zero — or use a singular-value-decomposition-based rank check, which is more robust.
Frequently asked questions
What does the determinant geometrically mean?
For a 2×2 matrix, |det| is the area of the parallelogram spanned by its columns. For 3×3, it's the volume of the parallelepiped. In n dimensions, it's the n-dimensional "volume." The sign indicates orientation — positive means the transformation preserves orientation; negative means it flips it (mirror reflection somewhere).
Why does det = 0 mean no inverse exists?
Det = 0 means the matrix collapses space — multiple input vectors get mapped to the same output. So the transformation isn't invertible — given an output, you can't uniquely recover the input. Algebraically, Cramer's rule for matrix inversion requires dividing by det; div by zero is undefined.
How do you compute det of a 2×2 matrix?
|a b| = ad − bc. Top-left times bottom-right minus top-right times bottom-left. Easy to remember; useful in many contexts. For larger matrices, the formula becomes more complex (cofactor expansion or LU decomposition).
What's cofactor expansion?
A method to compute det of larger matrices. Pick any row or column; for each entry, multiply it by (-1)^(i+j) times the determinant of the submatrix obtained by deleting that entry's row and column. Sum these up. Recursive — reduces n×n to multiple (n-1)×(n-1) determinants. O(n!) for naive recursive implementation; impractical beyond n ~ 7.
How is det used in calculus?
As the Jacobian determinant in change of variables. When you transform an integral from (x, y) to (u, v) coordinates, the Jacobian dx·dy = |det J| · du·dv accounts for how area scales under the transformation. Polar coordinates — Jacobian is r, so dx·dy = r·dr·dθ. The Jacobian IS a determinant, and it appears in every multivariable change-of-variables computation.
How does det relate to eigenvalues?
Det = product of eigenvalues. Trace = sum of eigenvalues. So if a 3×3 matrix has eigenvalues 2, 3, 5 — det = 30, trace = 10. This connects det to the matrix's spectrum without computing eigenvalues explicitly. Useful for shortcuts and intuition.
Why is det multiplicative — det(AB) = det(A)·det(B)?
Geometrically obvious — the volume scaling of a composition is the product of the individual scalings. If A doubles area and B triples it, AB sextuples it. Algebraically, this requires proof using cofactor expansion or properties of multilinear forms. The proof is a few pages but the result is one of the cleanest in linear algebra.