Matrix size
2x2
A=
 ⌈ a₁ b₁ ⌉ ⌊ a₂ b₂ ⌋
First row
a₁
b₁
Second row
a₂
b₂
Result
Determinant |A|

# Matrix Determinant Calculator

By Maciej Kowalski, PhD candidate

Welcome to the matrix determinant calculator, where you'll have a chance to compute, well, matrix determinants, using the easy to use determinant formula for any square matrix up to 4x4 in size. Also, we'll look into some of the basic properties of determinants that can help with solve larger ones, such as the determinant of a 4x4 matrix.

"What is a determinant, and why should I care?" We'll show you the determinant definition in a little while, but let's just say that, among other uses, it is extremely helpful when dealing with systems of equations. Basically, how to solve a system of three equations is the same as how to find the determinant of a 3x3 matrix.

Convinced? Encouraged? Excited? Let's move on then, shall we?

## What is a determinant?

Why don't we start with what a matrix is? Believe it or not, it's not only the sci-fi classic from the '90s. In mathematics, it's the name we give to an array of elements (usually numbers) with a set number of rows and columns. An example of a matrix is

A =
 ⌈ 3 -1 ⌉ | 0 2 ｜ ⌊ 1 -1 ⌋

As you can see, the numbers are arranged between two big square brackets, `[` and `]`. Also, we say that, for example, the number `2` is in the cell in the second row and the second column.

The determinant definition states that it is a number that is obtained by multiplying and adding the cells of a square matrix according to a given rule. Let's take a closer look at a few important things here.

• As the determinant definition suggests, we need to have a square matrix to even start the calculations. This means that we can find the determinant of a 2x2 matrix or the determinant of a 4x4 matrix, but not, for example, of something that looks like the `A` above, which is a 3x2 (three rows and two columns) matrix;
• The determinant formula for larger matrices gets quite complicated. Its number of summands is equal to the number of permutations of the number that is the matrix's side. This means that the determinant of a 2x2 matrix has only two summands, but for 5x5 matrices, we get 120 summands;
• There are ways to make the calculations easier. For example, finding the determinant of a 4x4 matrix can be changed into the problem of how to find the determinant of a 3x3 matrix. We'll look into some such properties of determinants in "Properties of determinants" section; and
• The determinant of a matrix, `A` is denoted by `|A|` (simply replace the square brackets of a matrix with vertical lines `|`) or `det(A)`. Do not mistake the first notation with the absolute value! In general, the determinant can be a negative number.

So, what is a determinant? It's a number, we've learnt that much. But why is it useful? Where does it appear?

The matrix determinant is an extremely helpful and often-used tool in linear algebra. Whenever we have a matrix and want to understand it, the determinant is one of the first things we turn to. For instance, every system of linear equations can be described by a matrix, and its determinants help us find the solution, for example, by using Cramer's rule. Moreover, when we use matrices to describe a linear transformation, it's often best to diagonalize them. How do we do that? With determinants, of course. Lastly, we usually need the eigenvalues of such a transformation. Yes, you guessed it - for that, we also use determinants.

Hopefully, we've managed to convince you that it's worthwhile to learn the determinant definition. But how do we calculate it? Is there some short, neat determinant formula for everyday use?

## The general determinant formula

Before we see some specific examples, like how to find the determinant of a 3x3 matrix, let's take a look at the monstrosity that is the general determinant definition.

Let `A` be a square matrix of size `n`, where `n` is some natural number. Denote the cells of `A` by ai,j, where `i` is the number of the row, and `j` is the number of the column. Then:

|A| = Σ (-1)sgn(σ) Π ai,σ(i)

where,

• `Σ` is the some of all permutations of the set `{1,2,...,n}`; and
• `Π` is the product of `i`-s from `1` to `n`.

Pretty, isn't it? If we translate the funny symbols into something more understandable, it means more or less this:

To calculate the determinant, look at your matrix, take `n` numbers, one from each row and every column, and multiply them together. Take all such `n`-tuples, change their sign sometimes, and sum it all up.

Don't worry, now that we've put this general determinant definition out into the open, we'll not think about it anymore. We'll stick to the easy cases, where the matrix is not too big, to show what it really means.

## The determinant of a 2x2, 3x3, and 4x4 matrix

As it often is in life, size matters. In this particular case, the smaller the matrix, the easier the determinant formula. For consistency, we have used the same notation below as in the matrix determinant calculator.

If

A =
 ⌈ a₁ b₁ ⌉ ⌊ a₂ b₂ ⌋

then the determinant of `A` is

`|A| = a₁*b₂ - a₂*b₁`.

Note, that this is equivalent to taking the numbers of one of the diagonals of the square matrix (from the top left corner to the bottom right) minus the other one (from the top right corner to the bottom left).

Next, if

 ⌈ a₁ b₁ c₁ ⌉ B = | a₂ b₂ c₂ ｜ ⌊ a₃ b₃ c₃ ⌋

then the determinant of `B` is

`|B| = a₁*b₂*c₃ + a₂*b₃*c₁ + a₃*b₁*c₂ - a₃*b₂*c₁ - a₁*b₃*c₂ - a₂*b₁*c₃`.

Here again we can use some diagonals to remember the formula. To see it clearly, let's write the two top rows again beneath the matrix:

 | a₁ b₁ c₁ ｜ | a₂ b₂ c₂ ｜ | a₃ b₃ c₃ ｜ a₁ b₁ c₁ a₂ b₂ c₂

Now, as in the 2x2 case, start with the diagonal of the original square matrix, that goes from the top left corner to the bottom right - this is the first summand, `a₁*b₂*c₃`. Then we take this whole diagonal and move it one step down, i.e., in each column take the element under the one we took before. Here the expanded array we drew above helps us to see that this gives the second summand, `a₂*b₃*c₁`. We do this one more time to get `a₃*b₁*c₂` and this finishes the down-right diagonals and the summands that appear with a plus.

Next, we move on to the other diagonal of the original matrix (from the top right corner to the bottom left) and get the first negative summand in the formula, `a₃*b₂*c₁`. We do the same thing as before - moving the diagonal down. The expanded form above let's us easily see that this gives the other two negative summands, `a₁*b₃*c₂` and `a₂*b₁*c₃`.

Lastly, if

C =
 ⌈ a₁ b₁ c₁ d₁ ⌉ | a₂ b₂ c₂ d₂ ｜ | a₃ b₂ c₃ d₃ ｜ ⌊ a₄ b₄ c₄ d₄ ⌋

then the determinant of such a 4x4 matrix is

`|C| = a₁*b₂*c₃*d₄ - a₂*b₁*c₃*d₄ + a₃*b₁*c₂*d₄ - a₁*b₃*c₂*d₄ + a₂*b₃*c₁*d₄ - a₃*b₂*c₁*d₄ + a₃*b₂*c₄*d₁ - a₂*b₃*c₄*d₁ + a₄*b₃*c₂*d₁ - a₃*b₄*c₂*d₁ + a₂*b₄*c₃*d₁ - a₄*b₂*c₃*d₁ + a₄*b₁*c₃*d₂ - a₁*b₄*c₃*d₂ + a₃*b₄*c₁*d₂ - a₄*b₃*c₁*d₂ + a₁*b₃*c₄*d₂ - a₃*b₁*c₄*d₂ + a₂*b₁*c₄*d₃ - a₁*b₂*c₄*d₃ + a₄*b₂*c₁*d₃ - a₂*b₄*c₁*d₃ + a₁*b₄*c₂*d₃ - a₄*b₁*c₂*d₃`.

Whew, that was a long one, wasn't it? You can see now that it's super easy to find the determinant of a 2x2 matrix, and we can learn how to find the determinant of a 3x3 matrix in an hour or so. But the determinant of a 4x4 matrix is a whole new problem. Don't get us wrong, it's perfectly doable, but who's going to pay us for that time spent calculating and, later, looking for where we took `a₁` instead of `a₂`?

So, how do we use the diagonal trick here? The answer is simple: we don't. Unfortunately, it doesn't work for matrices of that are 4 or larger.

"So, how can I efficiently calculate what is a 4x4 determinant? Or 5x5?" Well, how convenient of you to ask! We'll show you that in the next section.

## Properties of determinants

We'll now list a few important properties of determinants that may come useful. We begin with simple ones and bring out the big guns at the very end.

1. The determinant of a product is the product of the determinants. In other words, if we multiply two square matrices and want to find the determinant of the result, then we can get the answer by calculating the determinants of the factors and multiplying them together.

2. The determinant of a matrix is equal to that of its transpose. In essence, if instead of the matrix we started with, we "flip it", so that its first row will be the first column, the first column will be the first row, etc. (this is called the transposition of a matrix), then their determinants will be the same. For example:

 | 1 4 -1 ｜ | 1 0 6 ｜ | 0 2 -3 ｜ = | 4 2 11 ｜ | 6 11 5 ｜ | -1 -3 5 ｜
1. If we exchange two rows or two columns, the determinant will stay the same, but with the opposite sign. This means that, for instance, if we want to know how to find the determinant of a 3x3 matrix, then we can exchange, say, its first column with its third to obtain the same number, but with a different sign (see the example below).
 | 1 4 -1 ｜ | -1 4 1 ｜ | 0 2 -3 ｜ = - | -3 2 0 ｜ | 6 11 5 ｜ | 5 11 6 ｜
1. We can add any non-zero multiple of a row to some other row (or a column to a column) and not change the determinant. This is similar to what we do in Gaussian elimination when we want to find the row echelon form of a system of equations, except that there we only dealt with rows (which corresponded to equations). This property means that if we add, say, two copies of the first row to the second one, we'll obtain a matrix with the same determinant. For example:
 | 1 4 -1 ｜ | 1 4 -1 ｜ | 0 2 -3 ｜ = | 0+2*1 2+2*4 -3+2*(-1) ｜ | 6 11 5 ｜ | 6 11 5 ｜

which gives,

 | 1 4 -1 ｜ | 1 4 -1 ｜ | 0 2 -3 ｜ = | 2 10 -5 ｜ | 6 11 5 ｜ | 6 11 5 ｜
1. (Laplace expansion) Remember the "What is a determinant of a 5x5 matrix?" question from the above section? Finally, we can touch upon this topic and introduce a powerful tool to help us with the determinant formula.

Let `A` be a square matrix of size `n`. Say that the `j`-th row (or column) of `A` has elements `a₁`, `a₂`,...,`aₙ`. Denote by `Aᵢ` the matrix obtained from `A` by removing the whole row and column in which we had `aᵢ` (`Aᵢ` is then a square matrix of size `n-1`). Then

|A| = (-1)j+1 * a₁ * |A₁| + (-1)j+2 * a₂ * |A₂| + ... + (-1)j+n * aₙ * |Aₙ|.

Now that's a useful tool if we've ever seen one. And it's quite fun to use! For example, if they ask us how to find the determinant of a 3x3 matrix, we can grab a piece of paper, pick, say, the third row of the matrix, and write enthusiastically:

 | 1 4 -1 ｜ | 0 2 -3 ｜ | 6 11 5 ｜
= (-1)3+1*6*
 | 4 -1 ｜ | 2 -3 ｜
+
+(-1)3+2*11*
 | 1 -1 ｜ | 0 -3 ｜
+(-1)3+3*5*
 | 1 4 ｜ | 0 2 ｜

It must have taken ages to read through all this theory, so why don't we finally look at an example?

## Example: using the matrix determinant calculator

Say that you want to calculate the determinant of the following matrix:

A =
 ⌈ 2 5 1 3 ⌉ | 4 1 7 9 ｜ | 6 8 3 2 ｜ ⌊ 7 8 1 4 ⌋

The determinant of a 4x4 matrix, huh? We saw the determinant formula for one in the section "The determinant of a 2x2, 3x3, and 4x4 matrix", so we know it's not going to be very entertaining, is it? But we've learnt some properties of determinants since then, so why don't we make them work in our favor?

Before we do that, however, let's use the matrix determinant calculator to see how our tool simplifies such problems. First of all, we're dealing with a 4x4 matrix, so we need to tell that to the calculator by choosing the appropriate option under "Matrix size."

This will show us an example of such a matrix with symbolic notation for its elements. As we can see, `a₁`, `b₁`, `c₁`, and `d₁` denote the numbers in the first row, so let's scroll to where we input data and feed the matrix determinant calculator with what we have in our exercise:

`a₁ = 2`, `b₁ = 5`, `c₁ = 1`, `d₁ = 3`.

Similarly, for the other rows, we have:

`a₂ = 4`, `b₂ = 1`, `c₂ = 7`, `d₂ = 9`,

`a₃ = 6`, `b₃ = 8`, `c₃ = 3`, `d₃ = 2`,

`a₄ = 7`, `b₄ = 8`, `c₄ = 1`, `d₄ = 4`.

The moment we write the last number, the matrix determinant calculator will do its magic and spit out the answer:

`|A| = 630`.

Alright, now that we have this spoiler of an answer, let's see how we can obtain this answer by hand. Obviously, one way is to simply use the 24-term determinant formula, but we'd like some extra points for creativity and want to use the properties of determinants.

We'll use the Laplace expansion, but in a clever way. We pick an arbitrary row or column, say the first row of the matrix, and try to make the expansion a little easier. After all, if we use the formula straight away, we'll get the sum of four 3x3 determinants. Not terrible, but not great either. We can, however, do something first - use elementary column operations.

We've seen in the above section that if we add any non-zero multiple of a column to another column, the determinant will stay the same. So why don't we add a `(-2)`-multiple of the third column to the first one?

|A| =
 | 2+(-2)*1 5 1 3 ｜ | 4+(-2)*7 1 7 9 ｜ | 6+(-2)*3 8 3 2 ｜ | 7+(-2)*1 8 1 4 ｜

which gives,

|A| =
 | 0 5 1 3 ｜ | -10 1 7 9 ｜ | 0 8 3 2 ｜ | 5 8 1 4 ｜

And why have we done that? Recall that in the Laplace expansion, the summands were like this: `(-1)` to some power times the element of the row or column we've chosen times a smaller determinant. Therefore, if we now expand `|A|` with respect to the first row, the summand corresponding to the first cell in the first row will be `(-1)` to some power times `0` times some determinant. And this is zero because anything times zero is zero.

Great, we've reduced the number of summands by one! So how about we repeat the procedure and get even fewer? To do that, we want to have more zeros in the first row, so let's make the `5` and the `3` into `0`-s. As we did before, we add to those columns the right multiple of the third column (the one with `1`):

|A| =
 | 0 5+(-5)*1 1 3+(-3)*1 ｜ | -10 1+(-5)*7 7 9+(-3)*7 ｜ | 0 8+(-5)*3 3 2+(-3)*3 ｜ | 5 8+(-5)*1 1 4+(-3)*1 ｜

which gives,

|A| =
 | 0 0 1 0 ｜ | -10 -34 7 -12 ｜ | 0 -7 3 -7 ｜ | 5 3 1 1 ｜

Now this is more like it! With this form, if we use the Laplace expansion to the first row, we'll only get one summand because the three others will be `0` times something, which is `0`. To be precise, we get

|A| = (-1)1+3*1*
 | -10 -34 -12 ｜ | 0 -7 -7 ｜ | 5 3 1 ｜

And we know quite well how to find the determinant of a 3x3 matrix, don't we? But remember that if you'd like to have some more fun, you could use the Laplace expansion again to get a determinant of a 2x2 matrix. Otherwise, we can just use the determinant formula and based on the above get:

`|A| = (-1)⁴ * (-10*(-7)*1 + (-34)*(-7)*5 + (-12)*0*5 - (-12)*(-7)*5 - (-10)*(-7)*3 - (-34)*0*1) = 630`.

Yay, it agrees with what we had above! See how much time the matrix determinant calculator can save us? Do you know how many pages of our favorite book we could have read in that time?

Maciej Kowalski, PhD candidate