Gradium × TensorTonic Voice Challenge is open for registration.Register now
Modules
03/11
Linear Algebra

Contents

Determinants & Inverses

Understanding when transformations can be reversed.

By Pratham Grover

Last updated 13 November 2026

What does the determinant tell you?

The determinant of a square matrix tells you how much the matrix scales area or volume, and whether it can be inverted. A determinant of zero means the matrix squashes space into fewer dimensions, so it has no inverse and the system Ax=bAx = b has either no solution or infinitely many; any non-zero determinant means the inverse exists and the system has exactly one solution. On TensorTonic you compute determinants and solve linear systems from scratch, with tests that check your output.

Why determinants matter

The determinant of a matrix is a single number that captures something fundamental: does this transformation preserve the "full dimensionality" of space, or does it collapse some dimensions?

If the determinant is zero, the matrix is singular: it squashes space into a lower dimension, and there is no way to undo this. If the determinant is nonzero, the transformation is reversible, and we can compute the inverse.

The Central Question

Can we solve Ax=bAx = b for any bb? The answer is yes if and only if det⁡(A)≠0\det(A) \neq 0.

Geometric Interpretation

Geometrically, the determinant measures how a matrix scales areas (in 2D) or volumes (in 3D). For a 2×2 matrix with columns v1v_1 and v2v_2, ∣det⁡(A)∣|\det(A)| is the area of the parallelogram spanned by those vectors.

det⁡>0\det > 0

Transformation preserves orientation. Vectors maintain their "handedness" (right-hand rule).

det⁡<0\det < 0

Transformation flips orientation. Like looking in a mirror.

det⁡=0\det = 0

Transformation collapses at least one dimension. The parallelogram has zero area (it is a line or a point). Information is lost irreversibly.

det⁡[abcd]=ad−bc\det \begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc
The 2×2 determinant formula: product of diagonal minus product of anti-diagonal.

Interactive: Determinant

Drag the sliders to change the matrix entries. Watch how the unit square transforms into a parallelogram, and see how the determinant tracks the signed area.

det(A) = (1.5)(1.0) - (0.5)(0.2)1.40
The red and green vectors are the transformed basis vectors. The colored area is the determinant. If the vectors swap order (relative to clockwise/counter-clockwise), the area becomes negative.

Properties of Determinants

Determinants obey several useful rules that make computation efficient.

  1. Multiplicativity: det⁡(AB)=det⁡(A)det⁡(B)\det(AB) = \det(A) \det(B)
  2. Transpose: det⁡(AT)=det⁡(A)\det(A^T) = \det(A)
  3. Inverse: det⁡(A−1)=1/det⁡(A)\det(A^{-1}) = 1/\det(A)
  4. Row swap: Swapping two rows negates the determinant.
  5. Row scaling: Multiplying a row by kk multiplies det by kk.
  6. Triangular matrices: det = product of diagonal entries.

Computational Insight

Direct computation of a determinant is O(n!)O(n!) via cofactor expansion. In practice, we use LU decomposition: factor A=LUA = LU, then det⁡(A)=det⁡(L)×det⁡(U)\det(A) = \det(L) \times \det(U) = product of pivots. This is O(n3)O(n^3).

Matrix Inverse

The inverse of a matrix AA is the matrix A−1A^{-1} such that AA−1=A−1A=IA A^{-1} = A^{-1} A = I. It "undoes" the transformation performed by AA.

A−1=1det⁡(A)[d−b−ca]A^{-1} = \frac{1}{\det(A)} \begin{bmatrix} d & -b \\ -c & a \end{bmatrix}
The 2×2 inverse formula: swap diagonals, negate anti-diagonals, divide by det.

Existence

A−1A^{-1} exists if and only if det⁡(A)≠0\det(A) \neq 0.

Uniqueness

When it exists, the inverse is unique.

Interactive: Inverse

Adjust the matrix and watch its inverse update in real time. Note: when det approaches 0, the inverse entries explode (become very large), a hallmark of numerical instability.

Input Space (x)
x = [1.0, 1.0]
A
A⁻¹
Output Space (b)
b = [2.0, 1.5]

Matrix A

det: 1.25

Inverse A⁻¹

0.80
-0.40
-0.40
1.20

Notice: A⁻¹ is calculated as 1/det * adj(A). When det approaches 0 (singular), the division creates massive numbers (instability), making it impossible to "undo" the transform reliably.

How do you compute a determinant and an inverse? Worked 2×2 and 3×3 examples

A 2×2 example

For A=[4726]A = \begin{bmatrix} 4 & 7 \\ 2 & 6 \end{bmatrix}, the determinant is ad−bc=4⋅6−7⋅2=10ad - bc = 4 \cdot 6 - 7 \cdot 2 = 10, so the matrix is invertible. Swapping the diagonal entries, negating the off-diagonal ones and dividing by 10 gives A−1=110[6−7−24]=[0.6−0.7−0.20.4]A^{-1} = \frac{1}{10} \begin{bmatrix} 6 & -7 \\ -2 & 4 \end{bmatrix} = \begin{bmatrix} 0.6 & -0.7 \\ -0.2 & 0.4 \end{bmatrix}, and multiplying the two returns the identity matrix.

A 3×3 example

For B=[201132112]B = \begin{bmatrix} 2 & 0 & 1 \\ 1 & 3 & 2 \\ 1 & 1 & 2 \end{bmatrix}, expanding along the first row gives det⁡(B)=2(3⋅2−2⋅1)−0+1(1⋅1−3⋅1)=8−2=6\det(B) = 2(3 \cdot 2 - 2 \cdot 1) - 0 + 1(1 \cdot 1 - 3 \cdot 1) = 8 - 2 = 6. Because the determinant is non-zero, Bx=bBx = b has exactly one solution, and for b=(3,6,4)b = (3, 6, 4) that solution is x=(1,1,1)x = (1, 1, 1). The inverse is B−1=16[41−303−3−2−26]B^{-1} = \frac{1}{6} \begin{bmatrix} 4 & 1 & -3 \\ 0 & 3 & -3 \\ -2 & -2 & 6 \end{bmatrix}.

Changing the bottom-right entry from 2 to 1 drops the determinant to 2(3−2)+(1−3)=02(3 - 2) + (1 - 3) = 0, because the third row becomes one third of the sum of the first two rows, so that matrix is singular and has no inverse. In practice, ML code solves systems with np.linalg.solve rather than computing an inverse explicitly, because it is faster and more numerically stable.

Python
import numpy as np

A = np.array([[4.0, 7.0],
              [2.0, 6.0]])
print("det(A) =", round(np.linalg.det(A), 4))
print("A^-1 =
", np.linalg.inv(A).round(4))

B = np.array([[2.0, 0.0, 1.0],
              [1.0, 3.0, 2.0],
              [1.0, 1.0, 2.0]])
b = np.array([3.0, 6.0, 4.0])
print("det(B) =", round(np.linalg.det(B), 4))
print("solution of Bx = b:", np.linalg.solve(B, b).round(4))
Output
det(A) = 10.0
A^-1 =
 [[ 0.6 -0.7]
 [-0.2  0.4]]
det(B) = 6.0
solution of Bx = b: [1. 1. 1.]

Singular Matrices

A matrix with det⁡=0\det = 0 is called singular. Several equivalent statements all describe this condition:

  • det(A) = 0
  • A is not invertible
  • The columns of A are linearly dependent
  • The null space of A is nontrivial (more than just zero)
  • Ax = b has either no solution or infinitely many solutions
  • At least one eigenvalue is zero

Numerical Reality

In practice, we rarely check if det = 0 exactly. Instead, we look at the condition number of A, which measures how close A is to being singular. High condition number means small changes in b cause large changes in x.

ML Applications

Covariance Matrices

In multivariate Gaussians, the det of the covariance matrix appears in the normalizing constant. A singular covariance means the distribution is degenerate (lives on a lower dimensional subspace).

Regularization

Ridge regression adds λI\lambda I to XTXX^TX before inverting. This ensures the matrix is invertible even if X has collinear features. Learn why.

Jacobian Determinant

In normalizing flows (generative models), we transform a simple distribution through invertible layers. The log det of the Jacobian appears in the loss function.

PCA Feature Collapse

If data covariance is singular (det = 0), some principal components have zero variance. PCA then reduces dimensionality naturally.

Frequently asked questions about determinants and inverses

What does a determinant of zero mean?

A determinant of zero means the matrix is singular, so it squashes space into fewer dimensions and has no inverse. The system Ax = b then has either no solution or infinitely many.

Why does ML code use np.linalg.solve instead of computing the inverse?

Solving the system directly with np.linalg.solve is faster and more numerically stable than computing an inverse explicitly. As the determinant approaches zero, the entries of the inverse explode, which is a hallmark of numerical instability.

Practice this

On TensorTonic you implement this from scratch and test it in the browser.