ml.lab
Python sleeps until you run code
03 Determinants, inverses and rank

Lesson 1 of 4

The determinant

One number says how much a transformation scales area and whether it turns the plane over. When that number is zero, the transformation destroys information and nothing can undo it.

About 40 minutes
By the end you can
  • Read the determinant of a 2x2 matrix as the signed area of the image of the unit square.

  • Explain what a negative determinant and a zero determinant do to space.

  • Show that a zero determinant and lost information are the same event.

  • Derive ad−bcad - bc from the parallelogram picture, and use it.

In the last module you watched matrices bend a grid. A stretch pulled it wider, a shear slid it sideways, a rotation turned it. One matrix did something more drastic: it flattened the whole plane onto a single line.

Here is a question to hold on to. After a transformation, can you get back to where you started? After a shear, yes: shear back the other way. After the flattening, no. Many different points landed on the same spot, and nothing in the output says which one each came from.

One number decides this, and it has a picture: how much the transformation scales area. That number is the determinant. By the end of this lesson you will compute it by hand and in code, read its sign, and know exactly why zero is the dangerous value.

Area scaling

We start with the picture, because every fact in this lesson comes from it.

A reminder from module 2. A 2x2 matrix A\mathbf{A} sends the basis vector ı^=(1,0)\hat{\imath} = (1,\allowbreak 0) to its first column and ȷ^=(0,1)\hat{\jmath} = (0,\allowbreak 1) to its second column. The unit square is the square with corners (0,0)(0,\allowbreak 0), (1,0)(1,\allowbreak 0), (1,1)(1,\allowbreak 1) and (0,1)(0,\allowbreak 1): its two sides from the origin are ı^\hat{\imath} and ȷ^\hat{\jmath}. So A\mathbf{A} turns the unit square into the parallelogram whose sides from the origin are the two columns.

The widget below answers one question: when a matrix moves the plane, how much bigger or smaller does area get? The faint square grid is the plane before the matrix acts. The blue and coral lines are the same grid after it. The blue arrow Aı^\mathbf{A}\hat{\imath} is column 1 and the coral arrow Aȷ^\mathbf{A}\hat{\jmath} is column 2, and you can drag their tips. The white shape is where the unit square lands, and the area readout is its area. The matrix starts at A=[2101.5]\mathbf{A} = \begin{bmatrix} 2 & 1 \\ 0 & 1.5 \end{bmatrix}.

Two facts hold for every matrix you try.

  1. Every grid square turns into a copy of the same parallelogram, moved to a new place. So every grid square has its area multiplied by the same number.
  2. That number is the area of the parallelogram the unit square becomes.

Together they say that one number describes what A\mathbf{A} does to the area of any shape at all: a circle, a triangle, a blob. The box below proves the first fact, since everything else rests on it.

Go slower: Why every shape is scaled by the same factor

Call DD the area of the parallelogram that the unit square becomes.

Step 1, a small square anywhere. Take a square of side hh whose bottom-left corner is at a point p\mathbf{p}. Its corners are p\mathbf{p}, p+hı^\mathbf{p} + h\hat{\imath}, p+hȷ^\mathbf{p} + h\hat{\jmath} and p+hı^+hȷ^\mathbf{p} + h\hat{\imath} + h\hat{\jmath}, and its area is h2h^2.

Step 2, push each corner through A\mathbf{A}. Linearity splits each product into pieces. For example A(p+hı^)=Ap+h Aı^\mathbf{A}(\mathbf{p} + h\hat{\imath}) = \mathbf{A}\mathbf{p} + h\,\mathbf{A}\hat{\imath}. So the image has one corner at Ap\mathbf{A}\mathbf{p} and sides h Aı^h\,\mathbf{A}\hat{\imath} and h Aȷ^h\,\mathbf{A}\hat{\jmath} from there. (A linear map sends straight edges to straight edges, so the image is exactly the parallelogram with those corners.)

Step 3, compare with the unit square. The unit square's image has sides Aı^\mathbf{A}\hat{\imath} and Aȷ^\mathbf{A}\hat{\jmath} and area DD. The small square's image has the same two sides, each shrunk by the factor hh, and slid over to start at Ap\mathbf{A}\mathbf{p}. Shrinking both sides by hh multiplies the area by h×h=h2h \times h = h^2, and sliding does not change area. So the image has area h2Dh^2 D.

Step 4, take the ratio. Area after divided by area before is h2D/h2=Dh^2 D / h^2 = D. Neither hh nor p\mathbf{p} is left: every small square, of any size and anywhere, is scaled by the same DD.

Step 5, any shape. Cover a shape with a fine grid of small squares. Each one is scaled by DD, so their total area is scaled by DD. As the grid gets finer the squares fill the shape more and more exactly, so the shape's own area is scaled by DD too.

That common factor gets a name.

The sign is the subject of the next section; for now, read the determinant as the area factor. Some books write the determinant as ∣A∣|\mathbf{A}|. We will not, because in this course bars mean the length of a vector.

Three examples you can check in the widget:

  • [2003]\begin{bmatrix} 2 & 0 \\ 0 & 3 \end{bmatrix} stretches xx by 2 and yy by 3. The unit square becomes a 2 by 3 rectangle, so det⁡=2×3=6\det = 2 \times 3 = 6. A circle of area π\pi becomes an ellipse of area 6π6\pi.
  • The shear [1101]\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} keeps ı^\hat{\imath} and sends ȷ^\hat{\jmath} to (1,1)(1,\allowbreak 1). The parallelogram has base 1 and height 1, so det⁡=1\det = 1. A shear slides the layers of the plane past each other, like a deck of cards pushed sideways: each layer keeps its length, and the stack keeps its height, so no area is gained or lost.
  • A rotation turns every shape without changing its size, so det⁡=1\det = 1.

A neat stack of cards seen from the side, then the same stack pushed so it leans over as a parallelogram with the same height and the same card widthA shear slides each layer sideways in proportion to its height. Every card keeps its size and the stack keeps its height, so the area does not change.

Now read an area factor off a picture yourself, without the widget.

Work it outRead the area scaling

A transformation sends ı^\hat{\imath} to (3,0)(3,\allowbreak 0) and ȷ^\hat{\jmath} to (1,2)(1,\allowbreak 2). A shape of area 5 goes in. What is the area of the shape that comes out? Use the picture (base times height), not a formula, and enter a whole number.

area out

Type a number: 0.25, -2, 3/4 and sqrt(2) all work. Enter checks.

In short: a matrix scales every area by the same factor, and that factor is the area of the parallelogram built on its two columns. The next section adds a sign to that number.

Negative determinants: the plane flips over

An area is never negative, so why should the determinant be? Because there is one more thing a transformation can do to the plane, which area alone does not record: turn it over.

Orientation. Going from ı^\hat{\imath} to ȷ^\hat{\jmath} is a counterclockwise quarter turn. After the transformation, look at the two columns. If the shorter turn from the first column to the second is still counterclockwise, orientation is preserved and the determinant is positive. If that shorter turn is now clockwise, the plane has been turned over, like a page seen from the back, and the determinant is negative. Text drawn on the plane would come out mirror-reversed.

The same widget, now with the determinant switched on, lets you watch the sign change. It starts from the same A=[2101.5]\mathbf{A} = \begin{bmatrix} 2 & 1 \\ 0 & 1.5 \end{bmatrix}. Two things are new: the det A readout, which turns coral when the determinant is negative, and a white arc at the origin that turns from Aı^\mathbf{A}\hat{\imath} to Aȷ^\mathbf{A}\hat{\jmath}. The widget also prints the formula ad−bcad - bc with the live numbers; a later section derives it.

The two mirrors from the walkthrough, written as matrices: the reflection in the xx-axis, [100−1]\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}, keeps ı^\hat{\imath} and sends ȷ^\hat{\jmath} to (0,−1)(0,\allowbreak -1), so the turn from the first column to the second is now clockwise. The area is still 1, and det⁡=−1\det = -1. Swapping the axes with [0110]\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}, a reflection across the line y=xy = x, also has determinant −1-1.

A flip is harmless for undoing: flip back and you are where you started. So a negative determinant says "turned over", not "damaged". The value that does damage is the one you passed through in step 2.

Zero determinant: information is lost

Why single out zero? Because it is the one value that changes what a matrix can do: a matrix with determinant zero destroys information, and no later step can bring it back.

A collapse, step by step. Take the singular matrix from module 2's gallery, A=[1224]\mathbf{A} = \begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}. Its second column (2,4)(2,\allowbreak 4) is twice its first column (1,2)(1,\allowbreak 2), so the parallelogram on the two columns is flat and det⁡A=0\det\mathbf{A} = 0. Every output is a combination of the columns (module 2), and the second column is twice the first, so

Ax=x1[12]+x2[24]=x1[12]+2x2[12]=(x1+2x2)[12].\mathbf{A}\mathbf{x} = x_1 \begin{bmatrix} 1 \\ 2 \end{bmatrix} + x_2 \begin{bmatrix} 2 \\ 4 \end{bmatrix} = x_1 \begin{bmatrix} 1 \\ 2 \end{bmatrix} + 2x_2 \begin{bmatrix} 1 \\ 2 \end{bmatrix} = (x_1 + 2x_2)\begin{bmatrix} 1 \\ 2 \end{bmatrix}.

Every output is a multiple of (1,2)(1,\allowbreak 2), so the whole plane lands on the line through (1,2)(1,\allowbreak 2). Points off that line, such as (1,0)(1,\allowbreak 0), are never reached at all.

Now look for inputs that collide. The input (2,−1)(2,\allowbreak -1) goes to 2(1,2)+(−1)(2,4)=(2,4)−(2,4)=(0,0)2(1,\allowbreak 2) + (-1)(2,\allowbreak 4) = (2,\allowbreak 4) - (2,\allowbreak 4) = (0,\allowbreak 0). Adding it to any input changes nothing in the output: by linearity, A(x+t (2,−1))=Ax+t A(2,−1)=Ax+0\mathbf{A}(\mathbf{x} + t\,(2,\allowbreak -1)) = \mathbf{A}\mathbf{x} + t\,\mathbf{A}(2,\allowbreak -1) = \mathbf{A}\mathbf{x} + \mathbf{0} for every number tt. For example (1,1)(1,\allowbreak 1) and (1,1)+(2,−1)=(3,0)(1,\allowbreak 1) + (2,\allowbreak -1) = (3,\allowbreak 0) both land on (3,6)(3,\allowbreak 6). Each output point is hit by a whole line of inputs, and nothing in the output says which one it came from. (The widget's Singular preset, with columns (1,0.5)(1,\allowbreak 0.5) and (2,1)(2,\allowbreak 1), sends the same direction (2,−1)(2,\allowbreak -1) to zero.)

This is no accident of the example. Zero area and lost information are the same event, seen two ways.

If two inputs collide, the area factor is 0.

  1. Suppose two different inputs land on the same output: x≠y\mathbf{x} \ne \mathbf{y} but Ax=Ay\mathbf{A}\mathbf{x} = \mathbf{A}\mathbf{y}.
  2. Subtract the two outputs and use linearity: A(x−y)=Ax−Ay=0\mathbf{A}(\mathbf{x} - \mathbf{y}) = \mathbf{A}\mathbf{x} - \mathbf{A}\mathbf{y} = \mathbf{0}. So n=x−y\mathbf{n} = \mathbf{x} - \mathbf{y} is a nonzero vector that A\mathbf{A} crushes to the origin.
  3. Take a parallelogram with n\mathbf{n} as one side and any vector w\mathbf{w} off the line of n\mathbf{n} as the other. It has a positive area.
  4. Its image has sides An=0\mathbf{A}\mathbf{n} = \mathbf{0} and Aw\mathbf{A}\mathbf{w}. One side has length zero, so the image is flat and has area 0.
  5. A positive area became 0, and every area is scaled by the same factor, so that factor is 0.

If the area factor is 0, inputs collide.

  1. Suppose det⁡A=0\det\mathbf{A} = 0. Then the parallelogram on the two columns has no area, so it is flat: both columns lie on one line through the origin, and one is a multiple of the other.
  2. Say column 2 is kk times column 1. Then the input n=(k,−1)\mathbf{n} = (k,\allowbreak -1) goes to k(column 1)−(column 2)=0k(\text{column 1}) - (\text{column 2}) = \mathbf{0}. (If instead column 1 is mm times column 2, use n=(1,−m)\mathbf{n} = (1,\allowbreak -m).) For [1224]\begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}, k=2k = 2 and n=(2,−1)\mathbf{n} = (2,\allowbreak -1), the vector we found above.
  3. Either way a nonzero input lands on the origin, and then, exactly as in the example, x\mathbf{x} and x+t n\mathbf{x} + t\,\mathbf{n} land on the same output for every x\mathbf{x} and every number tt.

You have met this test before. In module 1's lesson on span and basis, solving for the coefficients that combine a\mathbf{a} and b\mathbf{b} into a target meant dividing by a1b2−a2b1a_1 b_2 - a_2 b_1, and that number was zero exactly when one vector is a multiple of the other. The next section shows it is the determinant of the matrix with columns a\mathbf{a} and b\mathbf{b}.

A square matrix with determinant zero is called singular. The others are called invertible, because they can be undone, which a later lesson makes precise.

Now read all three cases from pictures alone: for each pair of columns, picture the two arrows and the turn from the first to the second.

Quick checkWhich one flips the plane

Four transformations are described by where they send ı^\hat{\imath} and ȷ^\hat{\jmath}. Picture each pair of arrows, and for each pair ask whether the shorter turn from the first arrow to the second is counterclockwise (as from ı^\hat{\imath} to ȷ^\hat{\jmath}) or clockwise. Which transformation flips the plane over?

Choose one answer, then check.

The formula ad−bcad - bc

Reading areas off pictures works for friendly matrices like the ones so far. For any 2x2 matrix, the area has a short formula. Name the entries

A=[abcd],with columns (a,c) and (b,d).\mathbf{A} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}, \qquad \text{with columns } (a, c) \text{ and } (b, d).

Then

det⁡A=ad−bc.\det\mathbf{A} = ad - bc.

In words: the product of the diagonal entries, minus the product of the other two. For A=[3112]\mathbf{A} = \begin{bmatrix} 3 & 1 \\ 1 & 2 \end{bmatrix}, a=3a = 3, b=1b = 1, c=1c = 1 and d=2d = 2, so ad−bc=(3)(2)−(1)(1)=6−1=5ad - bc = (3)(2) - (1)(1) = 6 - 1 = 5: the parallelogram spanned by the columns (3,1)(3,\allowbreak 1) and (1,2)(1,\allowbreak 2) has area 5. Written with columns a=(a1,a2)=(a,c)\mathbf{a} = (a_1,\allowbreak a_2) = (a,\allowbreak c) and b=(b1,b2)=(b,d)\mathbf{b} = (b_1,\allowbreak b_2) = (b,\allowbreak d), the formula is module 1's a1b2−a2b1a_1 b_2 - a_2 b_1.

The formula comes straight out of the picture. Draw a rectangular box around the parallelogram, and subtract the pieces of the box that lie outside the parallelogram. The picture shows the pieces for the columns (3,1)(3,\allowbreak 1) and (1,2)(1,\allowbreak 2); the box below does the subtraction in general.

A 4 by 3 rectangle on a square grid containing the parallelogram with corners (0, 0), (3, 1), (4, 3) and (1, 2). The six leftover pieces are shaded: two flat right triangles 3 wide and 1 tall, below the bottom side and above the top side; two steep right triangles 1 wide and 2 tall, left of the left side and right of the right side; and two unit squares, in the bottom-right and top-left corners of the boxThe box around the parallelogram on (3, 1) and (1, 2), cut into the parallelogram and six leftover pieces. Box minus pieces is the area: 12 − 7 = 5.

Go slower: Where ad−bcad - bc comes from

Draw the parallelogram with corners 0\mathbf{0}, (a,c)(a,\allowbreak c), (a+b,c+d)(a + b,\allowbreak c + d) and (b,d)(b,\allowbreak d). Take the case where all four entries are positive and the first column (a,c)(a,\allowbreak c) is less steep than the second column (b,d)(b,\allowbreak d), so the first arrow lies below the second and the turn from the first to the second is counterclockwise. Follow along with the numbers a=3a = 3, c=1c = 1, b=1b = 1, d=2d = 2 from the picture.

Step 1, a box around it. The parallelogram fits inside the rectangle from (0,0)(0,\allowbreak 0) to (a+b,c+d)(a + b,\allowbreak c + d). Multiply out its area, one product at a time: (a+b)(c+d)=ac+ad+bc+bd.(a + b)(c + d) = ac + ad + bc + bd. With the numbers: the box is 4×3=124 \times 3 = 12.

Step 2, the pieces outside. The part of the box outside the parallelogram splits into six pieces:

  • two right triangles with legs aa and cc: one under the first column, with corners (0,0)(0,\allowbreak 0), (a,0)(a,\allowbreak 0), (a,c)(a,\allowbreak c), and one above the top side, with corners (b,d)(b,\allowbreak d), (b,c+d)(b,\allowbreak c + d), (a+b,c+d)(a + b,\allowbreak c + d). Each has area 12ac\tfrac{1}{2}ac (here 12×3×1=1.5\tfrac12 \times 3 \times 1 = 1.5);
  • two right triangles with legs bb and dd: one left of the second column, with corners (0,0)(0,\allowbreak 0), (0,d)(0,\allowbreak d), (b,d)(b,\allowbreak d), and one right of the far side, with corners (a,c)(a,\allowbreak c), (a+b,c)(a + b,\allowbreak c), (a+b,c+d)(a + b,\allowbreak c + d). Each has area 12bd\tfrac{1}{2}bd (here 12×1×2=1\tfrac12 \times 1 \times 2 = 1);
  • two rectangles with sides bb and cc: one in the bottom right corner of the box, from (a,0)(a,\allowbreak 0) to (a+b,c)(a + b,\allowbreak c), and one in the top left, from (0,d)(0,\allowbreak d) to (b,c+d)(b,\allowbreak c + d). Each has area bcbc (here 1×1=11 \times 1 = 1).

Add them up: 2⋅12ac+2⋅12bd+2bc=ac+bd+2bc2 \cdot \tfrac12 ac + 2 \cdot \tfrac12 bd + 2bc = ac + bd + 2bc. With the numbers: 1.5+1.5+1+1+1+1=71.5 + 1.5 + 1 + 1 + 1 + 1 = 7.

Step 3, subtract. The parallelogram is the box minus the pieces: area=(ac+ad+bc+bd)−(ac+bd+2bc).\text{area} = (ac + ad + bc + bd) - (ac + bd + 2bc). The acac terms cancel, and so do the bdbd terms: area=ad+bc−2bc.\text{area} = ad + bc - 2bc. And bc−2bc=−bcbc - 2bc = -bc: area=ad−bc.\text{area} = ad - bc. With the numbers: 12−7=512 - 7 = 5, and ad−bc=6−1=5ad - bc = 6 - 1 = 5.

Other arrangements of the columns need a slightly different drawing, but the area always comes out as ∣ad−bc∣|ad - bc|, the size of ad−bcad - bc without its sign. The sign then records the orientation from the section on flips: swap the two columns and the formula becomes bc−adbc - ad, the same size with the opposite sign.

Try the formula on a matrix with a negative entry, where the signs are easy to slip on.

Work it outA 2x2 determinant

Compute det⁡[4−231]\det\begin{bmatrix} 4 & -2 \\ 3 & 1 \end{bmatrix} with the formula ad−bcad - bc. Enter a whole number.

det

Type a number: 0.25, -2, 3/4 and sqrt(2) all work. Enter checks.

To recap the lesson: the determinant is the factor by which a transformation scales every area. Its sign says whether the plane was turned over, zero means information was lost for good, and for a 2x2 matrix it is ad−bcad - bc. The next lesson computes determinants of any size: three rules about columns, a recipe for 3x3 matrices, the method software uses, and the rule for chains of transformations.

Finally, put the lesson's main point in your own words, the way you would explain it to a colleague.

In your own wordsWhy zero is fatal and negative is not

Explain to a colleague, using the picture of the unit square, why a matrix with determinant 0 cannot be undone while a matrix with determinant −5-5 can. No formulas needed.

A few sentences first: 0 of 60 characters.

Saved in this browser as you type.

Next: Computing determinants