Determinant of a Matrix Using Gaussian Elimination: Step-by-Step from Theory to Examples

The determinant of a matrix is a numerical value associated with a square matrix that reveals essential properties about it. With the help of the determinant, we can determine whether a matrix is invertible, estimate its rank, and analyze its eigenvalues and eigenvectors. But why is this so important? Because behind every matrix, there’s often a real-world problem — a system of linear equations, a model in physics, economics, engineering, or many other fields.

When you know how to quickly calculate the determinant of a matrix, you can work more confidently with linear models and numerical methods. However, calculating the determinant directly using cofactor expansion formulas can become quite tedious — especially for large matrices. So a natural question arises: can we turn this into a step-by-step algorithm that works just as well on paper as it does in code?

This is where the Gaussian elimination method becomes incredibly useful. It helps us replace complex formulas with a sequence of simple row operations. In this article, we’ll walk through how to find the determinant of a matrix using Gaussian elimination, what rules you absolutely need to remember, and how to avoid common pitfalls like division by zero.

Gaussian Elimination: Determinant of a Matrix through Row Operations

You’re probably already familiar with the Gaussian elimination method from your linear algebra course — it’s typically used to solve systems of linear equations by transforming the matrix into a triangular or row-echelon form. But why not use the same idea when we want to calculate the determinant of a matrix?

Here’s the basic idea: we perform a series of row operations to transform the matrix into an upper triangular form. In this form, all the entries below the main diagonal are zeros. At this point, an important rule kicks in — the determinant of an upper triangular matrix is simply the product of the entries on its main diagonal.

However, not all row operations affect the determinant in the same way. That’s why you need to keep in mind three key rules:

  • When you multiply a row by a number, the determinant is also multiplied by that number.
  • If you swap two rows (or two columns), the sign of the determinant changes.
  • Adding to one row another row multiplied by a scalar does not change the value of the determinant.

This third type of operation is the most convenient when we want to preserve the value of the determinant without extra adjustments. So, when using Gaussian elimination to compute a determinant, we try to rely mostly on this operation, while carefully keeping track of any row multiplications or swaps in the final formula.

Gaussian Elimination Algorithm: Step-by-Step to Calculating the Determinant of a Matrix

Now let’s move on to the formal process. Suppose we have a square matrix of size \( n×n \):

\[
A = \begin{pmatrix}
a_{11} & a_{12} & a_{13} & \dots & a_{1n} \\
a_{21} & a_{22} & a_{23} & \dots & a_{2n} \\
a_{31} & a_{32} & a_{33} & \dots & a_{3n} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & a_{n3} & \dots & a_{nn}
\end{pmatrix};
\]

Our goal is to use a sequence of elementary row operations to transform this matrix into an upper triangular one.

We begin by eliminating all the entries below the first diagonal element \( a_{11} \) in the first column. To do this, we take rows \( 2,3,…,n \), and replace each one with a new version. Specifically, we add the first row multiplied by \( -\frac{a_{21}}{a_{11}}, -\frac{a_{31}}{a_{11}}, \dots, -\frac{a_{n1}}{a_{11}} \) to rows \( 2 \) through \( n \), respectively. After this step, the matrix looks like this:

\[
A = \begin{pmatrix}
a_{11} & a_{12} & a_{13} & \dots & a_{1n} \\
0 & a^{(1)}_{22} & a^{(1)}_{23} & \dots & a^{(1)}_{2n} \\
0 & a^{(1)}_{32} & a^{(1)}_{33} & \dots & a^{(1)}_{3n} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
0 & a^{(1)}_{n2} & a^{(1)}_{n3} & \dots & a^{(1)}_{nn}
\end{pmatrix};
\]

The updated elements with the superscript “(1)” are calculated using the formula:

\[
a^{(1)}_{ij} = a_{ij} – \frac{a_{i1}}{a_{11}} \cdot a_{1j};
\quad i = 2, \dots, n; \quad j = 1, \dots, n;
\]

Next, we ignore the first row and column and repeat the same process with the submatrix starting at element \( a^{(1)}_{22} \). The task is to eliminate all the entries below \( a^{(1)}_{22} \) in the second column. After this step, the matrix becomes:

\[
A = \begin{pmatrix}
a_{11} & a_{12} & a_{13} & \dots & a_{1n} \\
0 & a^{(1)}_{22} & a^{(1)}_{23} & \dots & a^{(1)}_{2n} \\
0 & 0 & a^{(2)}_{33} & \dots & a^{(2)}_{3n} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
0 & 0 & 0 & \dots & a^{(n-1)}_{nn}
\end{pmatrix};
\]

Where:

\[
a^{(2)}_{ij} = a^{(1)}_{ij} – \frac{a^{(1)}_{i2}}{\,a^{(1)}_{22}\,} \cdot a^{(1)}_{2j};
\quad i = 3, \dots, n; \quad j = 2, \dots, n;
\]

We continue this process for each subsequent column. On the \( (n-1) \)-th step, the matrix takes on a triangular form:

\[
A = \begin{pmatrix}
a_{11} & a_{12} & a_{13} & \dots & a_{1n} \\
0 & a^{(1)}_{22} & a^{(1)}_{23} & \dots & a^{(1)}_{2n} \\
0 & 0 & a^{(2)}_{33} & \dots & a^{(2)}_{3n} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
0 & 0 & 0 & \dots & a^{(n-1)}_{nn}
\end{pmatrix};
\]

The general formula for computing the elements at step \( k \) is:

\[
a^{(k)}_{ij} = a^{(k-1)}_{ij} – \frac{a^{(k-1)}_{ik}}{a^{(k-1)}_{kk}} \cdot a^{(k-1)}_{kj};
\quad k = 1,\dots,n;\quad i = k+1,\dots,n;\quad j = k,\dots,n;
\]

Once the matrix has been transformed into upper triangular form, the determinant of a matrix is calculated as the product of the diagonal elements (taking into account any multipliers or row swaps made during the process):

\[
\det(A) = a_{11} \cdot a^{(1)}_{22} \cdot a^{(2)}_{33} \cdots a^{(n-1)}_{nn};
\]

And that’s how we arrive at a compact computational formula for the determinant — directly linked to the Gaussian elimination algorithm.

Challenges in Calculation: Division by Zero and Row Swaps

In practice, using the Gaussian method to compute the determinant of a matrix doesn’t always go smoothly. At some point in the process, a diagonal element might turn out to be zero. This causes a major issue because it leads to division by zero in the calculation formulas — which is, of course, not allowed.

To avoid this situation, there are modified versions of the algorithm that involve swapping elements — known as partial and full pivoting.

  • Partial Pivoting. At each step, we look for the element with the largest absolute value in the current column, below the current diagonal position. Then, we swap rows to move this “better” element into the diagonal position. This helps us avoid division by zero and improves numerical stability.
  • Full Pivoting. This goes one step further. At each step, we search the entire remaining submatrix — the part to the right and below the current diagonal — for the element with the largest absolute value. We then swap not only rows but also columns to move this element into the diagonal position. While this approach is even more effective at preventing division by zero, it makes the algorithm more complex and computationally demanding.

Using either partial or full pivoting reduces the chances of encountering zero on the diagonal, but it does increase the overall number of operations. So choosing the right approach depends on the size of the matrix, the required level of accuracy, and the available computing resources.

One more important point — you need to track the sign of the determinant. As mentioned earlier, every time you swap two rows or two columns, the sign of the determinant flips. So if you use partial or full pivoting during Gaussian elimination, make sure to count how many swaps you’ve performed. If the number is odd, multiply the final product of the diagonal elements by \( -1 \). If it’s even, the sign stays the same.

Applying Gaussian Elimination: Determinant of a Matrix in Practice

Theory gives us the big picture, but true understanding comes when you actually work through problems yourself. So let’s now shift to the practical side and see how Gaussian elimination works when calculating the determinant of a matrix in real examples. In each case, we’ll follow the transformations step by step and explain how the final determinant is formed.

Example 1: What is the core idea of using Gaussian elimination to find the determinant?

The method is based on performing a series of elementary row operations to transform the matrix into a triangular form. At each step, we eliminate the elements below the main diagonal by adding a multiple of one row to another. The result is an upper triangular matrix, and the determinant of such a matrix is simply the product of the elements on the main diagonal.

Example 2: Calculate the determinant of a 4×4 matrix

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

We begin by working on the first column. The goal is to eliminate all entries below the element \( a_{11} = 1 \). To do that, we add row \( 1 \) multiplied by \( -3 \) to row \( 2 \), and row \( 1 \) multiplied by \( -5 \) to row \( 3 \). Row \( 4 \) already has a zero in the first column, so it stays unchanged. After these transformations, the matrix becomes:

\[
A = \begin{pmatrix}
1 & 5 & 3 & -4 \\
0 & -14 & -11 & 12 \\
0 & -32 & -15 & 30 \\
0 & 3 & -5 & 0
\end{pmatrix};
\]

Next, we move to the second column and eliminate the entries below the diagonal element \( a^{(1)}_{22} = -14 \). To do this, we add row \( 2 \) multiplied by \( -2.286 \) to row \( 3 \), and row \( 2 \) multiplied by \( 0.214 \) to row \( 4 \). The resulting matrix is:

\[
A = \begin{pmatrix}
1 & 5 & 3 & -4 \\
0 & -14 & -11 & 12 \\
0 & 0 & 10.146 & 2.568 \\
0 & 0 & -7.354 & 2.568
\end{pmatrix};
\]

Now we move on to the third column. We need to eliminate the element \( a^{(2)}_{43} = -7.354 \). To do that, we add row \( 3 \) multiplied by \( 0.725 \) to row \( 4 \). After this final transformation, the matrix is in upper triangular form:

\[
A = \begin{pmatrix}
1 & 5 & 3 & -4 \\
0 & -14 & -11 & 12 \\
0 & 0 & 10.146 & 2.568 \\
0 & 0 & 0 & 4.43
\end{pmatrix};
\]

Now, the determinant can be calculated as the product of the diagonal elements:

\[
\det(A) = 1 \cdot (-14) \cdot 10.146 \cdot 4.43 = -629.225;
\]

So, the determinant of matrix \( A \) is \( -629.225 \).

Example 3: Calculate the determinant of a 5×5 matrix

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

Just like before, we try to eliminate the entries below the main diagonal in the first column. But here we immediately run into a problem: the first diagonal element is zero. That means we’d have to divide by zero when calculating the necessary coefficients — which we obviously can’t do.

So, what should we do in this case? We use the partial pivoting strategy. That means we rearrange the rows to place a non-zero element in the top-left position. For example, let’s swap row \( 1 \) with row \( 2 \). The new matrix becomes:

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

Now the first diagonal element is non-zero, so we can proceed with Gaussian elimination without running into division by zero. After performing the necessary row operations to reduce the matrix to upper triangular form, we get:

\[
A = \begin{pmatrix}
5 & 6 & 7 & 8 & 9 \\
0 & 1 & 2 & 3 & 4 \\
0 & 0 & 2 & 0 & 5 \\
0 & 0 & 0 & -12 & -6.5 \\
0 & 0 & 0 & 0 & -4.292
\end{pmatrix};
\]

Now, we can calculate the determinant as the product of the diagonal elements. But don’t forget — we performed one row swap, so we need to multiply the result by \( -1 \) to correct the sign. That gives us:

\[
\det(A) = (-1) \cdot 5 \cdot 1 \cdot 2 \cdot (-12) \cdot (-4.292) = -515.04;
\]

Therefore, the determinant of matrix \( A \) is \( -515.04 \).

After the Determinant of a Matrix: Where to Go Next in Linear Algebra

If you’re starting to feel more confident with Gaussian elimination and how to calculate the determinant of a matrix, then it’s the perfect time to take the next step forward. There’s so much more to explore in linear algebra, and diving deeper will help you see how these concepts are used to solve real-world problems. Below are some recommended directions that naturally follow this topic. Choose the one that sparks your interest and continue learning step by step.

  1. Inverse Matrix and the Determinant: When Does a Matrix Have an Inverse — Learn how a non-zero determinant is directly related to whether a matrix has an inverse. This connection plays a key role in analyzing and solving different types of mathematical problems.
  2. Systems of Equations and the Determinant of a Matrix: Cramer’s Rule in Action — Discover how determinants are used in Cramer’s rule to check whether a system of equations has a solution — and how to find that solution one step at a time.
  3. Other Applications of Gaussian Elimination: Finding the Inverse Matrix through Row Operations — See how the same method used for calculating the determinant can also be applied to compute the inverse of a matrix, all while keeping track of the original matrix’s properties.

These topics will deepen your understanding and help you make connections between theory and practice — exactly what makes linear algebra so powerful and exciting to learn.

Determinant of a Matrix and Code: From Flowchart to Working Program

If you’re into programming, the flowchart for computing the determinant of a matrix using Gaussian elimination can be a fantastic hands-on exercise. Take a close look at each block in the diagram, follow the path from the input matrix to the final result, and imagine how each part of the flowchart could turn into a line of code in your favorite programming language. Doesn’t it sound exciting to write a small program in Python, C++, Java, or any other language — and calculate the determinant of matrices of different sizes with just one click?

Trying this out will not only strengthen your understanding of how Gaussian elimination works but also help you develop algorithmic thinking. You’ll move beyond just applying formulas — you’ll start thinking in terms of logic, structure, and step-by-step processes. And that’s exactly what programming is all about.

Flowchart showing the step-by-step algorithm for calculating the determinant of a matrix using Gaussian elimination