Inverse of a Matrix Using the Gauss–Jordan Method: From Idea to a Clear Algorithm

The inverse of a matrix is a tool that lets you “undo” multiplication by a matrix and recover the original object. In linear algebra problems, you often need to restore an initial vector or the solution of a system after it has been multiplied by a matrix. We’ve already looked at the approach of solving the corresponding systems of linear equations. But here’s a natural question: is there a way to work with the matrix as a single object, following a clear procedure without solving many separate systems? That is exactly what the Gauss–Jordan method does.

In this article, we’ll figure out why this approach is correct, how it is connected to elementary row operations, and what the algorithm looks like in matrix form. No unnecessary complications—just clear, consistent steps, the way you need them for confident practical use.

Inverse of a Matrix: What Exactly Are We Looking For and Why?

Let’s start with the basics. For a square matrix \( A \) (of size \( n\times n \)), the inverse matrix \( A^{-1} \) is a matrix that gives the identity matrix when multiplied. In other words, we have:

\[
A \cdot A^{-1} = I, \qquad A^{-1} \cdot A = I,
\]

where \( I \) is the identity matrix:

\[
I=
\begin{pmatrix}
1&0&\cdots&0\\
0&1&\cdots&0\\
\vdots&\vdots&\ddots&\vdots\\
0&0&\cdots&1
\end{pmatrix}.
\]

Why do we need this? For example, if you have a matrix equation \(A \cdot x = b \), then—when \( A^{-1} \) exists—the solution can be written compactly:

\[
x=A^{-1} \cdot b.
\]

This notation is short and convenient. But in practice, it’s important to have a method that allows you to find \( A^{-1} \) directly, treating the matrix as a single object. That is exactly what the Gauss–Jordan method is designed for.

Gauss–Jordan Method: Inverse of a Matrix Through Elementary Row Operations

The Gauss–Jordan method is based on elementary row operations—the same kinds of steps you use when you transform a matrix into a more convenient form. The idea is straightforward: we transform the matrix \( A \) until it becomes the identity matrix. At the same time, under those exact same transformations, another matrix is formed—and that matrix will be the inverse matrix we are looking for.

How do we set this up? First, we build an augmented matrix by attaching the identity matrix \( I \) to \( A \):

\[
\left(
\begin{array}{cccc|cccc}
a_{11} & a_{12} & \cdots & a_{1n} & 1 & 0 & \cdots & 0 \\
a_{21} & a_{22} & \cdots & a_{2n} & 0 & 1 & \cdots & 0 \\
\vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn} & 0 & 0 & \cdots & 1
\end{array}
\right).
\]

Next, we perform elementary row operations so that the left block becomes the identity matrix. The key point is that these operations are applied to every row of the augmented matrix, which means they affect both the left and the right blocks at the same time.

If the matrix \( A \) is non-singular (that is, its determinant is not zero), then in the end we obtain:

\[
\left(\begin{array}{c|c}
A & I
\end{array}\right)
\Longrightarrow
\left(\begin{array}{c|c}
I & A^{-1}
\end{array}\right),
\qquad \det(A) \ne 0.
\]

So, the right block of the final augmented matrix is exactly the inverse matrix \( A^{-1} \) we wanted to find.

Inverse of a Matrix: The Gauss–Jordan Algorithm Step by Step

Now let’s move to a more formal description. Suppose we have a square matrix of size \( n\times n \):

\[
A=\begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1n}\\
a_{21} & a_{22} & \cdots & a_{2n}\\
\vdots & \vdots & \ddots & \vdots\\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{pmatrix}.
\]

Our goal is to obtain the inverse matrix \( A^{-1} \) using a sequence of elementary row operations. To do this, as mentioned earlier, we build the augmented matrix \( \left(A\mid I\right) \), meaning we attach the identity matrix \( I \) of the same size to \( A \):

\[
\left( A \mid I \right)=
\left(
\begin{array}{cccc|cccc}
a_{11} & a_{12} & \cdots & a_{1n} & 1 & 0 & \cdots & 0 \\
a_{21} & a_{22} & \cdots & a_{2n} & 0 & 1 & \cdots & 0 \\
\vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn} & 0 & 0 & \cdots & 1
\end{array}
\right).
\]

Next, we work column by column from left to right. At each step, we choose a pivot element in the current column, make it equal to \( 1 \), and then turn all the other entries in that column into zeros—both below and above the pivot row. In the end, the left block must become \( I \), and the right block will then be \( A^{-1} \).

So, we start with the pivot element \( a_{11} \). First we make it equal to \( 1 \) (we divide the first row by \( a_{11} \)), and then we make all entries in the first column in rows \( 2,3,\dots,n \) equal to zero. After completing this step, we get a matrix of the form:

\[
\left(A^{(1)} \mid B^{(1)}\right)=
\left(
\begin{array}{cccc|cccc}
1 & a^{(1)}_{12} & \cdots & a^{(1)}_{1n} & b^{(1)}_{11} & b^{(1)}_{12} & \cdots & b^{(1)}_{1n}\\
0 & a^{(1)}_{22} & \cdots & a^{(1)}_{2n} & b^{(1)}_{21} & b^{(1)}_{22} & \cdots & b^{(1)}_{2n}\\
\vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots\\
0 & a^{(1)}_{n2} & \cdots & a^{(1)}_{nn} & b^{(1)}_{n1} & b^{(1)}_{n2} & \cdots & b^{(1)}_{nn}
\end{array}
\right).
\]

The entries in the left block after the first step are computed by:

\[
a_{ij}^{(1)} = a_{ij} – \frac{a_{i1}}{a_{11}}\,a_{1j},\qquad i=2,\dots,n,\; j=1,\dots,n.
\]

And the right block follows the same pattern:

\[
b_{ij}^{(1)} = b_{ij} – \frac{a_{i1}}{a_{11}}\, b_{1j}, \qquad i=2,\dots,n,\; j=1,\dots,n,
\]

where initially \( B^{(0)}=I \).

Next, we exclude the first row and the first column from consideration and apply the same procedure to the submatrix that starts at the element \( a^{(1)}_{22} \). Now we need to make the pivot element in position \( (2,2) \) equal to \( 1 \) and zero out all entries in the second column in rows \( i\neq2 \). After that, the second column of the left block has a \( 1 \) on the diagonal and zeros everywhere else.

Continuing in the same way for each next column, at the \( k \)-th step (for \( k=1,\dots,n \)) we work with the pivot element \( a^{(k-1)}_{kk} \) and zero out the entries in column \( k \) for all rows \( i\neq k \). For the left block, the generalized formulas are:

\[
\begin{aligned}
a^{(k)}_{kj} &= \frac{a^{(k-1)}_{kj}}{a^{(k-1)}_{kk}}, \qquad j=1,\dots,n,\\
a^{(k)}_{ij} &= a^{(k-1)}_{ij}-a^{(k-1)}_{ik}\,a^{(k)}_{kj}, \qquad i=1,\dots,n,\ i\neq k,\ j=1,\dots,n.
\end{aligned}
\]

For the right block, the formulas are analogous:

\[
\begin{aligned}
b^{(k)}_{kj} &= \frac{b^{(k-1)}_{kj}}{a^{(k-1)}_{kk}}, \qquad j=1,\dots,n,\\
b^{(k)}_{ij} &= b^{(k-1)}_{ij}-a^{(k-1)}_{ik}\,b^{(k)}_{kj}, \qquad i=1,\dots,n,\ i\neq k,\ j=1,\dots,n.
\end{aligned}
\]

After performing the steps \( k=1,2,\dots,n \), the left block of the augmented matrix becomes the identity matrix:

\[
\left( A^{(n)} \mid B^{(n)} \right)=\left( I \mid A^{-1} \right).
\]

So, the right block after all transformations is the desired inverse matrix \( A^{-1} \).

What If the Pivot Element Is Zero?

In practice, it can happen that the pivot element you want to start eliminating with (for example, \( a_{11} \), or later \( a^{(1)}_{22} \), \( a^{(2)}_{33} \), and so on) is equal to zero. In that situation, it is enough to swap rows so that a nonzero number moves into the pivot position. Since a row swap is an elementary operation, the algorithm can then continue in the usual way.

But if, in the given column, all possible candidates for the pivot element are zero, then it is impossible to turn the left block into \( I \). That means the inverse matrix does not exist (the matrix \( A \) is singular).

Inverse of a Matrix in Practice: From Row Operations to the Final Answer

Now let’s move to practice, because the Gauss–Jordan method becomes truly clear when you see it in action. We will work with the augmented matrix \( \left(A\mid I\right) \) and step by step transform the left block into \( I \).

Example 1. Find the inverse of a matrix

\[
A=
\begin{pmatrix}
2 & -1 & 4 \\
4 & -2 & 8 \\
6 & -3 & 12
\end{pmatrix}.
\]

We write the augmented matrix:

\[
\left(A^{(0)}\mid B^{(0)}\right)=
\left(
\begin{array}{ccc|ccc}
2 & -1 & 4 & 1 & 0 & 0 \\
4 & -2 & 8 & 0 & 1 & 0 \\
6 & -3 & 12 & 0 & 0 & 1
\end{array}
\right).
\]

We start with the pivot element \( a_{11}=2 \). We divide the first row by \( 2 \), and then we zero out the first column in rows \( 2 \) and \( 3 \):

  • From the second row we subtract the first row multiplied by \( 4 \).
  • From the third row we subtract the first row multiplied by \( 6 \).

This gives:

\[
\left(A^{(1)} \mid B^{(1)}\right)=
\left(
\begin{array}{ccc|ccc}
1 & -0.5 & 2 & 0.5 & 0 & 0 \\
0 & 0 & 0 & -2 & 1 & 0 \\
0 & 0 & 0 & -3 & 0 & 1
\end{array}
\right).
\]

Here you can see the key point: in the left block, zero rows have appeared, but in the right block the corresponding rows are not zero. This means it is impossible to transform the left block into \( I \), so the inverse of \( A \) does not exist. The reason is clear: the rows of the matrix are linearly dependent (the second row is \( 2 \) times the first, and the third row is \( 3 \) times the first).

Example 2. Find the inverse of a matrix

\[
A=
\begin{pmatrix}
5 & -6 & 7 & 1\\
7 & 10 & -9 & 8\\
3 & 3 & 5 & 1\\
-10 & 2 & 3 & 4
\end{pmatrix}.
\]

We write the augmented matrix:

\[
\left(A^{(0)} \mid B^{(0)}\right)=
\left(
\begin{array}{cccc|cccc}
5 & -6 & 7 & 1 & 1 & 0 & 0 & 0 \\
7 & 10 & -9 & 8 & 0 & 1 & 0 & 0 \\
3 & 3 & 5 & 1 & 0 & 0 & 1 & 0 \\
-10 & 2 & 3 & 4 & 0 & 0 & 0 & 1
\end{array}
\right).
\]

At the first step, we make the pivot element in position \( (1,1) \) equal to \( 1 \) and eliminate the first column in the other rows:

  • From the second row we subtract the first row multiplied by \( 7 \).
  • From the third row we subtract the first row multiplied by \( 3 \).
  • To the fourth row we add the first row multiplied by \( 10 \).

After that we have:

\[
\left(A^{(1)}\mid B^{(1)}\right)=
\left(
\begin{array}{cccc|cccc}
1.&-1.2&1.4&0.2&0.2&0&0&0\\
0&18.4&-18.8&6.6&-1.4&1&0&0\\
0&6.6&0.8&0.4&-0.6&0&1&0\\
0&-10&17&6&2&0&0&1
\end{array}
\right).
\]

Next we move to the second column: we normalize the pivot element in position \( (2,2) \) and zero out all other entries in that column:

  • To the first row we add the second row multiplied by \( 1.2 \).
  • From the third row we subtract the second row multiplied by \( 6.6 \).
  • To the fourth row we add the second row multiplied by \( 10 \).

We obtain:

\[
\left(A^{(2)}\mid B^{(2)}\right)=
\left(
\begin{array}{cccc|cccc}
1&0&0.174&0.63&0.109&0.065&0&0\\
0&1&-1.022&0.359&-0.076&0.054&0&0\\
0&0&7.543&-1.967&-0.098&-0.359&1&0\\
0&0&6.783&9.587&1.239&0.543&0&1
\end{array}
\right).
\]

After similar transformations for the third and fourth columns, the left block becomes the identity matrix, and the right block becomes the desired inverse. In the end:

\[
\left(A^{(4)}\mid B^{(4)}\right)=
\left(
\begin{array}{cccc|cccc}
1&0&0&0&0.032&0.022&0.030&-0.060\\
0&1&0&0&-0.1&-0.001&0.143&-0.008\\
0&0&1&0&0.018&-0.028&0.112&0.023\\
0&0&0&1&0.117&0.076&-0.079&0.088
\end{array}
\right),
\]

so

\[
A^{-1}\approx
\begin{pmatrix}
0.032 & 0.022 & 0.030 & -0.060 \\
-0.100 & -0.001 & 0.143 & -0.008 \\
0.018 & -0.028 & 0.112 & 0.023 \\
0.117 & 0.076 & -0.079 & 0.088
\end{pmatrix}.
\]

Example 3. Find the inverse of a matrix

\[
A=
\begin{pmatrix}
0 & -1 & 3 & 0 & 2 \\
2 & -4 & 1 & 5 & 3 \\
-4 & 5 & 7 & -10 & 0 \\
-2 & 1 & 8 & -5 & 3
\end{pmatrix}.
\]

Here it is important to stop right away and check the dimensions. This matrix has \( 4 \) rows and \( 5 \) columns, so it is not square. But an inverse matrix is defined only for square matrices of size \( n\times n \). Therefore, for this \( A \), the inverse matrix \( A^{-1} \) does not exist, and the Gauss–Jordan method in its standard form cannot be applied here.

Where to Go Next: Topics That Will Strengthen Your Skills

If you enjoyed working with inverse matrices, it makes perfect sense to move on to related topics and expand your toolbox for solving problems. Where should you start so that it’s genuinely useful? Below are three directions that naturally continue the same theme and help you see other approaches to finding the inverse matrix.

  1. Inverse of a Matrix Using Cofactors: The Logic of Minors and Determinants — We’ll look at the classical method based on minors and cofactors so you can clearly understand how the final answer is constructed.
  2. Inverse of a Matrix and the Characteristic Polynomial: An Unusual but Powerful Approach — We’ll explain how the inverse is connected to the characteristic polynomial and show how this idea can be used in practice.
  3. Inverse of a Matrix by the Bordering Method: How Adding Rows and Columns Leads to the Result — We’ll present the main idea of the bordering method and explain how the inverse matrix can be obtained through step-by-step expansion.

From Theory to Code: The Inverse Matrix in Your Program

If you’re interested in programming, try turning this flowchart into a small program that finds an inverse matrix using the Gauss–Jordan method. It’s a genuinely useful exercise, because you immediately see how a mathematical algorithm behaves with real numbers during computation.

Pick your favorite language—Python, PHP, JavaScript, or C++—and build a mini calculator: you enter a matrix, run the computation, and get \( A^{-1} \) as the output. And if you also print the intermediate matrices at each step, it becomes even more interesting to compare the result with manual calculations.

A flowchart of the algorithm that shows, step by step, how the inverse of a matrix is computed using the Gauss–Jordan method

Leave a Reply

Your email address will not be published. Required fields are marked *