Determinant and inverse

The determinant says whether a transformation can be undone. The inverse is the undo.

What you'll learn
  • Connect a zero determinant to lost information
  • Compute an inverse two ways — by cofactors and by row reduction
  • Know when not to compute an inverse at all

The first lesson showed the determinant as an area (or volume) scaling factor. That single idea answers the most practical question you can ask about a matrix: can its transformation be undone?

If the determinant is non-zero, space is stretched or turned but nothing is lost, so there is a way back: the inverse \(A^{-1}\), with \(A^{-1}A = AA^{-1} = I\). If the determinant is zero, some direction was crushed flat. Many inputs now land on the same output, and no matrix can tell them apart again.

A transforms the grid, then A⁻¹ brings it back exactly. Push 'squash' to 1: the columns line up, the determinant reaches zero, and the grid stays collapsed because nothing can undo it.

Determinant facts from the notebook

A = np.random.randint(1, 5, (2, 2))
A[:, -1] = 2 * A[:, -2]       # dependent columns
np.linalg.det(A)              # 0: singular
  • Dependent columns ⇒ determinant 0. That is the singular case above.
  • Swapping two rows flips the sign. Orientation reverses; area does not change.
  • \(\det(AB) = \det(A)\det(B)\). Doing two transformations scales area by each factor in turn — exactly what composition predicts.

Computing the inverse

The notebook builds the inverse twice.

Minors, cofactors, adjugate (MCA). Replace each entry by the determinant of what is left when you delete its row and column, apply a checkerboard of signs, transpose, and divide by the determinant:

for i in range(m):
    for j in range(m):
        # select every row and column except i and j
        rows = [True] * m; rows[i] = False
        cols = [True] * m; cols[j] = False
        minors[i, j] = np.linalg.det(A[rows, :][:, cols])
        H[i, j] = (-1) ** (i + j)          # the checkerboard of signs

C = H * minors                             # cofactors
Ainv = C.T / np.linalg.det(A)              # adjugate over determinant

The division by \(\det A\) is the whole story in one line: when it is zero, the formula has nothing to divide by.

Row reduction. Augment \(A\) with the identity and reduce. The row operations that turn \(A\) into \(I\) turn \(I\) into \(A^{-1}\):

\[[\,A \mid I\,] \;\xrightarrow{\text{RREF}}\; [\,I \mid A^{-1}\,]\]
Aaug = Matrix(np.concatenate((A, np.eye(m, m)), axis=1))   # [A | I]
Asol = Aaug.rref()[0]
Ainvrref = Asol[:, m:m*2]                                  # the right half

The diagonal case in the notebook is the friendliest: the inverse of \(\operatorname{diag}(1, 2, \dots, 9)\) is \(\operatorname{diag}(1, \tfrac12, \dots, \tfrac19)\). Each axis is stretched independently, so each is undone independently.

Don’t invert if you don’t have to

To solve \(A\mathbf{x} = \mathbf{b}\), the formula says \(\mathbf{x} = A^{-1}\mathbf{b}\). In code, prefer

x = np.linalg.solve(A, b)     # not np.linalg.inv(A) @ b

Solving directly is faster and noticeably more accurate when the matrix is close to singular. The SVD lesson makes “close to singular” precise with the condition number.

Try it yourself. In the animation, set squash to 0.95 and watch the inverse’s entries in the read-out. Explain why they become large. Then in the notebook, compute np.linalg.inv of a matrix with determinant around \(10^{-12}\) and check how far A @ Ainv is from the identity.

View source on GitHub →