[Math] Finding multiplicative inverse modulo n using matrix method

discrete mathematicsmodular arithmetic

According to this video (15:17 onwards), there is a "matrix method" to find the multiplicative inverse of $a$ mod $n$ by row reducing $$\begin{bmatrix}
a & 1\\
n & 0
\end{bmatrix}$$

In the author's case, to find $97^{-1} mod\ n$, he did row operations:
$$
\left[
\begin{array}{ccc}
97 & 1\\
224 & 0
\end{array}
\right] \sim
\left[
\begin{array}{ccc}
97 & 1\\
30 & -2
\end{array}
\right] \sim
\left[
\begin{array}{ccc}
7 & 7\\
30 & -2
\end{array}
\right] \sim
\left[
\begin{array}{ccc}
7 & 7\\
2 & -30
\end{array}
\right] \sim
\left[
\begin{array}{ccc}
1 & 97\\
2 & -30
\end{array}
\right]
$$ and concluded that $97^{-1}=97$.

My question is how exactly does this method work and why didn't he row reduce traditionally into row echelon form?

Best Answer

In short, this is a compact form of the extended Euclidean algorithm (the typical way of finding modular inverses). I think the best way to see what is going on is to compare the matrix calculations to the calculations that you get coming out of the extended Euclidean algorithm.

If you get stuck, this answer by Marc van Leeuwen explains what's happening.