# 3.8 Inverting Matrices Mod *n*

Finding the inverse of a matrix mod $n$ can be accomplished by the usual methods for inverting a matrix, as long as we apply the rule given in Section 3.3 for dealing with fractions. The basic fact we need is that a square matrix is invertible mod $n$ if and only if its determinant and $n$ are relatively prime.

We treat only small matrices here, since that is all we need for the examples in this book. In this case, the easiest way is to find the inverse of the matrix is to use rational numbers, then change back to numbers mod $n\text{.}$ It is a general fact that the inverse of an integer matrix can always be written as another integer matrix divided by the determinant of the original matrix. Since we are assuming the determinant and $n$ are relatively prime, we can invert the determinant as in Section 3.3.

For example, in the $2\times 2$ case the usual formula is

so we need to find an inverse for $ad-bc\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}n)\text{.}$

# Example

Suppose we want to invert $\left(\begin{array}{cc}1& 2\\ 3& 4\end{array}\right)\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}11)\text{.}$ Since $ad-bc=-2\text{,}\text{}$ we need the inverse of $-2$ mod 11. Since $5\times (-2)\equiv 1\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}11)\text{,}\text{}$ we can replace $-1/2$ by 5 and obtain

A quick calculation shows that

# Example

Suppose we want the inverse of

The determinant is 2 and the inverse of $M$ in rational numbers is

(For ways to calculate the inverse of a matrix, look at any book on linear algebra.) We can replace 1/2 with 6 mod 11 and obtain

Why do we need the determinant and $n$ to be relatively prime? Suppose $MN\equiv I\text{\hspace{0.17em}}(\text{mod}\text{\hspace{0.17em}}n)\text{,}\text{}$ where $I$ is the identity matrix. Then

Therefore, $det(M)$ has an inverse mod $n\text{,}\text{}$ which means that $det(M)$ and $n$ must be relatively prime.