# #004 Linear Algebra – The determinant

## #004 Linear Algebra – The determinant

Highlight: In this post we will explain what the determinant is and why we use it in linear algebra. We will give an interpretation of a determinant both in a 2-D and in a 3-D space. Also, we will show how to implement these calculations in Python.

Tutorial Overview:

### 1. Determinant in a 2-D coordinate system

In the previous post we saw how a linear transformation can change our coordinate system and how it can transform our basis vectors. In addition, sometimes we would like to have a description and more intuition of such linear transformations. In other words, we are interested to see if the area of one object is changed under a linear transformation. For instance, we see that a rotation doesn’t change an area at all. On the other hand, some other transformations do change. Then, we would like to have a measure that tells us how much the area in one coordinate system is changed in another, linearly transformed, coordinate system. For instance, let’s take a dilation as an operation, and in this case, we can observe how much some object does change. To do this, we will keep track of a unit square, defined by basis vectors, and how it is transformed under a dilation operation.

In this case, a unit square will be mapped into a rectangle of size 6. Hence, we can say that the area has increased 6 times.

In the case of a shear, a unit square is mapped into a unit parallelogram. This is due to the fact that the area of the parallelogram is a “length x height”. So, in this case the area will remain the same, but the square will be stretched.

Ok. This is for a unit square. But, what is happening for some object in general?

To answer this question we will use the following reasoning. First, every unit square will behave in the same manner as the basis one does. So, every grid square of size 1 will preserve the area of 1 and will be mapped into a parallelogram under shear operation. One trick that we can apply is to fine-sample every object until it is completely covered by squares.

We see that every transformed square will behave exactly in the same manner. That means, for instance, if our unit square is scaled with a factor of $$1$$ every other square of area one will not change its area, but will be changed into a parallelogram. This is illustrated in the image below for an arbitrary linear transformation.

So, this new area that we get, we will call a determinant of a transformation because it actually determines how much our new unit square will be in size. For instance, this is one simple transformation that rotates and extends our axes. The rotation is given by the transformation matrix written below. We can see that the transformation doubled area of our unit square.

In the previous posts we saw that a linear transformation can map a 2-D space into a single line. So, what is the value of the determinant in that case? Obviously the area of a single line is actually $$0$$. We can prove this by looking at the transformation matrix and we can see that these two column vectors are dependent. If that is the case, we will obtain a transformation that maps our 2-D plane to the line. Then, the determinant of such linear transformation is $$0$$.

However, there is one small detail related to determinants. It can happen that with some transformation we actually get a determinant to be a negative number. And this happens for transformations that doesn’t preserve the order of $$\hat{i}$$ and $$\hat{j}$$. In the starting positions $$\hat{j}$$ is to the left of $$\hat{i}$$. On the other hand, if after a transformation $$\hat{j}$$ is to the right of $$\hat{i}$$ the orientation of the space has been reversed.

A nice intuition about the determinant and its sign we can get with the following experiment. Imagine that we start stretching a unit square to some position defined with the left image below. The more we stretch the point of a parallelogram (opposite of the coordinate origin) and move it closer to the y axis, the value of the determinant is getting smaller and smaller. Once we “cross” on the other side of the y axis, we actually obtain a reversed order of axes and the determinant becomes negative. If we continue this process, our parallelogram is increasing its size, but the sign of the determinant remains negative. This is illustrated in the right image below.

### 2. Determinant in a 3-D coordinate system

Now, you can ask yourself what is actually happening in a 3-D space? We have volumes there, right? Well, the idea is quite similar. Instead of an area that we used to calculate determinant for the plane, in a 3-D space we actually use determinant to calculate a volume. Now, instead of a unit square we have a unit cube. Thus, our determinant will tell us how much the volume of that unit cube will change when we apply a linear transformation. So, we will get something called parallelepiped. This can be one illustrated with the image below, and how we can change and transform our 3-D space.

Here, again, a determinant can be negative. Again, this can happen with the inverse order of the axes. In addition, the difference is that now we also have three vectors of size 3. One way to calculate it is to decompose as a linear combination of three determinants of 2×2 matrices.

We do not provide a numerical examples in this post. For that we refer to introductory Linear Algebra book by Gilbert Strang.

#### Summary

In this post, we have introduced an important tool in linear algebra. Determinants are easy to calculate and are usually used to verify whether some conditions are fulfilled. For instance, whether a linear transformation maps a plane into a plane or into a line. In the next post, we will learn further explorations and applications of these concepts. 