Search

Search papers and lessons

Matrix Inverse

Level 2 · 9 min read

The inverse of a square matrix is the matrix that undoes it, and it exists exactly when the determinant is not zero. It turns a system of linear equations into a single formula.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

A matrix AA is a rule that moves vectors around. Its inverse, written A−1A^{-1}, is the rule that moves them back. Multiplying by AA and then by A−1A^{-1} (in either order) leaves every vector unchanged, and that identity action is written II. A square matrix has an inverse exactly when its determinant is not zero.

The inverse is the matrix version of dividing by a number. It is the cleanest way to write the solution of a linear system: if Ax=bA\mathbf{x} = \mathbf{b}, then x=A−1b\mathbf{x} = A^{-1}\mathbf{b}. Where you'll see it: in solving equations for fitted models, in changing coordinates in graphics and robotics, and in the covariance formulas of multivariate statistics.

Intuition

Think of a matrix as a machine that takes a point and returns a new point. Rotating every point by 30 degrees is a machine. To undo it, rotate by minus 30 degrees. That second machine is the inverse. Stretching the horizontal direction by 2 is undone by shrinking it by one half. Shearing a shape sideways is undone by shearing it back.

Some machines cannot be undone. If a matrix squashes the plane onto a line, then every line of points running along the squashed direction lands on a single spot. Once two different inputs give the same output, no rule can recover the input from the output. The determinant is the test for this: a zero determinant means area has been squashed to zero, so the map has lost information.

Why care? Equations of the form Ax=bA\mathbf{x} = \mathbf{b} ask: which input x\mathbf{x} does the machine AA turn into b\mathbf{b}? If the machine can be undone, the answer is A−1bA^{-1}\mathbf{b}, one step, for any b\mathbf{b}. The inverse turns "solve this equation" into "apply that machine".

−3−2−10123−3−2−10123xy
  • original square corners
  • after the stretch by 2
A stretch of the horizontal direction by 2 maps the square to a rectangle. Applying the inverse, a squeeze by one half, returns it to the square.

The math

Definition

Definition: Matrix inverse

Let AA be an n×nn \times n matrix and let II be the n×nn \times n identity matrix, which has ones on the diagonal and zeros elsewhere. The matrix AA is invertible (or nonsingular) if there is a matrix A−1A^{-1} such that

AA−1=A−1A=I.A A^{-1} = A^{-1} A = I.

If no such matrix exists, AA is singular.

Both products must equal II. For square matrices, one of them implies the other, but the definition states both. The inverse is unique: if two matrices both undo AA, they are equal.

When the inverse exists

A square matrix is invertible if and only if its determinant is nonzero:

A−1 exists  ⟺  det⁡A≠0.A^{-1} \text{ exists} \iff \det A \neq 0.

Equivalently, the columns of AA are linearly independent: none of them is a combination of the others. A zero determinant means some direction has been collapsed.

The 2 by 2 formula

For a 2×22 \times 2 matrix with det⁡A=ad−bc≠0\det A = ad - bc \neq 0,

(abcd)−1=1ad−bc(d−b−ca).\begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad - bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix}.

Swap the diagonal entries, negate the off-diagonal ones, and divide by the determinant. You can check it by multiplying out: the product is II.

Rules that follow from the definition

  • (AB)−1=B−1A−1(AB)^{-1} = B^{-1} A^{-1}. The order reverses, just as when you undo a sequence of steps: undo the last one first.
  • (A−1)−1=A(A^{-1})^{-1} = A.
  • det⁡(A−1)=1/det⁡A\det(A^{-1}) = 1 / \det A.
  • (AT)−1=(A−1)T(A^{\mathsf{T}})^{-1} = (A^{-1})^{\mathsf{T}}.

Gauss-Jordan elimination

For larger matrices, write the augmented block [ A∣I ][\,A \mid I\,] and apply row operations (swap rows, scale a row, add a multiple of one row to another) until the left block becomes II. The right block is then A−1A^{-1}. If you reach a row of zeros on the left, AA is singular.

Solving linear systems

If AA is invertible, the system Ax=bA\mathbf{x} = \mathbf{b} has exactly one solution:

x=A−1b.\mathbf{x} = A^{-1}\mathbf{b}.

Multiply both sides by A−1A^{-1} on the left. The left side becomes x\mathbf{x} because A−1A=IA^{-1}A = I.

Worked examples

Example
Inverting a 2 by 2 matrix

Let A=(4726)A = \begin{pmatrix} 4 & 7 \\ 2 & 6 \end{pmatrix}.

  1. Determinant: ad−bc=4⋅6−7⋅2=24−14=10ad - bc = 4 \cdot 6 - 7 \cdot 2 = 24 - 14 = 10. It is nonzero, so the inverse exists.
  2. Apply the formula: A−1=110(6−7−24)=(0.6−0.7−0.20.4)A^{-1} = \frac{1}{10} \begin{pmatrix} 6 & -7 \\ -2 & 4 \end{pmatrix} = \begin{pmatrix} 0.6 & -0.7 \\ -0.2 & 0.4 \end{pmatrix}.
  3. Check the top-left entry of AA−1A A^{-1}: 4⋅0.6+7⋅(−0.2)=2.4−1.4=14 \cdot 0.6 + 7 \cdot (-0.2) = 2.4 - 1.4 = 1.
  4. Check the top-right entry: 4⋅(−0.7)+7⋅0.4=−2.8+2.8=04 \cdot (-0.7) + 7 \cdot 0.4 = -2.8 + 2.8 = 0.
  5. Check the bottom row: 2⋅0.6+6⋅(−0.2)=02 \cdot 0.6 + 6 \cdot (-0.2) = 0 and 2⋅(−0.7)+6⋅0.4=12 \cdot (-0.7) + 6 \cdot 0.4 = 1.

So AA−1=IA A^{-1} = I. Interpretation: A−1A^{-1} is the exact undo of the machine AA, and it can be used on any input.

Example
Solving a system with the inverse

Solve 4x+7y=14x + 7y = 1 and 2x+6y=02x + 6y = 0. In matrix form this is Ax=bA\mathbf{x} = \mathbf{b} with AA from the previous example and b=(1,0)\mathbf{b} = (1, 0).

  1. The inverse is A−1A^{-1} from the previous example.
  2. Compute x=A−1b=(0.6−0.7−0.20.4)(10)=(0.6−0.2)\mathbf{x} = A^{-1}\mathbf{b} = \begin{pmatrix} 0.6 & -0.7 \\ -0.2 & 0.4 \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 0.6 \\ -0.2 \end{pmatrix}.
  3. Check the first equation: 4(0.6)+7(−0.2)=2.4−1.4=14(0.6) + 7(-0.2) = 2.4 - 1.4 = 1. ✓
  4. Check the second equation: 2(0.6)+6(−0.2)=1.2−1.2=02(0.6) + 6(-0.2) = 1.2 - 1.2 = 0. ✓

Interpretation: x=0.6x = 0.6 and y=−0.2y = -0.2. If a new right-hand side arrives, say (0,1)(0, 1), the same A−1A^{-1} gives the new answer with one multiplication. This reuse is the main reason to know the inverse.

Example
A singular matrix

Let B=(2412)B = \begin{pmatrix} 2 & 4 \\ 1 & 2 \end{pmatrix}.

  1. Determinant: 2⋅2−4⋅1=02 \cdot 2 - 4 \cdot 1 = 0. So BB has no inverse.
  2. Look at the system Bx=(1,0)B\mathbf{x} = (1, 0), that is 2x+4y=12x + 4y = 1 and x+2y=0x + 2y = 0.
  3. The first equation is twice the second, so 2x+4y2x + 4y must equal 2⋅0=02 \cdot 0 = 0. The system asks for it to equal 1.
  4. The two equations contradict each other, so there is no solution.

Interpretation: the second column of BB is twice the first, so BB maps the plane onto a line. Outputs off that line are unreachable, and the inverse cannot exist.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Solving Ax=bA\mathbf{x} = \mathbf{b} for one b\mathbf{b}Forming A−1A^{-1} costs more and loses accuracySolve directly, for example with an LU factorization
Determinant is tiny but not zeroRounding errors are amplified and the answer can be wrongCheck the condition number; use a better-conditioned formulation
Matrix is not squareNo inverse existsUse the Moore-Penrose pseudoinverse for least-squares problems
Matrix is triangularNothing special, but the inverse is easyUse back substitution
Matrix is nearly singular in a fitting problemEstimates blow upAdd a small penalty term, as in ridge regression
Deciding "is it singular?" from floating-point numbersA determinant that should be zero comes out as 10−1610^{-16}Use the rank, computed from a singular value decomposition

The most common mistake is computing an inverse when a solve is enough. Numerical libraries expose a direct solver for Ax=bA\mathbf{x} = \mathbf{b}, and it is both faster and more accurate. Use the explicit inverse for theory and for small matrices where you need the formula itself.

History

Gaussian elimination, the row-reduction method at the heart of computing inverses, appears in Chinese mathematical texts such as The Nine Chapters on the Mathematical Art, compiled in the first centuries CE. Carl Friedrich Gauss later used the elimination method in his work on least squares, in the early 1800s. Arthur Cayley's 1858 memoir on matrices defined matrix multiplication and the inverse in the modern way. The name Gauss-Jordan elimination, the variant that continues reducing until the left block is the identity, credits Wilhelm Jordan, who described it in his 1888 handbook of geodesy. The pseudoinverse for non-square matrices was introduced by E. H. Moore in 1920 and rediscovered by Roger Penrose in 1955. The inverse caught on because it turns a whole family of linear problems into one reusable operation.

Check yourself

QuestionFor which 2×22 \times 2 matrices is the inverse guaranteed not to exist?Show answer

Exactly those whose determinant ad−bcad - bc equals zero. Then the columns are parallel or one of them is zero, and the map squashes the plane onto a line.

QuestionCompute the determinant of (3152)\begin{pmatrix} 3 & 1 \\ 5 & 2 \end{pmatrix} and then its inverse.Show answer

The determinant is 3⋅2−1⋅5=13 \cdot 2 - 1 \cdot 5 = 1. The inverse is 11(2−1−53)=(2−1−53)\frac{1}{1}\begin{pmatrix} 2 & -1 \\ -5 & 3 \end{pmatrix} = \begin{pmatrix} 2 & -1 \\ -5 & 3 \end{pmatrix}. Check the top-left entry of the product: 3⋅2+1⋅(−5)=13 \cdot 2 + 1 \cdot (-5) = 1.

QuestionWhy does (AB)−1(AB)^{-1} equal B−1A−1B^{-1}A^{-1} and not A−1B−1A^{-1}B^{-1}?Show answer

Think of ABAB as doing BB first and then AA. To undo it you must undo the last step first, which is AA, and then undo BB. That order is the product B−1A−1B^{-1}A^{-1}. Check it directly: (B−1A−1)(AB)=B−1(A−1A)B=B−1B=I(B^{-1}A^{-1})(AB) = B^{-1}(A^{-1}A)B = B^{-1}B = I.

QuestionA matrix CC has determinant 0.50.5. What is det⁡(C−1)\det(C^{-1})?Show answer

det⁡(C−1)=1/det⁡C=1/0.5=2\det(C^{-1}) = 1 / \det C = 1 / 0.5 = 2. Scaling area by 0.50.5 in one step is undone by scaling by 22.

QuestionA least-squares fit of a model with two parameters needs to invert the 2×22\times 2 matrix XTXX^{\mathsf{T}}X built from the data, and its determinant is 10−1210^{-12} even though the data values are of order 1. Why might a direct inverse be a poor idea?Show answer

The determinant is so close to zero relative to the entries that the inverse has entries of large size, and rounding errors in the data get multiplied by those entries. The parameter estimates can become unstable. Solve with a numerically stable method, check the condition number, or add a small penalty term so the matrix is well away from singular.

Sources