5. Determinants: definition, cofactor expansion, properties, geometric meaning, Cramer's Rule

📖 Reading · 10 min
💡 Every code box below is live — edit it and hit Run.

The 2\times2 inverse formula in §16.3 hinged on a single number, ad-bc, that had to be nonzero. This lesson generalizes that number to any square matrix — the determinant — and shows it is simultaneously an invertibility test, a signed area/volume, and (via Cramer's Rule) a direct formula for solving small systems.

The 2\times2 and 3\times3 determinant

\det\begin{pmatrix}a&b\\c&d\end{pmatrix}=ad-bc

For 3\times3, cofactor expansion along the first row:

\det\begin{pmatrix}a&b&c\\d&e&f\\g&h&i\end{pmatrix}=a\det\begin{pmatrix}e&f\\h&i\end{pmatrix}-b\det\begin{pmatrix}d&f\\g&i\end{pmatrix}+c\det\begin{pmatrix}d&e\\g&h\end{pmatrix}

Each term is an entry from the first row, times the determinant of the 2\times2 minor left after deleting that entry's row and column, with alternating signs.

Cofactor expansion in general

For an n\times n matrix, the minor M_{ij} is the determinant of the (n-1)\times(n-1) matrix left after deleting row i and column j, and the cofactor is C_{ij}=(-1)^{i+j}M_{ij} — the sign alternates in a checkerboard pattern starting with + at position (1,1). Expanding along any row i (or column j) gives the same answer:

\det A=\sum_{j=1}^na_{ij}C_{ij}=\sum_{i=1}^na_{ij}C_{ij}

This is a genuinely recursive definition — an n\times n determinant reduces to n determinants of size n-1 — and it's rarely how determinants are computed by hand past 3\times3 (choosing a row or column with the most zeros minimizes the work), and essentially never how software computes them (§16.5's LU decomposition gives a far cheaper route).

Key properties

  • \det I=1.
  • \det(A^T)=\det A.
  • \det(AB)=\det A\cdot\det B — determinant is multiplicative, one of its most useful properties, and notably not something addition respects (\det(A+B)\neq\det A+\det B in general).
  • Swapping two rows negates the determinant; scaling a row by c scales the determinant by c; adding a multiple of one row to another leaves the determinant unchanged — the three elementary row operations from §16.1, each with a precise, predictable effect. This is the practical way to compute large determinants: row-reduce to triangular form (tracking sign flips from swaps), then multiply the diagonal.
  • A matrix with a zero row or two identical rows has determinant 0.
  • \det A\neq0\iff A\text{ is invertible} — this is the payoff: the single-number invertibility test §16.3 was missing, and, combined with the formula A^{-1}=\frac1{\det A}\operatorname{adj}(A) (the adjugate, built from cofactors — not derived here, since Gauss-Jordan from §16.3 is the practical method), it also explains why the 2\times2 inverse formula divides by ad-bc.

Geometric meaning

|\det A| is the area (for 2\times2) or volume (for 3\times3, and n-dimensional volume in general) of the parallelogram or parallelepiped spanned by A's columns, treated as vectors from the origin. For A=\begin{pmatrix}a&b\\c&d\end{pmatrix}, the columns (a,c) and (b,d) span a parallelogram of area exactly |ad-bc|.

The sign of \det A records orientation: positive means the columns preserve the standard counterclockwise (right-handed, in 3D) orientation; negative means they flip it, like a reflection. A determinant of exactly 0 means the columns are collinear (in 2D) or otherwise fail to span the full space — no area/volume at all, they've collapsed into a lower-dimensional set — which is exactly the geometric reason a zero-determinant matrix is singular: its columns don't span enough of the space for A\vec x=\vec b to reach every target \vec b.

This is why §18.2's transformation matrices with determinant 1 (rotations) preserve area exactly, while a scaling matrix's determinant is the area scale factor directly.

Cramer's Rule

For an invertible n\times n system A\vec x=\vec b, each variable has a direct determinant formula: let A_i be A with column i replaced by \vec b. Then

x_i=\frac{\det A_i}{\det A}

For 2\times2, A\vec x=\vec b with A=\begin{pmatrix}a&b\\c&d\end{pmatrix}:

x=\frac{\det\begin{pmatrix}b_1&b\\b_2&d\end{pmatrix}}{\det A},\qquad y=\frac{\det\begin{pmatrix}a&b_1\\c&b_2\end{pmatrix}}{\det A}

Cramer's Rule is elegant and requires \det A\neq0 exactly when §16.3 already required it for an inverse to exist — but computing n+1 determinants is far more expensive than one Gaussian elimination for any system beyond a handful of variables, so it's a theoretical tool (useful for seeing how a solution depends on \vec b algebraically) rather than the practical solving method.

Doing it in Python

import numpy as np

A = np.array([[2., 1., 3.], [0., -1., 4.], [5., 2., 1.]])
print("det(A) =", round(float(np.linalg.det(A)), 4))

B = np.array([[1., 2.], [2., 4.]])  # columns are collinear
print("det(B) =", round(float(np.linalg.det(B)), 4), " (singular)")

print("det(A.T) == det(A):", np.isclose(np.linalg.det(A.T), np.linalg.det(A)))
print("det(A@A) == det(A)**2:", np.isclose(np.linalg.det(A @ A), np.linalg.det(A) ** 2))
det(A) = 17.0
det(B) = 0.0  (singular)
det(A.T) == det(A): True
det(A@A) == det(A)**2: True

Cramer's Rule, checked against direct solving:

import numpy as np

A = np.array([[2., 1.], [5., 3.]])
b = np.array([4., 9.])

detA = np.linalg.det(A)
Ax = A.copy(); Ax[:, 0] = b
Ay = A.copy(); Ay[:, 1] = b

x = np.linalg.det(Ax) / detA
y = np.linalg.det(Ay) / detA
print(f"Cramer: x={x:.4f}, y={y:.4f}")
print("direct :", [round(v, 4) for v in np.linalg.solve(A, b).tolist()])
Cramer: x=3.0000, y=-2.0000
direct : [3.0, -2.0]

Worked example

Compute \det A for A=\begin{pmatrix}1&2&3\\0&1&4\\2&0&1\end{pmatrix} by cofactor expansion along the first column (chosen for its zero).

\det A=1\det\begin{pmatrix}1&4\\0&1\end{pmatrix}-0\det\begin{pmatrix}2&3\\0&1\end{pmatrix}+2\det\begin{pmatrix}2&3\\1&4\end{pmatrix}

The middle term vanishes (multiplied by 0), so only two 2\times2 determinants are needed:

=1(1\cdot1-4\cdot0)+2(2\cdot4-3\cdot1)=1(1)+2(5)=1+10

\boxed{\det A=11}

Sanity check. Since \det A\neq0, A is invertible — expand instead along row 2 (which also has a zero, at position (2,1)), as a second route to the same number: \det A=-0(\cdots)+1\det\begin{pmatrix}1&3\\2&1\end{pmatrix}-4\det\begin{pmatrix}1&2\\2&0\end{pmatrix}=1(1-6)-4(0-4)=-5+16=11 ✓ — same answer via a completely different expansion, confirming the "expand along any row or column" claim directly.

Your turn

1. Compute \det\begin{pmatrix}3&-2\\1&5\end{pmatrix}.

2. Without expanding, explain why \det\begin{pmatrix}1&2&3\\4&5&6\\2&4&6\end{pmatrix}=0.

3. Use Cramer's Rule to solve \begin{aligned}3x+y&=7\\x-2y&=-7\end{aligned} for y only.

Solutions

1. 3(5)-(-2)(1)=15+2=17.

2. Row 3 is exactly 2\times row 1 (2(1,2,3)=(2,4,6)) — the rows are dependent, so by the "identical rows give determinant 0" property (apply it after the row operation "subtract 2\timesrow 1 from row 3," which leaves the determinant unchanged and produces an all-zero row): a zero row forces \det=0.

3. \det A=3(-2)-1(1)=-7. A_y=\begin{pmatrix}3&7\\1&-7\end{pmatrix}, \det A_y=3(-7)-7(1)=-28. y=\det A_y/\det A=-28/-7=4. (Full check: back-substituting into 3x+4=7\Rightarrow x=1, and indeed 1-2(4)=1-8=-7 ✓.)

Check yourself in code

For A=\begin{pmatrix}2&0&1\\1&3&2\\0&1&4\end{pmatrix}, print \det A and whether A is invertible.

Print exactly this:

det(A) = 21.0
invertible: True
import numpy as np

A = np.array([[2., 0., 1.], [1., 3., 2.], [0., 1., 4.]])
d = np.linalg.det(A)
print("det(A) =", round(d, 4))
# print whether A is invertible, based on the determinant
import numpy as np

A = np.array([[2., 0., 1.], [1., 3., 2.], [0., 1., 4.]])
d = np.linalg.det(A)
print("det(A) =", round(d, 4))
print("invertible:", not np.isclose(d, 0))

The determinant is a single number, computable by cofactor expansion or by row-reducing to triangular form, that is zero exactly when a matrix is singular. Geometrically it's a signed area or volume scale factor; algebraically it's multiplicative (\det(AB)=\det A\det B) and flips sign under a row swap; and Cramer's Rule turns it directly into a solution formula for small invertible systems.

Next: elementary matrices, which make precise the claim used throughout this lesson — that a row operation is itself a multiplication — and LU decomposition, which is what determinant and system-solving software actually use under the hood.