Interactive course · ~5 hours

Linear Algebra

A matrix is a rule for moving and combining coordinates. Start by dragging two-dimensional arrows so every symbol has a picture. Then use the same ideas to solve systems, choose bases, project onto models, compress data, inspect embeddings and decide whether a numerical answer can be trusted.

How this works

Every grid here is live. You drag an arrow and the numbers follow it; you change a number and the whole grid bends to match. Nothing is a picture of an answer worked out somewhere else. When a widget prints an area, or a stretch, or a score, it worked that number out from what you did a moment ago.

What you need before you start

Adding, subtracting and multiplying, including with negative numbers. Halves and quarters. That is the whole list. No algebra, no geometry, no programming. Every word with a special meaning gets explained the first time it turns up, and the ones that usually trip people are given their own note you can open or ignore.

The steps

Step 1

Draw an arrow, and add two of them

Start with a flat sheet ruled into squares. One point on it is special: the place where the two heavy lines cross. That point is the origin, and everything on this page is measured from it. The two heavy lines themselves are the axes: one lies flat and runs left and right, the other stands upright and runs up and down.

Now draw an arrow from the origin out to somewhere else. An arrow like that is called a vector. To say exactly which arrow you mean you only need two numbers: how far across, and how far up. Across is written first. So the vector (3, 2) is the arrow that goes three squares right and two squares up. Going left is a negative first number, and going down is a negative second number.

I have not used a grid with minus numbers on it

The two axes cross at the origin, and each one carries numbers. They get bigger going right along the flat axis and smaller going left, so one square to the left of the origin is at -1, and two squares left is at -2. The same idea works upright: above the origin the numbers count up, below it they count down into the negatives.

Nothing here needs you to be quick with negative numbers. If a sign confuses you, drag the arrow into that corner and read what the widget prints. It is showing you the answer while you move.

Why call it a vector and not just a point

A point is a place. A vector is a trip: a distance in a direction. Written down they look the same, because the trip that starts at the origin and ends at that place is described by exactly the same two numbers.

The difference starts to matter the moment you add two of them, which is the second half of this step. Adding two places makes no sense. Adding two trips does: do the first, then do the second, and see where you end up.

Lab 1 · The arrow and its two numbers
Try this firstDrag the small ring at the tip of the arrow. The two numbers under the grid change as you move, and the sentence below them says what the arrow is doing. Try to make the readout say 3 across and 2 up. Then press Show the two legs to see where those numbers come from.
Notice: the arrow is nothing but its two numbers. Drag it into the bottom left and both go negative. Drag it onto the flat axis and the second number is 0, because it does not go up at all. Every arrow in this whole course is stored as a pair of numbers like these.

Two arrows can be added. Put the tail of the second arrow on the tip of the first, and the sum is the arrow that runs from the origin to where you ended up. That is the whole rule. It is called adding nose to tail.

Adding two arrows using only the numbers

You never have to draw it. Add the across numbers together, add the up numbers together, and those two answers are the sum. So (2, 1) plus (1, 3) is (3, 4), because 2 plus 1 is 3 and 1 plus 3 is 4.

The drawing and the arithmetic are the same thing. Walking two right and one up, then one right and three up, gets you to the same place as walking three right and four up in one go. The order you do the two walks in does not change where you finish.

Lab 2 · Land the sum on the ring
Try this firstDrag the tip of the arrow marked a. A faint copy of b hangs off a's tip and moves with it, and the thick orange arrow is the sum. Your task is to land that orange tip exactly on the green ring. When you think it is there, press Check my answer.
Notice: there are many ways to win. Any pair of arrows whose across numbers add to 4 and whose up numbers add to -1 will do it. That is worth sitting with: a target does not pin down the two arrows that reach it, only their total.
A drone flies 5 squares east and 2 squares up, then flies 3 squares west and 1 square down. Written as vectors that is (5, 2) then (-3, -1). Where does it finish, measured from where it took off?
Add each pair separately: 5 plus -3 is 2, and 2 plus -1 is 1, so the drone finishes at (2, 1). The first answer is the common slip. It treats west as if it were east, adding 3 instead of subtracting it. The direction is carried by the sign, and once you have written -3 the arithmetic looks after the rest.
Step 2

Stretch an arrow, and turn it around

There is one more thing you can do to a single arrow: multiply it by a plain number. Multiplying (2, 1) by 3 means multiplying both of its numbers by 3, giving (6, 3). The arrow points the same way and is three times as long.

A plain number used this way has a name. It is called a scalar, because its job is to scale something. Scalars can be fractions, and they can be negative, and both of those are more interesting than they sound.

Why multiplying both numbers keeps the direction

Think of the arrow as a set of instructions: go 2 across, then 1 up. Doing that same trip three times in a row lands you 6 across and 3 up. You have walked in a perfectly straight line the whole time, because every step was in the same direction as the last one.

That is why the two numbers have to be multiplied by the same scalar. Multiplying only the across number would bend the trip. Multiplying both keeps the shape of the walk and only changes how far you go.

What a negative scalar does, and what 0 does

Multiplying by -1 flips both numbers' signs, so (2, 1) becomes (-2, -1). Same length, opposite direction. Multiplying by -2 does both at once: twice as long, and pointing backwards.

Multiplying by 0 gives (0, 0), an arrow with no length at all. It is called the zero vector, and it is the only vector that has no direction. It is not nothing. It is a real answer that a lot of the interesting questions later in this course turn out to have.

Lab 3 · One arrow, one dial
Try this firstDrag the slider marked k slowly from 3 down to -3. Watch the orange arrow shrink to nothing as k passes 0 and then grow again pointing the other way. The sentence underneath names what is happening at each moment.
Notice: the orange arrow never leaves the dotted line, whatever k you pick and wherever you drag v. Every multiple of one arrow lies on one straight line through the origin. That line is going to come back in Step 7 and again in Step 10, so it is worth seeing it now.

Now combine the two ideas. Take two fixed arrows, scale each one by a number of your choosing, and add the results nose to tail. This is called a combination of the two arrows, and with the right pair of scalars you can reach a surprising number of places.

A combination, written out slowly

Say u is (2, 1) and w is (-1, 2). Pick the scalars 2 and 1. Then 2 lots of u is (4, 2), and 1 lot of w is (-1, 2), and adding those nose to tail gives (3, 4).

Two dials, one landing spot. That is the whole machine, and almost everything later in this course is a question about it. Which dial settings reach a given spot? Is there ever more than one answer? Are there spots that cannot be reached at all?

Lab 4 · Two dials, one target
Try this firstMove the slider marked a and see which arrow changes. Then move b. The orange arrow is where the two land added together. Get its tip on the green ring and press Check my answer.
Notice: exactly one setting of the two dials works. Try to find a second one and you cannot. Step 8 explains why: two dials and two numbers to match usually pin each other down completely, and the exceptions are the interesting part.
An arrow v points up and to the right. Someone multiplies it by -0.5. What does the new arrow look like?
The minus flips the direction and the 0.5 halves the length, so both happen: down and to the left, half as long. The tempting wrong answer is the third one, from reading the minus sign as "bigger". A negative scalar does not make an arrow longer. Only the size of the number, ignoring its sign, decides the length.
Step 3

Move every point at once

Until now you have moved one arrow at a time. Now move the entire sheet in one action. Every point on it slides somewhere new, all together, and the grid you have been reading off bends with it.

The thing that does the moving is a matrix: four numbers written in a box, two across and two down. Feed the sheet in, get a bent sheet back. One point never goes anywhere, and that is the origin.

The moves in the lab below have ordinary names, and one of them is worth having now. A move that leans the sheet over, sliding it sideways further and further the higher up you look while one line stays exactly where it was, is called a shear. The lab's Lean over button is a shear, and later steps use the word.

How to read a box of four numbers

The box has a top row and a bottom row, and a left column and a right column. Four slots: top left, top right, bottom left, bottom right. That is all the structure there is. Written on one line people often squash it into square brackets, but on this page it always stays as a box so you can see the rows and columns.

What the four numbers actually mean is Step 4, and it is worth not guessing. For now the honest description is that they are the settings of a machine and the picture is the machine running.

What kind of moving this is, and what it rules out

These machines are limited on purpose, and the limits are what makes four numbers enough. Straight lines stay straight. Lines that were parallel, meaning always the same distance apart and never meeting, stay parallel. Marks that were evenly spaced along a line stay evenly spaced. And the origin stays exactly where it is.

Moving that obeys those four promises is called linear, which is where the name of this whole subject comes from. It rules out bending the sheet into a curve, and it rules out sliding the whole sheet sideways, because sliding would move the origin.

Lab 5 · Press Apply and watch the sheet move
Try this firstPress Lean over, then press Apply. The grid slides into its new shape while the faint grid behind it shows where it started. Press Reset to put it back, then try the other three presets. After that, type your own numbers into the box and apply those.
Notice: the faint grid and the moving grid always cross at the origin, and the moved lines are still straight and still parallel in two families. Try putting a large number like 6 in one slot. The grid stretches off the edge, but it never curves and never tears.
Does the whole sheet really move, or only the lines I can see

The whole sheet. The lines are drawn so that you have something to look at, but every point between them moves too, and it moves in the way the lines around it suggest. If you imagine a dot halfway between two grid lines before the move, it is halfway between the same two lines after it. That is the evenly-spaced promise doing its work.

This matters because the next lab asks you to recognise a move from its picture. You are reading the fate of every point off the fate of a handful of lines, and you are allowed to, because the four promises make the rest follow.

Lab 6 · Which box of numbers did that
Try this firstLook at the bent grid, then press the box of numbers you think produced it. The right answer lights up either way, with a sentence saying what gave it away. Press Next for another one. There are six rounds and your score is kept at the bottom.
A hint you are allowed to use: look at where the grid line that used to go straight right ends up. Everything else follows from that and from its partner going straight up. If that sounds like a rule, it is, and it is the whole of the next step.
A matrix is applied to the sheet, and a reader notices that a certain point did not move at all. Which point are they certainly talking about?
The origin stays put under every matrix, always. Multiply anything by zeros and you get zeros. Other points can also stay put, and Step 10 is about hunting for them, but the origin is the one you can name without seeing the numbers. The third answer is the tempting one, and the counter to it is the do-nothing matrix in the next step, which moves nothing at all.
Step 4

Read a matrix by watching two arrows land

Four numbers is not many, and yet they decide where every one of infinitely many points goes. Here is the reason, and it is the single most useful idea in the subject.

Put an arrow one square to the right, at (1, 0), and call it i. Put another one square up, at (0, 1), and call it j. Those two are the basis: the two arrows everything else is built out of. The arrow (3, 2) is just 3 lots of i plus 2 lots of j.

Column and row, and the odd names i and j

In a box of numbers, a row reads across and a column reads down. The box in this course has two rows and two columns, so a column is a pair of numbers stacked one above the other. When this page says "the first column" it means the top-left number with the bottom-left number underneath it.

The names i and j are just labels that stuck, the way x and y stuck for the axes. In books they usually wear little hats to show they are one square long. Nothing depends on the names, but you will meet them everywhere, so they are worth recognising.

Now the point. When a matrix bends the sheet, i and j land somewhere. Write down where i landed as the first column of the box, and where j landed as the second column, and you have written the matrix. The four numbers are the two landing spots.

The do-nothing matrix

If i stays at (1, 0) and j stays at (0, 1), nothing has moved. That box, with 1 and 0 on the top row and 0 and 1 on the bottom row, is called the identity. Most people call it the do-nothing matrix when they are talking rather than writing.

It is the grid you see before you press Apply, and it is what a move and its undo add up to in Step 9. Recognising it on sight is worth the small effort: 1s down the diagonal from top left to bottom right, 0s in the other two slots.

Why watch i and j, and not some other pair of arrows

Any two arrows that do not lie on one line would do. You could watch (2, 1) and (-1, 2) land instead. You would still be able to work out where every other arrow goes, because every arrow is some combination of those two, exactly as in Lab 4.

The pair i and j wins because their combinations are free. The arrow (3, 2) is 3 lots of i and 2 lots of j, and those two numbers are already written on the arrow. Watching any other pair would mean working out the two dial settings first, every single time.

Lab 7 · Drag the landing spots
Try this firstDrag the tip of the blue arrow marked i. The two numbers in the left column of the box follow it exactly, and the whole grid bends to keep up. Then drag j. When you have made the grid do the quarter turn the task asks for, press Check my answer.
Notice: you are writing a matrix by pointing at two places. Every box of four numbers you will ever see is a pair of landing spots written down, and every bent grid on this page can be read backwards into one.

That also tells you how to work out where any arrow goes, without drawing anything. The arrow (x, y) was x lots of i plus y lots of j before the move. Afterwards it is x lots of where i landed plus y lots of where j landed. That sentence is the rule for applying a matrix to a vector, and there is nothing else to it.

Lab 8 · The recipe, one piece at a time
Try this firstPress Next piece three times. Each press adds one part of the recipe to the picture, and the lines underneath say what was just added and with what numbers. Then drag the tip of v: the recipe clears itself back to nothing, and you can press Next piece again to run it on the new arrow.
Notice: the final orange arrow lands in exactly the same place whether you build it from the two pieces or just bend the whole grid and read v off the bent grid. Those are two descriptions of one thing, which is why the arithmetic and the picture can never disagree.
A matrix sends i to (2, 0) and sends j to (0, 3). Without drawing anything, where does the arrow (1, 1) end up?
One lot of where i landed plus one lot of where j landed gives (2 + 0, 0 + 3), which is (2, 3). The third answer is the one to watch out for: landing spots are added, never multiplied. Multiplying them would break the promise that evenly spaced marks stay evenly spaced. The first answer has the right two digits in the wrong order, which is what happens if you forget that across is always written first.
Step 5

Do two moves, and then swap the order

Bend the sheet with one matrix. Then bend the already-bent sheet with a second one. The end result is some new bent sheet, and since every bent sheet is a matrix, the pair of moves has a single matrix of its own. Working that matrix out is what people mean by multiplying two matrices.

Why "B after A" is written with B on the left

When the two are written next to each other as BA, the one nearest the arrow is the one that happens first. The arrow is imagined sitting to the right, so A touches it first and B works on the result. It reads backwards compared with English, and nearly everyone finds it awkward at the start.

This page avoids the trap by never relying on the written order. Every control says first move and second move in words, and the picture does them in that order in front of you.

Order matters, and here is the smallest example

Take a quarter turn and a flip across the flat axis. Turn first, then flip, and i ends up pointing down. Flip first, then turn, and i ends up pointing up. Same two moves, different answer, and the picture in the lab below shows both at once so you do not have to take that on trust.

Some pairs do agree. Two turns in the same plane agree, and two pure stretches along the axes agree. Agreeing is the exception, though, and assuming it is one of the most common mistakes in the subject.

Lab 9 · The same two moves, both ways round
Try this firstPress Play both and watch the two grids. The caption above each grid names the two moves in the order that grid is about to do them, and the right-hand grid does them the other way round. They start identical and they finish in different shapes. The two boxes underneath print the matrix each side ended up with.
Notice: the row of three buttons above the grids swaps which two moves you are using. Press the one marked Stretch across and Stretch upward and play that. Those two do agree, and the widget says so. Agreement is possible, it is just not something you may assume.

Working out the combined matrix by hand uses only Step 4. Ask where i ends up after both moves, and write that down as the first column. Ask the same about j for the second column. There is no separate rule to learn.

The row-times-column recipe books teach, and where it comes from

A book will tell you to take a row of the left-hand box and a column of the right-hand one, multiply the two first numbers, multiply the two second numbers, and add. Do that for each of the four row-and-column pairings and you have the combined box.

That is not a different rule. Walking i through both moves is exactly those multiplications, in exactly that order, and the recipe is just the bookkeeping written down so you do not have to draw anything. If you ever forget it, walk i and j through by hand as in the lab below and you will rebuild it.

Lab 10 · Work out the combined box yourself
Try this firstPress Show me where i goes. It walks i through both moves so you can read off the first column. Type those two numbers into the empty box, do the same for j, then press Check my answer. If you get stuck, Show me one that works fills the box in.
Notice: the check does not look at your arithmetic. It applies your box to a handful of test arrows and compares where they land with where the two real moves send them. Any box that behaves correctly passes, because behaving correctly is the only thing a matrix is for.
You put your socks on and then your shoes. A friend claims that with matrices, doing two things in the other order always gives the same answer. What is the shortest honest reply?
Order usually matters, and Lab 9 shows two grids finishing in different shapes from the same two moves. The trap in the first two answers is real, though: addition really does not care about order, and neither does multiplying ordinary numbers, so the habit is easy to carry over. Matrices are the place that habit breaks.
Step 6

Measure how much bigger space got

Bending the sheet changes areas. The single square between i and j, one wide and one tall, is called the unit square, and its area starts at exactly 1. Bend the sheet and it turns into a slanted box. Measure that slanted box and you know what happened to every area on the sheet at once.

The area of a slanted box

A box whose opposite sides are parallel but whose corners are not square still has an area. You work it out the ordinary way: pick one side as the base, measure straight across to the side opposite it, and multiply the two. Leaning a box over changes neither its base nor that straight-across distance. So it does not change the area at all, which is why a heavy shear can leave the number at 1.

You do not have to measure anything by hand here. The widget shades the box and prints its area, and it works that number out from the corners it just drew.

What a factor is

A factor is a multiplier. A factor of 2 means twice as much, a factor of 1 means unchanged, and a factor of 0.5 means half. Saying that a move has an area factor of 3 means that any shape you draw first, of any size, comes out with three times the area afterwards.

The strong part of that claim is the "any shape". Measuring one small square tells you about a circle, a triangle and a drawing of a cat, because the four promises from Step 3 force every area on the sheet to change by the same multiplier.

Lab 11 · Grow the shaded patch
Try this firstDrag the tip of the blue arrow i. The shaded patch changes shape and the number beneath it is that patch's area, worked out from its corners. Try to make the area read exactly 2. Then drag i past j, so the arrows swap sides, and read what the widget says about flipping.
Notice: dragging i sideways, so that it slides along the direction j points in, changes the shape of the patch but not its area. With j pointing straight up that means dragging i straight up: the patch leans over and the number under it does not move. Dragging i along its own direction is a different thing and does change the area. That is the leaning-box fact from the note above, and it is the reason a shear leaves the number at 1 no matter how far you push it.

Now the number itself. If the box reads a and b across the top and c and d across the bottom, the area factor is a×d − b×c. It is called the determinant. You have already watched it change; the formula just saves you the drawing.

Why the determinant can be negative

An area is never negative, but the determinant can be, and the minus sign carries a second piece of news: the sheet has been turned over. Before the move, going from i to j is a turn anticlockwise. If afterwards that same trip has become a turn clockwise, the sheet has been flipped, like reading a page through the back of the paper.

So the size of the determinant is the area factor, and its sign says whether the sheet is still the right way up. A determinant of -3 means areas tripled and the sheet is mirrored.

Lab 12 · Call the area before you see it
Try this firstRead the box of four numbers, work out a×d − b×c in your head, and press that answer. The grid then bends and shades the real patch, so you can see whether you were right. Press Next for another round. Six rounds, score at the bottom.
Notice: the rounds with a zero in the box are the quick ones, because a zero kills whichever product it is in. The rounds that catch people are the ones where b×c is bigger than a×d, since the answer comes out negative and the patch comes out flipped.
A matrix has 3 and 0 on the top row and 0 and 3 on the bottom row. A shape drawn on the sheet has an area of 4 squares. What is its area after the move?
The determinant is 3×3 − 0×0, which is 9, so every area is multiplied by 9 and 4 becomes 36. The first answer is the classic slip: tripling the width and tripling the height multiplies the area by nine, not by three. Areas grow faster than lengths, and the determinant is already counting the growth in both directions.
Step 7

Squash space flat, and lose something forever

Push the determinant down toward zero and watch what happens to the shaded patch. It gets thinner. At exactly zero it has no thickness left, and the whole sheet has been pressed onto a single line through the origin.

What "losing information" means here

Suppose a machine turns every number you feed it into that number's distance from zero. Feed it 5 and you get 5. Feed it -5 and you also get 5. Now somebody hands you the answer 5 and asks what went in. You cannot tell them, and no amount of cleverness will help, because two different inputs really did produce the same output.

A squashed sheet is that, on a much larger scale. Whole lines of starting points get pressed onto the same landing spot. The information about which one it was is not hidden or encrypted. It is gone.

Many arrows, one landing place

When the determinant is zero, the two columns of the matrix point along the same line. Where i lands and where j lands are multiples of one another. Everything the matrix can produce is a combination of those two, so everything it can produce lies on that one line.

And once the output is a line rather than a whole sheet, there are not enough landing spots to go round. The inputs have to double up, and they do: a whole parallel family of input lines maps onto each single output point.

Lab 13 · Flatten it on purpose
Try this firstDrag the tip of the purple arrow j until it sits on the dotted line through i. Watch the area number fall toward 0 and the bar under it empty out. When you get it to exactly 0 the widget says so and the whole grid folds onto one line.
Notice: you can get the area very small without getting it to zero, and a nearly-flat grid still holds all its information, in principle. In practice a computer storing these numbers to a limited number of decimal places cannot tell a very small determinant from zero, which is why "nearly flat" causes real trouble in real programs.

Here is the sharpest way to see the loss. When the sheet is squashed there is always a whole line of arrows, not just the zero vector, that land exactly on the origin. Every one of them has been wiped out.

These two families have names, if you want them

The line that everything lands on is the column space, because it is everything you can build out of the columns. The line of arrows that get wiped out to the origin is the null space, sometimes called the kernel. Both names turn up constantly in later work.

You will not need either word again in this course, and nothing later depends on it. They are here so that the ideas you have already got by dragging arrows do not feel like strangers when you meet them written down.

Lab 14 · Find an arrow that gets wiped out
Try this firstDrag the tip of the solid blue arrow v around. The hollow orange arrow is where the machine sends it, and it never leaves one line. Find a spot, away from the origin, where the hollow arrow shrinks to nothing, then press Check my answer.
Notice: once you have found one, slide v further out along the same direction. It still lands on the origin. An entire line of arrows is being destroyed, which is exactly how much information the squash threw away.
A matrix has a determinant of 0. Someone tells you where an arrow landed and asks you which arrow it was. What can you honestly say?
Two cases, and both are on show in Lab 14. If the spot is off the squash line, no arrow reaches it. If the spot is on the line, an endless family of arrows reaches it and they are all equally good answers. The first option is the tempting one, because most broken-looking problems in maths do yield to more effort. This one does not: the information is not hard to recover, it is absent.
Step 8

Ask which arrow lands on the target

Almost every use of this subject comes down to one question. You know the matrix, you know where you want to end up, and you need the arrow that gets sent there. Given the machine and the output, find the input.

Written out with letters, that question is a pair of equations. Written on the grid, it is a target ring and an arrow you drag until it lands. They are the same question, and the grid version is easier to believe.

What the pair of equations looks like written out

Suppose the box has 2 and 1 on top and 1 and 3 underneath, and the target is (5, 5). Applying the box to an arrow (x, y) gives (2x + 1y, 1x + 3y), from the recipe in Step 4. Wanting that to be the target means wanting 2x + y = 5 and x + 3y = 5 to be true at the same time.

Two statements, two unknown numbers, and one pair of values that satisfies both. That is what a system of equations is. There is no new mathematics in the phrase, only a name for the situation.

The same question in three languages

Language one, equations: find x and y that make both lines true at once. Language two, columns: find how many lots of the first column and how many of the second add up to the target, which is exactly the two-dial game from Lab 4. Language three, moving space: find the arrow that the bent grid carries onto the target.

Different books lead with different ones, and switching between them on demand is most of what being comfortable here means. The dials and the bending grid are the two you have already used.

Lab 15 · Hunt for the input
Try this firstDrag the tip of the solid blue arrow. The hollow orange arrow is where the machine sends it. Land the hollow one on the green ring, then press Check my answer. The readout keeps telling you how far off you are while you drag.
Notice: the hollow arrow moves faster than your hand. That is the area factor showing up in a new place. A machine that multiplies areas by 5 also amplifies your little corrections by roughly that much, which is why the last part of the hunt is fiddly.
If I can find it by dragging, why does anyone need a method

Dragging works here because the answer is a whole number and there are only two numbers to find. It stops working almost immediately. The arrow in the lab below snaps to quarter squares, so an answer of one third of a square cannot be reached by hand at all. Worse, you would not be told that, and you would stop at the nearest quarter believing you were done.

The real reason is size. A weather model has millions of unknown numbers rather than two, and nobody is going to drag those. A method that grinds out the answer without looking at a picture is the only thing that survives the jump, which is what the second lab in this step shows one doing.

A machine can compute the answer instead of you hunting for it, and it is worth watching one do it, because the interesting part is the two cases where it cannot.

Lab 16 · Three targets, three outcomes
Try this firstPress One answer, then press Work it out. The lines that appear are the arithmetic done a piece at a time, ending with the answer put back into both equations as a check. Then run No answer and Endless answers the same way.
Notice: the two awkward cases both have a determinant of 0, and they differ only in where the target sits. Off the squash line, nothing reaches it. On the squash line, a whole family reaches it. That is Step 7 arriving as a practical consequence.
A matrix has a determinant of 7. How many arrows land on a given target point?
A determinant that is not zero means the sheet was stretched and possibly turned over, but never folded. Nothing doubled up, so every target has exactly one arrow that reaches it. The second answer describes the squashed case, where the determinant is 0, and mixing the two up is the most common error in this step. A healthy determinant means no special lines and no exceptions.
Step 9

Undo a move, or find out you cannot

If a matrix bends the sheet, is there a second matrix that bends it straight again? Sometimes. When there is, it is called the inverse, and doing the move and then its inverse leaves the sheet exactly as it started, which is the do-nothing matrix from Step 4.

Undoing, in ordinary numbers first

Multiplying by 4 is undone by multiplying by one quarter, because 4 times a quarter is 1, and multiplying by 1 changes nothing. Every number has a partner like that, with a single exception: nothing multiplied by 0 gives 1, so multiplying by 0 cannot be undone. Once you have multiplied by zero, the original number is gone.

Matrices work the same way, and the determinant is what plays the part of the number. A determinant of 0 is the case with no partner, for the same reason. The squash in Step 7 threw information away, and no matrix can put back what is not there.

Reading the undo off the picture

Here is a way to find the inverse without any formula. The original matrix says where i and j go. The inverse has to say where they came from. So look at the bent grid, find the two arrows on it that are now sitting at (1, 0) and (0, 1), and those are the columns of the inverse.

That is a usable trick on simple matrices, and it is also the reason the inverse of a quarter turn one way is a quarter turn the other way, with no arithmetic at all.

Lab 17 · Build the undo yourself
Try this firstPress Play it. The grid does move A, then does your box on top of it, and stops. It should finish back on the plain square grid, and right now it does not. Change the four numbers in your box, play it again, and press Check my answer when the grid comes home.
Notice: the readout prints the combined matrix of the two moves together. You are aiming for 1, 0 on the top row and 0, 1 on the bottom. Watching that box while you change numbers is a much faster way to close in than watching the grid.
The short formula, for a two by two only

Start with a and b on the top row and c and d on the bottom. Swap a and d, so the top row now begins with d and the bottom row ends with a. Flip the sign of the other two, so b becomes -b and c becomes -c. Then divide all four of the results by the determinant. That box is the inverse.

The division is where the whole story sits. A determinant of 0 makes it a division by zero, which is exactly the case that has no answer. Bigger boxes have no formula this short, so leaning on this one as your understanding is a mistake; the picture is the part that survives.

Lab 18 · Ask the machine to undo four moves
Try this firstPress Squash it flat, then press Undo it. Read what the machine says it cannot do and why. Then work along the other three moves and watch each one come home.
Notice: the undo of a stretch is a squeeze, the undo of a turn is a turn the other way, and the undo of a lean is a lean back. In every case the determinant of the undo is 1 divided by the determinant of the original, which has to be true: if areas grew by 5 they must shrink by 5 to get home.
A matrix squashes the sheet onto a line. A friend says they will find its inverse by being careful with the arithmetic. What is going wrong?
An inverse has to send every landing spot back to the one arrow it came from, and after a squash there is no such single arrow. Care cannot fix that. This is the same wall as dividing by zero, and it is worth recognising by sight: a determinant of 0 means stop, not try harder.
Step 10

Find the arrows that never turn

Bend the sheet and most arrows swing round to a new direction. A few do not. They get longer or shorter or flipped end for end, but they stay on the line they started on. Those are worth hunting for, and this step is the hunt.

What counts as "the same line"

An arrow and the same arrow pointing exactly backwards live on one line through the origin. So do an arrow and a stretched copy of it. That is the fact from Lab 3: every multiple of one arrow sits on one straight line, negatives included.

So "did not turn" means "ended up somewhere on its own line", which allows growing, shrinking and flipping. It rules out anything that ends up pointing off that line, however slightly.

Why the length of the arrow you drag does not matter

If an arrow stays on its line, so does every multiple of it. Doubling the input doubles the output, and a doubled arrow is still on the same line. So the answer is never a particular arrow, it is a whole direction and the widget draws it as a dashed line right across the grid.

That is why the hunt below only cares about the angle you drag to. Drag out to the edge if it makes the aiming easier. The reading will not change.

Lab 19 · Hunt for a line that holds still
Try this firstDrag the tip of v slowly in a circle around the origin. The bar under the grid is how far the machine turned it, and it drops as you get close to a good direction. Get the bar to read 0.0 degrees, press Lock this one in, then hunt for the second line.
Notice: the two directions you find are not at right angles for every matrix, though they happen to be for this one. Try to feel how the turn amount behaves as you sweep past a good direction: it falls to zero and climbs again, which is exactly what the next lab plots.

An arrow that stays on its own line is called an eigenvector of the matrix, and its line is an eigen-direction. The last lab of the course calls the same thing an eigen-line, because there it is drawn on the grid. The word is half German and it means something like "its own", as in the matrix's own private directions.

Some matrices have no such line at all

A pure turn moves every single direction. Turn the sheet by any amount that is not a whole half circle and nothing at all is left pointing where it started. So the hunt finds nothing and the turn bar never reaches zero. The third preset in the lab below, marked A pure turn, is exactly that case, and finding nothing there is not a bug.

A shear is the in-between case. It has one such line and no more. So the count can be two, one, or none, and the picture tells you which before any arithmetic does.

Lab 20 · Sweep every direction and plot the turn
Try this firstDrag the angle slider from one end to the other. The curve underneath is how far each direction gets turned, and the arrow on the grid points at whichever direction the slider is on. Look for the places where the curve touches the bottom, then press A pure turn and sweep again.
Notice: the curve for a pure turn is a flat line well above the bottom. It never touches, so there is no direction that holds still, and no amount of dragging will find one. The shear's curve touches the bottom twice, at 0 degrees and again at 180. Those two touches are the same line, pointed at from its two ends, which is why the widget still counts one line and not two.
Someone drags an arrow and reports that after the matrix it points in exactly the opposite direction, but is three times as long. Have they found an eigen-direction?
Same line is the test, and pointing backwards along a line does not leave it. Growing does not leave it either. The first answer is the natural reading of the word "direction" in everyday speech, which is why this trips people; here the whole line counts, both ways along it.
Step 11

Measure the stretch along those lines

You have the special directions. Each one comes with a number: how much longer the arrow got. That number is the eigenvalue of that direction, and it is written with the Greek letter lambda, which looks like this: λ.

What the stretch number counts

If an eigen-direction's arrow comes out twice as long, its eigenvalue is 2. If it comes out at three quarters of its old length, the eigenvalue is 0.75. If it does not change at all, the eigenvalue is 1, and that direction is completely untouched by the move.

The number belongs to the direction, not to the particular arrow. Slide your arrow further out along the same dashed line and the stretch reading stays where it is, which the lab below lets you confirm by dragging.

A negative eigenvalue, and a zero one

An eigenvalue of -2 means the arrow comes out twice as long and pointing backwards. The line is still held, the arrow has just been reversed along it, which is the case from the last quiz in Step 10.

An eigenvalue of 0 means arrows on that line are sent to the origin. That is the wiped-out line from Step 7, seen from a new angle: a matrix with a determinant of 0 always has 0 as one of its eigenvalues.

Lab 21 · Read both stretch numbers off the grid
Try this firstDrag the tip of v onto one of the two dashed lines. The stretch reading appears as soon as it is close enough, and it stays put as you slide along the line. Read both numbers, type them into the two boxes, and press Check my answer.
Notice: multiply your two answers together and compare with the area factor printed under the grid. They match, every time, for every matrix in the preset row. Areas grow by one stretch in one direction and the other stretch in the other, so of course the two multiply.
A way to guess both stretch numbers without dragging anything

Two facts pin them down for a box of four. The two stretch numbers multiply to the area factor, which you already know how to work out. They also add up to the sum of the top-left and bottom-right numbers. Take the box with 3 and 1 on top and 1 and 3 underneath. Its two stretch numbers must multiply to 8 and add to 6, and only 4 and 2 do both.

You can check that pair against the lab below, which reads them off the grid instead. Guessing like this runs out quickly on unfriendly numbers, and boxes bigger than two by two need a real method, but the two facts themselves stay true however large the box gets.

One more thing these numbers are good for. Apply the same matrix over and over to any arrow you like, and the direction with the biggest stretch takes over. Whatever you start with drifts toward that line and then stays there.

Lab 22 · Apply it again, and again
Try this firstPress Apply once six or seven times. Watch the arrow swing toward one of the dashed lines and then stop turning. The list underneath records the angle each round, so you can see the swing getting smaller. Then drag v somewhere else: the count clears itself, and you can press Apply once again from the new starting point.
Notice: almost every starting arrow ends up on the same line, and the ratio of one length to the last settles down to the bigger of the two stretch numbers. That is a working method for finding the biggest eigenvalue of a matrix nobody has analysed, and Lab 25 uses it on something real.
A matrix has eigenvalues 4 and 0.5. What is its area factor, ignoring any flip?
Stretching by 4 one way and by a half the other way multiplies areas by 4 × 0.5, which is 2. Adding them is the tempting move. The check against it is the unit square from Step 6. One stretch multiplies its width and the other multiplies its height, and an area is width times height, so the two numbers have to multiply. The lab above prints both of them beside the area factor.
Step 12

Turn a character, shrink a picture, rank the pages

Three jobs that look unrelated. All three are a matrix doing what you have watched it do, and this step is where the dragging pays for itself.

Start with the easiest. A game character on screen is a list of corner points. Turning it is a matrix applied to every one of those points, and the two columns are just where i and j land after the turn.

What a picture is made of

A screen is a grid of tiny squares called pixels, each one holding a number that says how bright it is. A small grey picture eight pixels across and eight down is therefore 64 numbers. Any grid of numbers with rows and columns like that is a matrix too, just a bigger one than the boxes of four you have been dragging.

Everything in this course was stated for the two-by-two case because you can see it. The ideas do not stop there. An eight-by-eight matrix has eight columns, up to eight eigen-directions to hunt for, and the same question about what gets lost when it is squashed. Only up to eight, because a matrix can come with fewer of those lines than it has columns, exactly as the pure turn in Step 10 came with none.

Lab 23 · Turn and squash a character
Try this firstDrag the turn slider. The shape rotates and the four numbers in the box change as you drag, so you can watch a rotation matrix being built. Then drag the squash slider and see the shape flatten while the box changes in a different way.
Notice: the turn never changes the area factor, which reads 1 all the way round while the four numbers in the box change completely. A rotation moves everything and destroys nothing, so it must leave areas alone. The squash slider, on the other hand, drives the area factor straight toward 0.

Now the picture. A grey image is a big grid of brightness numbers, and storing all of them is expensive. If the image can be built out of a few simple layers instead, you store the layers.

What the word algorithm means

An algorithm is a recipe written precisely enough that a machine can follow it without judgement: do this, then that, and stop when the following is true. Long division is an algorithm. So is the repeated-applying trick from Lab 22, which is the recipe the next two labs run.

The layer-finder below really does run that recipe while you watch, with a hard limit on how many rounds it may take so it can never sit there spinning. The numbers it prints are what it worked out from the picture, not figures typed in by an author.

Lab 24 · Rebuild a picture from a few layers
Try this firstDrag the layers slider from 0 up to 8. The picture on the right builds up one layer at a time, and the counters underneath say how many numbers each version costs and how wrong it still is. Then press A blurrier picture and do it again.
Notice: the first two or three layers do nearly all the work, and the last few barely change what you see. That is the whole idea behind image compression. Keep the layers that matter, throw away the rest, and accept a picture that is close rather than exact.

Last one, and it is the reason search engines work. Give every page on a small web a score, then let each page pass its score along its outgoing links, over and over. The scores settle down, and where they settle is a ranking.

Where the matrix is hiding in that

Put the pages' scores in a list. One round of passing scores along links takes that list and produces a new list, and each new score is built from the old ones by multiplying and adding. That is a matrix applied to a list, exactly as in Step 4, with one column per page instead of two.

So a round is one application of a matrix, and running many rounds is Lab 22 all over again. The ranking the scores settle on is the eigen-direction with the biggest eigenvalue, which for this kind of matrix works out to 1. The scores stop changing because they have found the direction that does not turn.

Lab 25 · Rank five pages by passing scores along links
Try this firstPress One more round five or six times. The bars swing hard for the first two or three rounds as each page hands its score to the pages it links to, and then the swings get small. Press Run twenty rounds to take it all the way to the point where the widget says the scores have stopped moving, and Rewire the links to try a different little web.
Notice: the winner is usually not the page with the most links pointing at it. A single link from a high-scoring page is worth more than several from pages nobody visits, and that falls out of the arithmetic without anyone deciding it should.
A game rotates a character by applying a matrix to each of its 400 corner points. A programmer worries that the character will slowly change size after thousands of rotations. What does the mathematics say?
A rotation has a determinant of exactly 1, so areas come through untouched however many times you apply it. Lab 23 prints that number while you drag the slider, and it does not budge. In real code the corners do drift slightly, but from rounding the stored numbers, not from anything the rotation itself does.
Step 13

Length and angle come from the dot product

For vectors u=(u₁,u₂) and v=(v₁,v₂), the dot product is u·v=u₁v₁+u₂v₂. It is a number, not a vector. The length of v is ||v||=√(v·v). A unit vector has length 1 and records direction without scale.

The same dot product also equals ||u||||v||cos θ. A positive result means an acute angle, zero means perpendicular, and a negative result means an obtuse angle. Dividing the dot product by both lengths gives cosine similarity, which compares direction while ignoring magnitude.

Distance and similarity need a scale choice

Euclidean distance treats one unit in every coordinate equally. Standardising features, weighting coordinates or learning an inner product changes the geometry. A nearest neighbour is meaningful only after that choice, and a physical displacement may need its original length.

Lab 26 · Turn one vector around another
Try this firstMove the angle to 90 degrees. The dot product should reach zero while both lengths stay fixed.
Zero means perpendicular only when neither vector is zero. The zero vector has no direction.
Lab 27 · Compare distance with cosine
Try this firstChoose same direction, different length. Cosine similarity stays 1 while Euclidean distance grows.
Use the metric that matches the question. Document length may be nuisance for text embeddings but necessary for a physical displacement.
What does u·v=0 say for two nonzero vectors?
The cosine of their angle is zero. That happens at 90 degrees.
Step 14

A basis is a coordinate measuring kit

A set of vectors is linearly independent when none can be made from the others. Their span is every linear combination they can reach. A basis is an independent spanning set: enough directions to describe the space, with no redundant one.

Coordinates belong to a basis. The physical arrow does not change when its coordinates change from standard axes to tilted axes. The number of vectors in any basis is the dimension. In a plane it is two; in RGB colour it is three; an embedding may use hundreds or thousands.

Affine coordinates add an origin

Vectors describe displacement from zero. Points also need an origin. Graphics often add a homogeneous coordinate so translation can join rotation and scaling inside one larger matrix.

Lab 28 · Test whether two directions form a basis
Try this firstChoose independent. Then make one direction a multiple of the other and watch the reachable plane collapse to a line.
In two dimensions, independence is the same determinant test from Step 6.
Lab 29 · Describe one arrow in three bases
Try this firstSelect tilted axes. The coordinates change but the reconstructed arrow stays at (4,2).
A change-of-basis matrix converts descriptions. It does not move the underlying vector.
Why can three vectors in a plane not all be independent?
The third vector is already a combination of the first two.
Step 15

Elimination exposes pivots, rank and free variables

Gaussian elimination replaces equations with equivalent ones. Swap two rows, multiply a row by a nonzero number, or add a multiple of one row to another. These moves preserve the solution set while creating zeros below pivot positions.

A pivot column adds an independent direction. The number of pivots is the rank. A non-pivot input column creates a free variable and therefore a null-space direction. Rank-nullity says rank plus nullity equals the number of input columns.

Reduced row echelon form is useful for explanation, but software often uses LU or QR factorisation and pivoting instead of forming the full reduced matrix. The result and the numerical method are separate questions.

Pivoting chooses a safer next equation

Dividing by a tiny pivot magnifies rounding error. Partial pivoting swaps in a larger available entry before elimination. The exact equations are equivalent either way, but their floating-point behaviour can differ greatly.

Lab 30 · Eliminate one column at a time
Try this firstAdvance the row operations. Watch pivots appear without changing the represented solution.
A zero row can be harmless or contradictory. The augmented entry decides which.
Lab 31 · Balance rank and nullity
Try this firstChoose a 3-column matrix of rank 2. One free direction must remain.
Rank counts independent output directions; nullity counts input directions erased to zero.
A matrix has 5 input columns and rank 3. What is its nullity?
Five minus three is two. Rank plus nullity equals the input dimension.
Step 16

Projection finds the closest answer a model can express

The projection of v onto a nonzero direction u is ((v·u)/(u·u))u. The leftover error is perpendicular to u. For a subspace with an orthonormal basis, project onto each basis vector and add the pieces.

An overdetermined system Ax=b may have no exact solution. Least squares chooses x that minimises ||Ax-b||². At the optimum, the residual b-Ax is perpendicular to every column of A, giving the normal equations AᵀAx=Aᵀb.

QR is usually better than normal equations

Forming AᵀA squares the condition number and can lose accuracy. QR factorisation builds an orthonormal basis for the columns and solves the same least-squares problem more stably.

Lab 32 · Drop a perpendicular to a line
Try this firstChange the target vector. The projection slides along the model line while the residual stays perpendicular.
Closest means closest under the chosen norm. A different distance measure can choose a different fit.
Lab 33 · Fit a line to measured points
Try this firstAdd one outlier. Least squares moves because squared residuals give large errors extra weight.
Inspect residuals, not only the fitted coefficients. Curves and unequal spread reveal model mismatch.
At a least-squares solution, what is true of the residual?
The residual is the part the model cannot express.
Step 17

SVD separates directions, strengths and rank

Every real matrix has a singular value decomposition A=UΣVᵀ. V chooses orthonormal input directions, Σ stretches them by nonnegative singular values, and U chooses orthonormal output directions. Unlike eigenvectors, singular vectors work for rectangular matrices and always provide orthonormal bases.

Keeping the largest k singular values gives the best rank-k approximation under common matrix norms. PCA applies the same geometry to centred data and keeps directions with the most variance. The image layers in Lab 24 are a low-rank approximation.

Modern ML uses this algebra everywhere: embeddings are rows in large matrices; attention compares projected vectors; low-rank adaptation trains small factor matrices; quantisation stores approximate values. These methods save memory or computation, but evaluation must check what information was lost.

Randomised low-rank methods avoid reading every direction repeatedly

A random sketch can find an approximate important subspace before a smaller SVD is computed. The speed gain comes with probability and approximation error, so report the seed, retained energy and downstream quality rather than only matrix rank.

Lab 34 · Watch rotate, stretch, rotate
Try this firstAdvance through Vᵀ, Σ and U. A complicated matrix becomes three understandable moves.
The number of nonzero singular values is the rank.
Lab 35 · Keep principal components
Try this firstSwitch from two components to one. The cloud flattens onto its strongest direction and reconstruction error grows.
High variance is not automatically useful or fair. PCA ignores labels, causality and downstream harm.
What does a zero singular value mean?
That singular direction is stretched by zero.
Step 18

A correct formula can still give an unstable answer

The condition number compares the largest and smallest singular values. A large value means some input directions are stretched far more than others. Solving then amplifies measurement or rounding error along the weak direction.

Conditioning belongs to the problem; stability belongs to the algorithm. Partial pivoting, QR, SVD and iterative refinement control avoidable numerical error. Explicitly computing A⁻¹ to solve Ax=b is usually slower and less stable than solving the factorised system directly.

Report residual ||Ax-b|| and, when possible, forward error or a condition estimate. A tiny residual can coexist with an inaccurate x when the problem is ill-conditioned. Use scaled tests and higher precision to diagnose, not to hide, the geometry.

Automatic differentiation uses the same matrix products

Reverse-mode automatic differentiation propagates vector-Jacobian products backward through a computation graph. Large or tiny singular values help explain exploding and vanishing gradients. Stable training still needs measured scales, not only symbolic derivatives.

Lab 36 · Bring two columns close together
Try this firstLower the angle between the columns. The determinant shrinks and the condition estimate climbs.
Near dependence is a warning before exact singularity.
Lab 37 · Perturb the right-hand side
Try this firstAdd a tiny measurement error. Compare the change in b with the much larger change in the solved x.
The solver did not invent the sensitivity. Nearly parallel columns made the original question unable to distinguish two directions reliably.
Why is a small residual not always proof that x is accurate?
The weak direction hides input error.
Finished

What you can do now

You started with a grid and an arrow. Here is the list, and it is worth reading slowly, because most of it is usually taught as arithmetic and you learned it as pictures.

How this maps onto a normal textbook

What this course called "where i and j land" a book calls matrix-vector multiplication."Two moves in a row" is matrix multiplication."The area factor" is the determinant,"the undo" is the inverse, "which arrow lands on the target" is solving a linear system, and "the lines that hold still" are eigenvectors with their eigenvalues.

Nothing was simplified into a shape you have to unlearn. The pictures are what the symbols mean, so a book's notation should now read as a shorthand for something you have already dragged around with your own hands.

Lab 38 · The whole thing, unmarked
Try this firstType any four numbers into the box and press Apply. The three switches under the grid turn the extra drawings on and off: the unit square, the eigen-lines if this box has any, and the faint original grid. The readout keeps printing whatever it can work out either way. Nothing here is marked and nothing is checked.
Things worth trying: a box with two identical columns, to watch the grid fold. A box with a large negative number, to see a flip and a stretch at once. Numbers close to a preset but not quite, to see how far the eigen-lines swing for a small change.
  • Read a matrix as a pair of landing spots, and sketch what it does to a grid.
  • Apply a matrix to a vector without looking up a rule, by scaling the two columns and adding.
  • Combine two moves, and say why the order matters.
  • Work out a determinant and say what it means about area and about flipping.
  • Recognise a squashed matrix on sight and say what has been lost.
  • Turn a pair of equations into a question about arrows, and know when it has one answer, none, or endlessly many.
  • Find eigen-directions by hunting, and their eigenvalues by measuring the stretch.
  • Explain what a search engine's ranking has to do with a direction that does not turn.
  • Use dot products to measure length, angle, projection and cosine similarity.
  • Choose a basis, change coordinates, and connect pivots to rank and free variables.
  • Fit an overdetermined system by least squares and inspect its residuals.
  • Read SVD and PCA as directions plus strengths, including low-rank uses in modern ML.
  • Recognise an ill-conditioned problem and distinguish sensitivity from solver stability.
One last one, with everything in it. A matrix has 1 and 2 on the top row and 2 and 4 on the bottom. Without a widget, what do you know about it?
Both columns point along the same line, since (2, 4) is two lots of (1, 2). Everything the matrix can produce lies on that line, the determinant is 1×4 − 2×2 = 0, there is no inverse, and one of its eigenvalues is 0. Spotting a repeated column is the fastest determinant check there is.

Where this goes next

  • More than two dimensions. Three columns instead of two, the determinant as a volume factor, and the same squash question about whether a whole plane gets flattened.
  • Introduction to Algorithms. The repeated-applying trick from Lab 22 is one method among many, and comparing methods by counting their work is a subject of its own.
  • Data Structures. A matrix is stored as a grid of numbers in memory, and how you lay that grid out changes how fast the arithmetic runs by a surprising margin.
  • Neural Networks and Training That Works. Embeddings, attention, gradient propagation, low-rank adaptation and numerical evaluation all use the later chapters directly.
  • Control Systems and Optimisation. State-space models, least squares, eigenvalues, conditioning and iterative solvers continue there.