MathsLinear Algebra

Matrix Inverse
calculator.

Get the inverse of a square matrix, worked by Gauss-Jordan elimination or the adjugate.

How it's worked out

The inverse of a square matrix A is the matrix that undoes it. Interactive Linear Algebra asks for both orders to give the identity I, the matrix with 1s down the diagonal and 0s elsewhere.

AA−1\displaystyle A A^{-1}=I\displaystyle {}= I
A−1A\displaystyle A^{-1} A=I\displaystyle {}= I

Gauss-Jordan elimination writes A and I side by side as [A | I]. Then it uses row operations to turn the left block into I: swap two rows, scale a row, or add a multiple of one row to another. Every operation is done to the whole row, so the right block changes too. When the left block reaches I, the right block is the inverse.

[A|I]→[I|A−1][\,A \mid I\,] \rightarrow [\,I \mid A^{-1}\,]

If some column has no pivot, which is a nonzero entry to scale to 1, the left block can never become I and A has no inverse.

The adjugate method builds a cofactor for every entry. That is the determinant left after crossing out the entry's row and column, with a checkerboard sign. Turn rows of that cofactor matrix into columns and you have the adjugate. Divide it by det(A). Section 4.2 of the same book gives this formula and calls it a very inefficient way to compute an inverse next to row reduction.

A−1\displaystyle A^{-1}=1det⁡(A)adj⁡(A)\displaystyle {}= \frac{1}{\det(A)}\,\operatorname{adj}(A)

For a 2 by 2 matrix this is the short rule: swap the two diagonal entries, change the sign of the other two, and divide by ad − bc.

[abcd]−1\displaystyle \begin{bmatrix} a & b \\ c & d \end{bmatrix}^{-1}=1ad−bc[d−b−ca]\displaystyle {}= \frac{1}{ad - bc} \begin{bmatrix} d & -b \\ -c & a \end{bmatrix}

Worked examples

Sam uses the 2 by 2 shortcut

A\displaystyle A=[3412]\displaystyle {}= \begin{bmatrix} 3 & 4 \\ 1 & 2 \end{bmatrix}

Sam works out ad − bc as 6 − 4 = 2. Swapping 3 and 2 and changing the signs of 4 and 1 gives the adjugate. Dividing by 2 gives the inverse.

adj⁡(A)\displaystyle \operatorname{adj}(A)=[2−4−13]\displaystyle {}= \begin{bmatrix} 2 & -4 \\ -1 & 3 \end{bmatrix}
A−1\displaystyle A^{-1}=[1−2−1232]\displaystyle {}= \begin{bmatrix} 1 & -2 \\ -\frac{1}{2} & \frac{3}{2} \end{bmatrix}

The halves come from dividing by 2. When the determinant is 1 or −1, a whole-number matrix has a whole-number inverse.

Open this example in the tool

Lena inverts a 3 by 3 that starts with a zero

A\displaystyle A=[0121034−38]\displaystyle {}= \begin{bmatrix} 0 & 1 & 2 \\ 1 & 0 & 3 \\ 4 & -3 & 8 \end{bmatrix}

The top left entry is 0, so it cannot be a pivot. Lena swaps rows 1 and 2 first. After 5 row operations in all, the left block is I.

A−1\displaystyle A^{-1}=[−927−32−24−132−212]\displaystyle {}= \begin{bmatrix} -\frac{9}{2} & 7 & -\frac{3}{2} \\ -2 & 4 & -1 \\ \frac{3}{2} & -2 & \frac{1}{2} \end{bmatrix}

The determinant is −2, which is where the halves come from. She then needs x in Ax = b for b = (1, 2, 3). Multiplying the inverse by b gives x = (5, 3, −1), and the inverse is ready for any other b too.

Open this example in the tool

A matrix that is nearly singular

A\displaystyle A=[1111.0001]\displaystyle {}= \begin{bmatrix} 1 & 1 \\ 1 & 1.0001 \end{bmatrix}

The two rows are almost the same, and det(A) is only 0.0001. The inverse exists, but its largest entry is 10001.

A−1\displaystyle A^{-1}=[10001−10000−1000010000]\displaystyle {}= \begin{bmatrix} 10001 & -10000 \\ -10000 & 10000 \end{bmatrix}

Change 1.0001 to 1.0002 and the top left entry of the inverse drops to 5001. A tiny change in A moved A⁻¹ by thousands, so a measured matrix like this one gives an inverse you should not trust.

Open this example in the tool

Reading your result

No inverse is an answer too. In the matrix with rows 1, 2, 3 and 2, 4, 6 and 1, 0, 1, row 2 is twice row 1. Elimination finds only 2 pivots for 3 columns, so A is singular and det(A) = 0.

det(A⁻¹) is 1 over det(A). A matrix that stretches areas by 10 has an inverse that shrinks them by the same factor, so its determinant is 1/10.

Watch the size of the entries. Large entries in A⁻¹ next to small ones in A mean the matrix is close to singular. Rounding in your inputs then shows up, many times larger, in the inverse.

One answer for Ax = b. If A is invertible, Ax = b has exactly one solution, x = A⁻¹b. That holds for every b.

Common mistakes

  • Doing a row operation to one block only. The left and right blocks are one long row. Scale or add the whole row, or the right block is not the inverse.
  • Forgetting to transpose the cofactors. The adjugate is the cofactor matrix with rows turned into columns. For the matrix with rows 1, 2 and 3, 4 the inverse has 1 in the top right, not the cofactor in that spot.
  • Multiplying in the wrong order. The inverse of AB is B⁻¹A⁻¹, with the order reversed. Matrix products do not commute, so A⁻¹B⁻¹ is usually a different matrix.
  • Swapping rows of A and keeping the old inverse. Swapping the rows of A swaps the columns of the inverse. With the rows of Sam's matrix swapped, the inverse starts −2, 1.

Questions people ask

Work out its determinant. If det(A) is not 0, the inverse exists. Row reduction tells you the same thing: a pivot in every column means A can be reduced to I.

Sources