Skip to content

Determinant and Trace

Before we factor matrices, we need two numbers that summarize them: the determinant and the trace. The determinant measures how much a matrix scales volume (and whether it can be inverted); the trace sums its diagonal. Both are invariant under basis change, which is why they capture something intrinsic about a linear map — and both turn out to be built from the matrix’s eigenvalues.

A real-life example: does a mixture have a unique recipe?

You blend two base syrups to hit a target flavor with two properties (sweetness, acidity). Each syrup contributes a known amount of each. If the two syrups affect the properties in genuinely different ways, there’s a unique blend — but if one syrup is just a scaled version of the other, their “flavor vectors” are collinear and no unique recipe exists. The determinant of the 2×22\times2 recipe matrix is exactly the test: nonzero → unique blend, zero → no unique solution.

The determinant

The determinant det(A)\det(A) (also written A|A|) is defined only for square matrices. Small cases have closed forms:

det[a]=a,det[abcd]=adbc,\det[a] = a, \qquad \det\begin{bmatrix}a & b\\ c & d\end{bmatrix} = ad - bc,

and for 3×33\times3, Sarrus’ rule:

det[a11a12a13a21a22a23a31a32a33]=a11a22a33+a12a23a31+a13a21a32a31a22a13a32a23a11a33a21a12.\det\begin{bmatrix}a_{11}&a_{12}&a_{13}\\a_{21}&a_{22}&a_{23}\\a_{31}&a_{32}&a_{33}\end{bmatrix} = a_{11}a_{22}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{21}a_{32} - a_{31}a_{22}a_{13} - a_{32}a_{23}a_{11} - a_{33}a_{21}a_{12}.

For a triangular matrix, the determinant is just the product of the diagonal, det(T)=iTii\det(T) = \prod_i T_{ii} — which is why we compute large determinants by row-reducing to triangular form. Larger matrices use recursive Laplace expansion along a row or column.

The determinant is signed volume

The most useful picture: det(A)\det(A) is the signed volume of the shape spanned by the columns of AA. In 2-D that’s the area of the parallelogram formed by the two column vectors. Watch the area as one column rotates — it shrinks to zero exactly when the columns become collinear (a singular, non-invertible matrix), and the sign flips when their orientation flips:

sketch The determinant as signed area p5.js
The parallelogram spanned by a matrix's two columns. Its area is |det|; the sign encodes orientation. When the columns line up (collinear), the area is 0 — the matrix is singular and non-invertible.

That zero-area moment is the whole story of invertibility.

Determinant properties

  • det(AB)=det(A)det(B)\det(AB) = \det(A)\det(B) — determinant of a product is the product of determinants.
  • det(A)=det(A)\det(A^\top) = \det(A) — transposition doesn’t change it.
  • det(A1)=1/det(A)\det(A^{-1}) = 1/\det(A) when AA is invertible.
  • Similar matrices have the same determinant — so it’s invariant under basis change.
  • Adding a multiple of one row to another leaves det\det unchanged; scaling a row by λ\lambda scales det\det by λ\lambda; swapping two rows flips the sign.

Two headline theorems tie it to earlier chapters:

A is invertible    det(A)0    rk(A)=n.A \text{ is invertible} \iff \det(A) \neq 0 \iff \text{rk}(A) = n.

The trace

The trace is the sum of the diagonal entries:

tr(A)=i=1naii.\text{tr}(A) = \sum_{i=1}^n a_{ii}.

It’s linear (tr(A+B)=tr(A)+tr(B)\text{tr}(A+B) = \text{tr}(A) + \text{tr}(B)) and — crucially — invariant under cyclic permutation: tr(AKL)=tr(KLA)\text{tr}(AKL) = \text{tr}(KLA). In particular tr(AB)=tr(BA)\text{tr}(AB) = \text{tr}(BA) even when ABBAAB \neq BA, and tr(S1AS)=tr(A)\text{tr}(S^{-1}AS) = \text{tr}(A), so the trace is also basis-independent.

The bridge to eigenvalues

The characteristic polynomial pA(λ)=det(AλI)p_A(\lambda) = \det(A - \lambda I) is where determinant and trace meet eigenvalues (next page). Two beautiful identities fall out:

det(A)=i=1nλi,tr(A)=i=1nλi.\det(A) = \prod_{i=1}^n \lambda_i, \qquad \text{tr}(A) = \sum_{i=1}^n \lambda_i.

The determinant is the product of the eigenvalues; the trace is their sum. Volume scaling = product of stretches; that’s the geometry made precise.

diagram Diagram mermaid

NumPy

det_trace.py
import numpy as np
 
A = np.array([[4.0, 2.0],
              [1.0, 3.0]])
 
print("det:", np.linalg.det(A))          # 10.0
print("trace:", np.trace(A))             # 7.0
 
# invertible iff det != 0
print("invertible:", not np.isclose(np.linalg.det(A), 0))
 
# det = product of eigenvalues, trace = sum of eigenvalues
eig = np.linalg.eigvals(A)
print("eigenvalues:", np.round(eig, 4))
print("prod eig ≈ det :", np.isclose(np.prod(eig), np.linalg.det(A)))
print("sum  eig ≈ trace:", np.isclose(np.sum(eig), np.trace(A)))
 
# a singular matrix has det 0
S = np.array([[1.0, 2.0], [2.0, 4.0]])   # second column = 2 * first row-wise -> collinear
print("singular det:", round(np.linalg.det(S), 6))
det_trace.py
import numpy as np
 
A = np.array([[4.0, 2.0],
              [1.0, 3.0]])
 
print("det:", np.linalg.det(A))          # 10.0
print("trace:", np.trace(A))             # 7.0
 
# invertible iff det != 0
print("invertible:", not np.isclose(np.linalg.det(A), 0))
 
# det = product of eigenvalues, trace = sum of eigenvalues
eig = np.linalg.eigvals(A)
print("eigenvalues:", np.round(eig, 4))
print("prod eig ≈ det :", np.isclose(np.prod(eig), np.linalg.det(A)))
print("sum  eig ≈ trace:", np.isclose(np.sum(eig), np.trace(A)))
 
# a singular matrix has det 0
S = np.array([[1.0, 2.0], [2.0, 4.0]])   # second column = 2 * first row-wise -> collinear
print("singular det:", round(np.linalg.det(S), 6))
text
det: 10.000000000000002
trace: 7.0
invertible: True
eigenvalues: [2. 5.]
prod eig ≈ det : True
sum  eig ≈ trace: True
singular det: 0.0
text
det: 10.000000000000002
trace: 7.0
invertible: True
eigenvalues: [2. 5.]
prod eig ≈ det : True
sum  eig ≈ trace: True
singular det: 0.0

Why this matters for ML

  • Gaussian densities and normalizing flows need det\det of a covariance / Jacobian to normalize probabilities — the log-det term shows up in nearly every likelihood.
  • Invertibility checks: a zero (or tiny) determinant flags singular / ill-conditioned matrices that break linear solves and blow up regression coefficients.
  • The trace appears in loss functions (e.g. tr(AA)=AF2\text{tr}(A^\top A) = \lVert A\rVert_F^2), regularizers, and the cyclic trace trick that simplifies gradient derivations.

🧪 Try It Yourself

Exercise 1 – Determinant and invertibility

Exercise 2 – det = product of eigenvalues

Exercise 3 – Trace is the sum of eigenvalues

Recap

  • The determinant is the signed volume a matrix scales space by; det=0\det = 0 ⇔ singular ⇔ not full rank ⇔ no inverse.
  • det(AB)=detAdetB\det(AB) = \det A \det B, det(A)=detA\det(A^\top) = \det A, and it’s basis-invariant.
  • The trace sums the diagonal, is cyclic-invariant, and basis-independent.
  • det(A)=λi\det(A) = \prod \lambda_i and tr(A)=λi\text{tr}(A) = \sum \lambda_i — both are built from eigenvalues.

Next: those eigenvalues and the directions they belong to — Eigenvalues and Eigenvectors.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did