Math for ML / Linear Algebra
0 / 16

Linear algebra, visually

A hands-on study companion to the 16 videos in 3Blue1Brown's Essence of Linear Algebra. Every idea comes with a picture you can grab and drag, a worked example, the traps people fall into, and multiple-choice questions that start easy and get hard, an "in machine learning" note, and optional Python coding problems with automatic tests.

How to use this page

  • Watch, then play. Each chapter links to its video. Watch it, then come back and drag the figure until the idea feels obvious.
  • Colours mean the same thing everywhere: î (the x basis vector) is green, ĵ (the y basis vector) is red, k̂ is blue, and other vectors are gold and purple. A dot with a ring around it can be dragged (mouse or finger).
  • Questions get harder as you go: Warm-up Practice Think Challenge. Every question is multiple choice with exactly one right answer. Pick one, press Check answer, and the full worked solution opens.
  • Code it (optional): each chapter ends with Python problems, many of them machine-learning flavoured. Write your code in the box and press Submit to run it against test cases. Python runs in your browser; the first run downloads it (about 10–20 seconds, internet needed).
  • Your progress is saved in this browser. Tick "mark as done" at the end of a chapter and the bar at the top fills up.
Chapter 1

Vectors, what even are they?

Watch: Vectors | Chapter 1

A vector is an arrow that starts at the origin. Equivalently, it's the list of numbers saying how to walk to its tip. You can add vectors and you can scale them, and the rest of linear algebra is built on those two moves.

People mean three slightly different things by "vector":

  • Physics: an arrow with a length and a direction. Slide it around and it's the same vector.
  • Computer science: an ordered list of numbers, like (house size, price). Order matters.
  • Mathematics: anything you can sensibly add and scale. We come back to this in chapter 16.

Linear algebra moves back and forth between the first two. Plant every arrow with its tail at the origin, and then each arrow matches exactly one list of numbers. The vector (3, −2) means "walk 3 right, then 2 down". The numbers are its coordinates.

Adding v + w: put the tail of w on the tip of v. The sum is the arrow from the origin to where you end up. It's "do one movement, then the other", and in coordinates you add matching entries: (1, 2) + (3, −1) = (4, 1).

Scaling by a number c (a scalar) stretches the arrow by c, flipping it around if c is negative. In coordinates, multiply every entry: 2·(1, 2) = (2, 4).

Drag the tips of v (gold) and w (purple). The faded purple copy of w starts at the tip of v; the green arrow is the sum. Move the slider to scale v by c (dashed).

Worked exampleAdd and scale

Let v = (1, 2) and w = (3, −1).

  • v + w = (1+3, 2+(−1)) = (4, 1).
  • 2v = (2, 4), and −1.5w = (−4.5, 1.5).
  • w − v = (2, −3). That's the arrow from the tip of v to the tip of w: v + (w − v) = w.

Watch outCommon misconceptions

  • "A vector and a point are the same thing." We often stand for a vector by its tip, but adding two points doesn't mean anything until you treat them as arrows from an origin.
  • "Vectors only live in 2D or 3D." A list of 50 numbers is a perfectly good vector. You just can't draw it, and you don't need to.
  • "Negative scaling shrinks." It flips the direction. −2v is twice as long as v and points the opposite way.

In ML & deep learningWhere this shows up

In ML, every piece of data is a vector. A 28×28 grayscale image is a list of 784 numbers. A row in a spreadsheet of house prices is a vector of features. In a language model every token becomes an embedding, a vector of a few thousand numbers. The two moves from this chapter do real work: averaging embeddings (add, then scale by 1/n) summarises a sentence, and the famous analogy king − man + woman ≈ queen is plain vector arithmetic. Even training is vector arithmetic: one gradient-descent step is w ← w − η·∇L, a scaled vector subtracted from the weight vector.

Practice (pick one answer per question)

Compute (2, 5) + (−3, 1).

  1. (−1, 6)
  2. (−1, 4)
  3. (5, 6)
  4. (−6, 5)

(2 − 3, 5 + 1) = (−1, 6).

Compute 3·(1, −2).

  1. (3, −6)
  2. (3, −2)
  3. (4, 1)
  4. (1, −6)

(3, −6): three times as long, same direction.

Compute 2(1, 4) − (3, −1).

  1. (−1, 9)
  2. (−1, 7)
  3. (5, 7)
  4. (−2, 9)

(2, 8) − (3, −1) = (2 − 3, 8 + 1) = (−1, 9).

Find c with c·(2, −3) = (−5, 7.5).

  1. c = −2.5
  2. c = 2.5
  3. c = −0.4
  4. c = −1.5

From the first entry, 2c = −5, so c = −2.5. Check the second: −2.5 · −3 = 7.5 ✓. So c = −2.5: the vector is flipped and made 2.5 times longer.

How long is (3, 4)? Find the vector of length 1 pointing the same way.

  1. Length 5; unit vector (0.6, 0.8)
  2. Length 7; unit vector (3/7, 4/7)
  3. Length 5; unit vector (3, 4)
  4. Length √7; unit vector (0.6, 0.8)

Pythagoras: √(3² + 4²) = √25 = 5. Divide by 5 to get the unit vector (0.6, 0.8); check: 0.36 + 0.64 = 1 ✓.

You know v + w = (4, 1) and v − w = (2, 5). Find v and w.

  1. v = (3, 3), w = (1, −2)
  2. v = (6, 6), w = (2, −4)
  3. v = (1, −2), w = (3, 3)
  4. v = (3, 3), w = (−1, 2)

Add the two equations: 2v = (6, 6), so v = (3, 3). Then w = (4, 1) − (3, 3) = (1, −2). Check: (3, 3) − (1, −2) = (2, 5) ✓.

Which expression gives the midpoint between the tips of v and w?

  1. ½(v + w)
  2. ½(w − v)
  3. v + w
  4. ½v − ½w

Start at the tip of v and go halfway along the arrow w − v, which runs from tip to tip: v + ½(w − v) = ½v + ½w. It's symmetric in v and w, as a midpoint should be. It's also the centre of the parallelogram with sides v and w.

How many vectors of length exactly 5 have whole-number coordinates that are both ≥ 0?

  1. 4: (0, 5), (3, 4), (4, 3), (5, 0)
  2. 2: (3, 4) and (4, 3)
  3. 3: (0, 5), (5, 0), (3, 4)
  4. 6

We need x² + y² = 25 with x, y ≥ 0. Trying x = 0…5 gives y² = 25, 24, 21, 16, 9, 0. Only 25, 16, 9 and 0 are perfect squares, so the answers are (0, 5), (3, 4), (4, 3), (5, 0).

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 2

Linear combinations, span, and basis vectors

Watch: Linear combinations, span, and basis vectors | Chapter 2

Coordinates are amounts by which you scale the basis vectors. The span of some vectors is every place you can reach by scaling and adding them. A basis is a set of vectors that reaches everything, with none wasted.

Look at the coordinates (3, −2) again: they say "3 times î plus −2 times ĵ". î = (1, 0) and ĵ = (0, 1) are the basis vectors of the usual coordinate system, and coordinates are the scalars you apply to them.

Nothing forces you to use î and ĵ. Pick any two vectors v and w. A sum like av + bw is a linear combination. If you fix one scalar and vary the other, the tip traces a straight line, which is where the name comes from.

The span of v and w is the set of every linear combination: all the places you can reach. For two vectors in the plane there are three possibilities:

  • they point in different directions: the span is the whole plane;
  • they line up (one is a multiple of the other): the span is a line through the origin;
  • both are zero: the span is just the origin.

Vectors are linearly dependent when one of them is redundant because it's already in the span of the others. Otherwise they are linearly independent: each one adds a new direction. In 3D, three vectors span all of space unless the third lies in the plane of the first two.

A basis is a linearly independent set that spans the space. Each vector then has exactly one recipe in terms of the basis, so the coordinates are unique. Different bases give different coordinates for the same arrow; that's chapter 13.

Drag v and w, and use the sliders to choose a and b. The gold arrow is av + bw. Press Wander to let a and b drift, leaving a trail: it covers the plane, until you line v and w up and the trail gets stuck on one line.

Worked exampleFinding the recipe

Write (5, 1) as a·(1, 1) + b·(1, −1). Matching entries gives a + b = 5 and a − b = 1. Adding them: 2a = 6, so a = 3 and b = 2. Check: 3(1, 1) + 2(1, −1) = (3+2, 3−2) = (5, 1) ✓. Since (1, 1) and (1, −1) are independent, this recipe is the only one.

Watch outCommon misconceptions

  • "Two vectors always span a plane." Only if they point in different directions. (2, 4) and (−1, −2) span just a line.
  • "Dependent means parallel." For two vectors, yes. For three or more, no: (1, 0, 0), (0, 1, 0) and (1, 1, 0) are dependent although no two of them are parallel.
  • "There's one correct basis." Any two independent vectors form a basis of the plane. î and ĵ are just the convenient default.

In ML & deep learningWhere this shows up

If one feature is a linear combination of others (say "price in dollars" next to "price in euros"), it adds no new direction to the span. That's multicollinearity: the model can't tell the two apart, and regression weights become unstable. Embedding dimension is the number of independent directions a model can use to encode meaning. LoRA, the popular way to fine-tune large models cheaply, restricts each weight update to the span of a handful of vectors (a low-rank update), and it works because useful updates seem to live in a small span.

Practice (pick one answer per question)

Write (7, −3) as a combination of î and ĵ.

  1. 7î − 3ĵ
  2. −3î + 7ĵ
  3. 7î + 3ĵ
  4. 4(î + ĵ)

7î − 3ĵ. The coordinates are the scalars.

Is (2, 4) in the span of (1, 2)?

  1. Yes: (2, 4) = 2·(1, 2)
  2. No, they point in different directions
  3. Yes, but only if you also use ĵ
  4. No: the span of one vector is just a point

Yes: (2, 4) = 2·(1, 2). The span of one nonzero vector is the line through it.

Are (2, −6) and (−1, 3) linearly independent? What is their span?

  1. Dependent; the span is the line y = −3x
  2. Independent; the span is the whole plane
  3. Dependent; the span is the line y = 3x
  4. Independent; the span is a line

Dependent: (2, −6) = −2·(−1, 3). Their span is the line y = −3x.

For which k are (1, k) and (k, 4) dependent?

  1. k = 2 or k = −2
  2. k = 4 only
  3. k = 2 only
  4. k = 0

Dependent exactly when the area they span is 0: 1·4 − k·k = 0, so k² = 4 and k = 2 or k = −2. Check k = 2: (2, 4) = 2·(1, 2) ✓. Check k = −2: (−2, 4) = −2·(1, −2) ✓.

Write (4, 7) in the basis (2, 1), (1, 3).

  1. (1, 2)
  2. (2, 1)
  3. (4, 7)
  4. (1, 3)

Solve a(2, 1) + b(1, 3) = (4, 7), that is, 2a + b = 4 and a + 3b = 7. From the first, b = 4 − 2a. Substituting: a + 12 − 6a = 7, so a = 1 and b = 2. Check: (2, 1) + (2, 6) = (4, 7) ✓. Coordinates: (1, 2).

What is the span of (1, 0, 1), (0, 1, 1) and (1, 1, 2) in 3D? Give an equation for it.

  1. A plane: z = x + y
  2. All of 3D space
  3. A line through (1, 1, 2)
  4. A plane: x + y + z = 0

(1, 1, 2) = (1, 0, 1) + (0, 1, 1), so the third vector is redundant. The first two are independent, so the span is a plane. Every point x(1,0,1) + y(0,1,1) = (x, y, x + y) satisfies z = x + y, and every point with z = x + y has that form. Check (1, 1, 2): 2 = 1 + 1 ✓.

Why can three vectors in the plane never be linearly independent?

  1. If two of them are independent they already span the plane, so the third is in their span
  2. Because three vectors always add up to zero
  3. Because the third one must be parallel to the first
  4. They can be, as long as no two are parallel

If the first two are dependent, we're done. If they're independent, they span the whole plane, so the third is already in their span and is redundant. In both cases one vector is redundant.

If v and w are independent in 2D, how many ways are there to write a given vector as av + bw?

  1. Exactly one
  2. At most one, and sometimes none
  3. Infinitely many
  4. Exactly two (swap a and b)

At least one: independent vectors in 2D span the plane. At most one: suppose av + bw = a'v + b'w. Then (a − a')v = (b' − b)w. If a ≠ a', divide to get v as a multiple of w, which contradicts independence. So a = a', and then (b' − b)w = 0 with w ≠ 0 gives b = b'.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 3

Linear transformations and matrices

Watch: Linear transformations and matrices | Chapter 3

A linear transformation keeps grid lines parallel and evenly spaced and leaves the origin fixed. Its matrix lists where î and ĵ land, as columns.

1. A transformation is a function you can watch

A transformation takes in a vector and gives back a vector. "Transformation" rather than "function" is a hint to picture motion: every point of the plane slides to its new home all at once. Do that with the whole grid and you can see what the function does at a glance.

2. What makes it "linear"

A transformation is linear when, as you watch it:

  • the origin stays where it is, and
  • grid lines stay straight, parallel and evenly spaced.

Rotations, stretches, shears, reflections and squishing onto a line all pass. Shifting everything right (the origin moves) fails, and so does anything that bends lines. In algebra the same two rules read: T(v + w) = T(v) + T(w) and T(cv) = c·T(v).

3. Two vectors tell you everything

Any vector (x, y) is a recipe: "x copies of î plus y copies of ĵ". Grid lines stay parallel and evenly spaced, so that recipe survives the transformation. "Three steps along î, two along ĵ" turns into "three steps along the new î, two along the new ĵ":

T(xî + yĵ) = x·T(î) + y·T(ĵ).

So once you know the two landing spots T(î) = (a, c) and T(ĵ) = (b, d), you know where every vector goes. Write them side by side as columns. That's the matrix:

a b; c dx; y = xa; c + yb; d = ax+by; cx+dy.

Multiplying a matrix by a vector just means scale the columns by the vector's coordinates and add them up. The "row times column" rule you may have memorised is this same computation written out entry by entry.

Type a matrix or drag the green and red tips (where î and ĵ land). Press Play to watch the whole grid move from "do nothing" to your matrix. The gold arrow is the test vector: dashed steps show it being rebuilt as x·(new î) + y·(new ĵ).

Worked exampleReading a matrix

Take M = 1 −1; 2 1. The first column says î lands at (1, 2) and the second says ĵ lands at (−1, 1). Where does v = (3, 2) go?

Mv = 3·1; 2 + 2·−1; 1 = 3; 6 + −2; 2 = 1; 8.

Row-by-column gives the same answer: (1·3 + (−1)·2, 2·3 + 1·2) = (1, 8). Type this matrix into the figure and set the test vector to (1, 1): it lands at 1·(1, 2) + 1·(−1, 1) = (0, 3).

GalleryMatrices worth knowing by sight

MatrixWhat it doesWhy (read the columns)
0 −1; 1 0Rotate 90° counter-clockwiseî → (0, 1), ĵ → (−1, 0)
cos θ, −sin θ; sin θ, cos θRotate by angle θî goes to the point at angle θ on the unit circle
1 1; 0 1Shearî stays put; ĵ tips over to (1, 1)
2 0; 0 0.5Stretch x, squash yî doubles, ĵ halves
−1 0; 0 1Mirror across the y-axisî flips to (−1, 0)
1 2; 0.5 1Squish the plane onto a lineBoth columns lie on the line through (2, 1)

Practise reading matrices

Guess the matrix. The blue grid has been transformed; the green dot is where î landed and the red dot is where ĵ landed. Type the matrix you think did it and press Check. Your guess is drawn in gold so you can compare.

Worked exampleA rotation applied to a vector

A 90° counter-clockwise rotation sends î → (0, 1) and ĵ → (−1, 0), so its matrix is 0 −1; 1 0. Applied to (3, 2): 3·(0, 1) + 2·(−1, 0) = (−2, 3). Sanity check: the original makes a right angle with the result, because (3, 2)·(−2, 3) = −6 + 6 = 0.

Watch outCommon misconceptions

  • "Columns vs rows doesn't matter." It does: 1 2; 0 1 and 1 0; 2 1 are different shears.
  • "Any function that keeps lines straight is linear." It also has to fix the origin and keep spacing even. A shift keeps lines straight but isn't linear.
  • "T(x, y) = (x², y) is linear because it's simple." Doubling the input doesn't double the output, so it isn't.

In ML & deep learningWhere this shows up

A dense (fully connected) layer computes y = Wx + b: a linear transformation followed by a shift. Column j of W says where input feature j "pushes" the output. On its own, a linear layer can only rotate, stretch, shear and squash the grid, which is why networks put a nonlinear activation (ReLU, GELU) after it. Bend the grid between linear steps and the network can draw curved decision boundaries.

Practice (pick one answer per question)

Apply 1 3; −2 0 to (5, 7).

  1. (26, −10)
  2. (5, −3)
  3. (21, −10)
  4. (26, 10)

5·(1, −2) + 7·(3, 0) = (5 + 21, −10 + 0) = (26, −10).

A transformation sends î → (−2, 1) and ĵ → (0, 4). What is its matrix?

  1. −2 0; 1 4
  2. −2 1; 0 4
  3. 0 −2; 4 1
  4. 1 −2; 4 0

Those are the columns: −2 0; 1 4.

Apply that matrix, −2 0; 1 4, to (3, −1).

  1. (−6, −1)
  2. (−6, 7)
  3. (−6, 3)
  4. (−5, 3)

3·(−2, 1) + (−1)·(0, 4) = (−6, 3) + (0, −4) = (−6, −1).

Write down the matrices for reflecting across (a) the x-axis and (b) the line y = x.

  1. (a) 1 0; 0 −1  (b) 0 1; 1 0
  2. (a) −1 0; 0 1  (b) 0 1; 1 0
  3. (a) 1 0; 0 −1  (b) 0 −1; −1 0
  4. (a) 0 1; 1 0  (b) 1 0; 0 −1

(a) î stays, ĵ → (0, −1): 1 0; 0 −1. (b) The reflection swaps î and ĵ: 0 1; 1 0.

Are these linear? T₁(x, y) = (x + 1, y), T₂(x, y) = (y, x − y), T₃(x, y) = (xy, 0).

  1. Only T₂
  2. T₁ and T₂
  3. T₂ and T₃
  4. All three

T₁: no, because T₁(0, 0) = (1, 0) moves the origin. T₂: yes, with matrix 0 1; 1 −1. T₃: no, because T₃(2, 2) = (4, 0) but 2·T₃(1, 1) = (2, 0).

A shear keeps î fixed and sends (1, 1) to (3, 1). Find the matrix.

  1. 1 2; 0 1
  2. 1 3; 0 1
  3. 3 0; 1 1
  4. 1 0; 2 1

ĵ = (1, 1) − î, so T(ĵ) = (3, 1) − (1, 0) = (2, 1). Matrix 1 2; 0 1. Check: (1, 1) → (1 + 2, 0 + 1) = (3, 1) ✓.

Why is the second column of the rotation matrix cos θ, −sin θ; sin θ, cos θ equal to (−sin θ, cos θ)?

  1. ĵ starts at 90°, so after rotating it sits at angle θ + 90°, which is the point (−sin θ, cos θ)
  2. Because both columns of a rotation matrix must be equal
  3. Because a rotation flips the sign of every entry in column 2
  4. Because a rotation must have determinant −1

Rotating î by θ puts it at the point at angle θ on the unit circle: (cos θ, sin θ). ĵ starts 90° further round, so it lands at angle θ + 90°: (cos(θ+90°), sin(θ+90°)) = (−sin θ, cos θ). Those are the two columns.

A linear map sends (1, 2) → (4, 1) and (3, 5) → (10, 4). Find its matrix.

  1. 0 2; 3 −1
  2. 2 0; −1 3
  3. 4 10; 1 4
  4. 0 3; 2 −1

We need M·1 3; 2 5 = 4 10; 1 4. The matrix 1 3; 2 5 has det 5 − 6 = −1, so its inverse is −5 3; 2 −1. Then

M = 4 10; 1 4−5 3; 2 −1 = −20+20, 12−10; −5+8, 3−4 = 0 2; 3 −1.

Check: (1, 2) → (0 + 4, 3 − 2) = (4, 1) ✓, and (3, 5) → (0 + 10, 9 − 5) = (10, 4) ✓.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 4

Matrix multiplication as composition

Watch: Matrix multiplication as composition | Chapter 4

Doing one transformation and then another is again a linear transformation. Its matrix is the product, which you read right to left: in BA, A happens first.

Rotate the plane, then shear it. The combined effect still fixes the origin and keeps the grid even, so it's linear and has its own matrix. That matrix is called the product. If A goes first and B second, we write BA, because it acts on a vector as B(Av). The order looks backwards, but it's the same as writing f(g(x)) for functions.

Computing it without memorising. To get the product, follow î and ĵ through both steps:

  • First column of BA = where î ends up = B·(first column of A).
  • Second column of BA = B·(second column of A).

Each of those is an ordinary matrix-times-vector product, which you know how to do from chapter 3.

Order matters. Rotating then shearing is usually different from shearing then rotating, so in general AB ≠ BA. Grouping doesn't matter: (AB)C = A(BC). Both mean "apply C, then B, then A" in that order. You can see it without any algebra.

A happens first, then B. Step through plays A, then B. Product in one go applies BA directly, and you'll see it ends in the same place. Swap order exchanges A and B so you can see that AB ≠ BA.

Worked exampleRotate, then shear

R = 0 −1; 1 0 (rotate 90°), S = 1 1; 0 1 (shear). Rotate first, so the product is SR.

  • î: R sends it to (0, 1), then S sends (0, 1) to (1, 1).
  • ĵ: R sends it to (−1, 0), then S sends (−1, 0) to (−1, 0).

So SR = 1 −1; 1 0. In the other order, RS = 0 −1; 1 1. They're different.

Watch outCommon misconceptions

  • "AB means do A first." It means do B first, because ABv = A(Bv).
  • "You multiply matching entries." That's a different, rarely used operation (the Hadamard product). The real product composes transformations.
  • "AB = 0 means A = 0 or B = 0." No. 0 1; 0 0 squared is the zero matrix.

In ML & deep learningWhere this shows up

A neural network is a composition: layer after layer, so f(x) = W₃·σ(W₂·σ(W₁x)). Leave out the activations σ and the whole stack collapses into one matrix W₃W₂W₁, with no extra expressive power (you'll prove it in code below). Processing a batch is one matrix product, X·Wᵀ, which is why GPUs, built for matrix multiplication, rule deep learning. Backpropagation multiplies Jacobian matrices in reverse order, the chain rule written as matrix composition.

Practice (pick one answer per question)

Compute 1 2; 3 45 6; 7 8.

  1. 19 22; 43 50
  2. 5 12; 21 32
  3. 23 34; 31 46
  4. 19 43; 22 50

Columns: the left matrix times (5, 7) is (5 + 14, 15 + 28) = (19, 43), and times (6, 8) is (6 + 16, 18 + 32) = (22, 50). Result 19 22; 43 50.

In the product ABC, which transformation happens first?

  1. C
  2. A
  3. B
  4. It depends on the sizes

C, then B, then A. Read right to left.

A = 2 0; 1 1, B = 1 3; −1 0. Where does î go under AB? Then write out all of AB.

  1. î → (2, 0); AB = 2 6; 0 3
  2. î → (5, −2); AB = 5 3; −2 0
  3. î → (2, 1); AB = 2 6; 1 3
  4. î → (2, 0); AB = 2 0; 6 3

B first: î → (1, −1). Then A: 1·(2, 1) + (−1)·(0, 1) = (2, 0). ĵ: B sends it to (3, 0), then A gives 3·(2, 1) = (6, 3). So AB = 2 6; 0 3, and î goes to (2, 0).

Compute the shear-then-rotate product RS for R = 0 −1; 1 0 and S = 1 1; 0 1, and confirm it differs from SR = 1 −1; 1 0.

  1. 0 −1; 1 1, which differs from SR
  2. 1 −1; 1 0, the same as SR
  3. 1 1; 0 1
  4. 0 1; −1 1

S first. î → (1, 0) → R gives (0, 1). ĵ → (1, 1) → R gives 1·(0,1) + 1·(−1,0) = (−1, 1). So RS = 0 −1; 1 1 ≠ SR.

Find a nonzero 2×2 matrix A with A² = 0. Describe what it does geometrically.

  1. 0 1; 0 0: it flattens the plane onto the x-axis, then sends that axis to 0
  2. 0 −1; 1 0: a 90° rotation
  3. 1 0; 0 0: a projection
  4. No nonzero 2×2 matrix can do this

0 1; 0 0: î → (0, 0) and ĵ → (1, 0) = î. It flattens the plane onto the x-axis, and the x-axis then gets sent to 0. Applying it twice sends everything to 0.

Why is (AB)C = A(BC)?

  1. Both describe the same steps: apply C, then B, then A
  2. Because AB = BA for all matrices
  3. Because determinants multiply
  4. It is only true for invertible matrices

Both sides describe the same thing: apply C, then B, then A. Brackets only change how you group the description, not what happens to the vector, so the results must agree.

R(β)R(α) = R(α+β). Comparing the top-left entries gives which formula?

  1. cos(α+β) = cos α cos β − sin α sin β
  2. cos(α+β) = cos α cos β + sin α sin β
  3. cos(α+β) = cos α + cos β
  4. sin(α+β) = sin α sin β − cos α cos β

Rotating by α and then by β is a rotation by α + β, so R(β)R(α) = R(α+β). The top-left entry of the product is (row 1 of R(β))·(column 1 of R(α)) = cos β cos α − sin β sin α. The top-left entry of R(α+β) is cos(α+β). So cos(α+β) = cos α cos β − sin α sin β. The bottom-left entry gives sin(α+β) = sin α cos β + cos α sin β.

For square matrices with AB = I, what can you conclude?

  1. BA = I too: det A ≠ 0, so A⁻¹ exists and B = A⁻¹
  2. Nothing about BA
  3. BA = −I
  4. Only that det B = 1

Determinants multiply (chapter 6): det(A)·det(B) = det(I) = 1, so det A ≠ 0 and A has an inverse A⁻¹. Multiply AB = I on the left by A⁻¹: B = A⁻¹. Then BA = A⁻¹A = I.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 5

Three-dimensional linear transformations

Watch: Three-dimensional linear transformations | Chapter 5

Same ideas, one more arrow. A 3×3 matrix has three columns: where î, ĵ and k̂ land.

In 3D there are three basis vectors: î = (1,0,0), ĵ = (0,1,0) and k̂ = (0,0,1). A linear transformation of space keeps grid planes flat, parallel and evenly spaced, and fixes the origin. Any vector (x, y, z) is xî + yĵ + zk̂, so it lands at x·T(î) + y·T(ĵ) + z·T(k̂). Those three landing spots are the three columns of a 3×3 matrix.

Composition works the same way: the product of 3×3 matrices means "do the right one first", and you can compute it column by column. 3D transformations are everywhere in computer graphics, robotics and physics. Every camera view in a video game is built by multiplying 3×3 (or 4×4) matrices.

Drag in the scene to turn the camera (on a phone, swipe sideways). Pick a preset or type a 3×3 matrix, then press Play to watch the unit cube and the floor grid move. The readout gives det, the factor by which volumes scale (next chapter).

Worked exampleApply a 3×3 matrix

Say î → (1, 0, 2), ĵ → (0, 1, 0) and k̂ → (−1, 0, 1). The matrix is 1 0 −1; 0 1 0; 2 0 1. The vector (1, 2, 3) lands at

1·(1,0,2) + 2·(0,1,0) + 3·(−1,0,1) = (1 − 3, 2, 2 + 3) = (−2, 2, 5).

Watch outCommon misconceptions

  • "3D needs a whole new theory." It doesn't. Columns, combinations and composition work identically. Only the pictures get harder.
  • "3D rotations commute because 2D ones do." 2D rotations commute with each other; 3D rotations about different axes don't (see Q6).

In ML & deep learningWhere this shows up

3D transforms are everyday tools in computer vision and robotics. Point-cloud models (LiDAR in self-driving cars) are trained on randomly rotated copies of the data. Camera models in 3D reconstruction and NeRF chain rotation matrices. Even colour is 3D: converting RGB to other colour spaces is a 3×3 matrix multiply applied to every pixel.

Practice (pick one answer per question)

Apply 2 0 1; 0 1 0; −1 0 3 to (1, −1, 2).

  1. (4, −1, 5)
  2. (4, 1, 5)
  3. (2, −1, 6)
  4. (0, −1, 5)

1·(2, 0, −1) + (−1)·(0, 1, 0) + 2·(1, 0, 3) = (2 + 2, −1, −1 + 6) = (4, −1, 5).

Write the matrix that rotates 90° about the z-axis (x-axis towards y-axis).

  1. 0 −1 0; 1 0 0; 0 0 1
  2. 0 1 0; −1 0 0; 0 0 1
  3. 1 0 0; 0 0 −1; 0 1 0
  4. 0 0 1; 0 1 0; −1 0 0

î → (0, 1, 0), ĵ → (−1, 0, 0), k̂ stays: 0 −1 0; 1 0 0; 0 0 1.

Which matrix flattens space onto the xy-plane (drops the z-coordinate to 0)?

  1. 1 0 0; 0 1 0; 0 0 0
  2. 0 0 0; 0 0 0; 0 0 1
  3. 1 0 0; 0 1 0; 0 0 −1
  4. 1 0 0; 0 1 0; 1 1 0

î and ĵ stay, k̂ → 0: 1 0 0; 0 1 0; 0 0 0.

The matrix 2 0 0; 0 3 0; 0 0 0.5 scales each axis. By what factor does it change volumes?

  1. 3
  2. 5.5
  3. 6
  4. 1

The unit cube becomes a 2 × 3 × 0.5 box, with volume 3.

A = 1 0 0; 0 0 −1; 0 1 0 (90° about x) and B = 0 −1 0; 1 0 0; 0 0 1 (90° about z). Compute AB.

  1. 0 −1 0; 0 0 −1; 1 0 0
  2. 0 0 1; 1 0 0; 0 1 0
  3. 0 −1 0; 1 0 0; 0 0 1
  4. 1 0 0; 0 0 −1; 0 1 0

B first. î → B gives (0,1,0) → A gives column 2 of A = (0, 0, 1). ĵ → (−1,0,0) → minus column 1 of A = (−1, 0, 0). k̂ → (0,0,1) → column 3 of A = (0, −1, 0). So AB = 0 −1 0; 0 0 −1; 1 0 0.

Now compute BA and confirm 3D rotations don't commute.

  1. BA = 0 0 1; 1 0 0; 0 1 0, which differs from AB
  2. BA = 0 −1 0; 0 0 −1; 1 0 0, the same as AB
  3. BA is the identity
  4. BA = 0 1 0; 0 0 1; 1 0 0, which differs from AB

A first. î → (1,0,0) → B gives (0, 1, 0). ĵ → (0,0,1) → B gives (0, 0, 1). k̂ → (0,−1,0) → B gives −(−1, 0, 0) = (1, 0, 0). So BA = 0 0 1; 1 0 0; 0 1 0, which is different from AB.

AB from Q5 is itself a rotation. Find its axis (the line that stays fixed) and its angle.

  1. Axis through (1, −1, 1); angle 120°
  2. Axis through (1, 1, 1); angle 120°
  3. Axis through (1, −1, 1); angle 90°
  4. The z-axis; angle 180°

Solve AB·(x, y, z) = (x, y, z), that is, (−y, −z, x) = (x, y, z). So x = −y, y = −z and z = x. Taking x = 1 gives y = −1 and z = 1, so the axis is the line through (1, −1, 1). Check: AB(1, −1, 1) = (1, −1, 1) ✓.

For the angle, a rotation by θ has trace 1 + 2cos θ. The trace (sum of the diagonal) is 0 + 0 + 0 = 0, so cos θ = −½ and θ = 120°.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 6

The determinant

Watch: The determinant | Chapter 6

The determinant is the factor by which a transformation scales areas (2D) or volumes (3D). It's negative when space gets flipped over, and zero when space is squashed into fewer dimensions.

Some transformations stretch space and some squash it. The determinant measures by how much: watch the unit square, whose area starts at 1. Its new area is the determinant, and every other region scales by the same factor. Further down you'll see why, for a b; c d, this factor is exactly ad − bc, and why it works for any two vectors.

  • det = 3: every area triples.
  • det = 0.5: every area halves.
  • det = 0: the plane gets squashed onto a line (or a point). Very useful to detect, as the next chapter shows.
  • det < 0: orientation flips, like turning the sheet face-down. Before, ĵ was counter-clockwise from î; afterwards it's clockwise. The size of the number is still the area factor.

In 3D, det is the volume factor (unit cube → parallelepiped). A negative sign means a right-handed set of axes became left-handed.

det(AB) = det(A)·det(B), and you barely need to prove it: do B, areas scale by det B; then do A, they scale by det A. In total they've scaled by the product.

Choose a matrix and scrub the slider from identity to the full transformation. The unit square (gold) and a circle (teal) both scale by the same factor, det. The fill turns purple when orientation flips.

Why the determinant is ad − bc: the parallelogram area, for any two vectors

Put the two vectors in as the columns of a matrix:

a b; c d   has first column (a, c) and second column (b, d),   and   det a b; c d = ad − bc.

Drag the two tips below. The shaded parallelogram is the one the vectors span, and the number underneath is ad − bc, recomputed as you drag. Count grid squares if you don't believe it: put the vectors at (2, 0) and (0, 3) and you get a 2 × 3 rectangle with area 6, and 2·3 − 0·0 = 6.

Drag the green tip (a, c) and the red tip (b, d). "Rectangle proof" draws the bounding box and the pieces you cut away. "Shear it" slides the red vector parallel to the green one until the shape is a rectangle, and the area stays the same the whole time.

Proof 1: start with a rectangle and cut pieces off

Take the case where both vectors are in the first quadrant and the green one (a, c) is the lower one, like the default picture. The parallelogram has corners at 0, (a, c), (a + b, c + d) and (b, d). Draw the smallest rectangle that holds it: it is (a + b) wide and (c + d) tall, so its area is

(a + b)(c + d) = ac + ad + bc + bd.

Inside the rectangle but outside the parallelogram there are six pieces, in matching pairs (switch on "Rectangle proof" to see them):

  • two triangles with legs a and c, each of area ac2, so ac in total;
  • two triangles with legs b and d, each of area bd2, so bd in total;
  • two small rectangles, each b wide and c tall, so 2bc in total.

Subtract them:

area = (ac + ad + bc + bd) − ac − bd − 2bc = ad − bc.

That's the whole formula: big rectangle minus the corners. The catch is that this picture only fits one arrangement of the vectors. For the others you need a different drawing, or the argument below that covers every case at once.

Proof 2: shearing, which works for any two vectors

The key fact is old geometry: sliding the top edge of a parallelogram along its own line doesn't change its area, because the base and the height stay the same. In vector terms, replacing the second vector w by w + kv (any number k) slides its tip parallel to v. The formula agrees with that:

a(d + kc) − (b + ka)c = ad + kac − bc − kac = ad − bc.  ✓

The formula ignores shears too, in either direction. So shear until the shape is easy to measure. If a ≠ 0:

  1. Replace (b, d) with (b, d) − ba(a, c) = (0, d − bca). The red vector is now vertical.
  2. Replace (a, c) with (a, c) minus a multiple of that vertical vector to get (a, 0). The green vector is now horizontal.
  3. Now the shape is a rectangle with sides a and d − bca, so its signed area is a·(d − bca) = ad − bc.

Neither shear changed the area or the value of ad − bc, so the two were equal from the start. If a = 0, the first vector is (0, c), which points straight up. The parallelogram then has base |c| along the y-axis and height |b| (the horizontal distance to the other vector), so the area is |bc| = |ad − bc| because ad = 0. That covers every pair of vectors.

Where the sign comes from

ad − bc can be negative, but area can't. The determinant measures signed area:

  • Positive when you turn counter-clockwise (by less than half a turn) to get from the first vector to the second, the same way you turn from î to ĵ.
  • Negative when that turn is clockwise. As a transformation, the plane has been flipped over, like turning a sheet of paper face-down. Swapping the two vectors always flips the sign.
  • Zero when the vectors lie on one line through the origin (or one of them is zero). The parallelogram is flat. Algebraically, ad = bc says the two vectors are proportional.

Why it's the area of every shape, not just squares

The matrix sends the unit square (area 1) to this parallelogram, so it multiplies the square's area by |ad − bc|. Now cover any region, say a circle or a cat silhouette, with a fine grid of tiny squares. A linear transformation treats every tiny square the same way: each one turns into a tiny parallelogram with |ad − bc| times the area. Add them up and the whole region's area is multiplied by |ad − bc|. A circle of area π becomes an ellipse of area π·|ad − bc|. This is why people say the determinant is the factor by which a transformation scales area.

Going deeperWhy it had to be ad − bc

Ask for any rule f(v, w) giving the signed area of the parallelogram on two vectors. Geometry forces three properties:

  • f(î, ĵ) = 1, because the unit square has area 1.
  • f(v, v) = 0, because a parallelogram on two copies of one vector is flat. (This also forces f(w, v) = −f(v, w).)
  • f is linear in each slot. Doubling one side doubles the area, and f(v, w + u) = f(v, w) + f(v, u), which is the shear picture again: base times height adds up.

Now write v = aî + cĵ, w = bî + dĵ and expand using linearity:

f(v,w) = ab·f(î,î) + ad·f(î,ĵ) + cb·f(ĵ,î) + cd·f(ĵ,ĵ) = ab·0 + ad·1 + cb·(−1) + cd·0 = ad − bc.

No other formula has those three properties. The same argument in 3D (three vectors, volume) gives the 3×3 determinant.

Worked example2×2 and 3×3

det 2 1; −1 3 = 2·3 − 1·(−1) = 7: areas get 7 times bigger.

For 3×3, expand along the top row with alternating signs:

det 1 2 0; 0 1 3; 2 0 1 = 1·(1·1 − 3·0) − 2·(0·1 − 3·2) + 0·(…) = 1 + 12 = 13.

Watch outCommon misconceptions

  • "det(A + B) = det A + det B." False. Try A = B = I in 2D: det(2I) = 4, but 1 + 1 = 2.
  • "det = 0 means the matrix is all zeros." 1 2; 2 4 has det 0 and plenty of nonzero entries. It just squashes the plane onto a line.
  • "Negative area is nonsense, so ignore the sign." The sign carries real information (orientation). Take the absolute value only when you want plain area.

In ML & deep learningWhere this shows up

Normalizing flows (a family of generative models) push simple noise through invertible layers. To keep probabilities correct they track how each layer scales volume, log|det J|, which is this chapter's idea exactly. The likelihood of a multivariate Gaussian contains log det Σ. And a Jacobian with determinant near 0 warns that a layer is collapsing information: different inputs get squashed together.

Practice (pick one answer per question)

det 3 1; 2 4 = ?

  1. 10
  2. 14
  3. 2
  4. −10

3·4 − 1·2 = 10.

det 2 4; 1 2 = ? What does the transformation do to the plane?

  1. 0: the plane is squashed onto a line
  2. 8: areas grow eightfold
  3. 4
  4. −2: orientation flips

2·2 − 4·1 = 0. Both columns lie on the line through (2, 1), so the whole plane is squashed onto that line.

det 0 1; 1 0 = ? Interpret it.

  1. −1: a mirror flip; areas stay the same
  2. 1: a rotation
  3. 0: it squashes the plane
  4. −1: areas are halved

0 − 1 = −1. It's the mirror across y = x: areas are unchanged, but orientation flips.

A shape of area 5 goes through 3 1; 2 4. What is its new area?

  1. 50
  2. 15
  3. 2
  4. 10

Areas scale by |det| = 10, so 50.

det A = 3 and det B = −2. Find det(AB), det(BA) and det(A²).

  1. det(AB) = det(BA) = −6 and det(A²) = 9
  2. det(AB) = −6, det(BA) = 6, det(A²) = 9
  3. det(AB) = det(BA) = 1 and det(A²) = 6
  4. det(AB) = det(BA) = −6 and det(A²) = 6

det(AB) = det(BA) = 3·(−2) = −6 (scaling factors multiply in either order). det(A²) = 3·3 = 9.

det 1 2 3; 0 4 5; 0 0 6 = ?

  1. 24
  2. 21
  3. 6
  4. 0

For a triangular matrix, the determinant is the product of the diagonal: 1·4·6 = 24. (Expanding down the first column gives 1·(4·6 − 5·0) = 24 too.)

det 2 1 0; 1 3 1; 0 1 2 = ?

  1. 8
  2. 10
  3. 12
  4. 6

Expand along the top row: 2·(3·2 − 1·1) − 1·(1·2 − 1·0) + 0 = 2·5 − 2 = 8.

For an n×n matrix A, what is det(kA)? Explain it with volumes.

  1. kⁿ · det A
  2. k · det A
  3. n · k · det A
  4. det A: scaling doesn't change it

kA scales every one of the n column vectors by k, and each one scales the volume by k. So det(kA) = kⁿ det A. In 2D: det(2A) = 4 det A.

Which statement about det(A⁻¹) is true?

  1. det(A⁻¹) = 1/det A, so a matrix with det A = 0 has no inverse
  2. det(A⁻¹) = −det A
  3. det(A⁻¹) = det A
  4. det(A⁻¹) = 0 whenever det A < 0

A⁻¹A = I, so det(A⁻¹)·det(A) = det I = 1, which gives det(A⁻¹) = 1/det A. If det A = 0, that equation would say something × 0 = 1, which is impossible, so no inverse exists. Geometrically, a squashed plane can't be un-squashed into a function, because many points landed on the same spot.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 7

Inverse matrices, column space and null space

Watch: Inverse matrices, column space and null space | Chapter 7

Solving Ax = v means finding the vector that A moves onto v. If det A ≠ 0 you can run the movie backwards (A⁻¹) and there's exactly one answer. If det A = 0, space got squashed: there may be no answer or infinitely many.

A system of linear equations like 2x + y = 4, 5x + 3y = 11 is secretly one matrix equation, 2 1; 5 3x; y = 4; 11. In words: which vector x does this transformation carry onto v?

Case 1: det A ≠ 0. The transformation can be undone. The inverse A⁻¹ is "play it backwards", so A⁻¹A = I (doing nothing). The unique answer is x = A⁻¹v. For 2×2:

a b; c d−1 = 1ad − bcd −b; −c a.

Case 2: det A = 0. The plane got squashed onto a line (or a point). No function can unsquash it, because many inputs landed on the same output, so there's no inverse. A solution exists only if v happens to lie on the squashed line, and then there are infinitely many.

Some vocabulary for describing the squash:

  • Column space: every possible output Ax, which is the span of the columns. In this figure it's the line or plane that everything lands on.
  • Rank: the dimension of the column space. Rank 2 for a 2×2 means nothing was lost.
  • Null space (or kernel): every input that lands on 0. When space is squashed, a whole line (or more) collapses into the origin.
  • Rank–nullity: rank + dim(null space) = number of columns. Dimensions lost to the squash show up in the null space.
Pick a matrix and scrub. For a squashing matrix, the teal line is the column space (where everything lands), and the purple dots on the dashed null-space line all get sucked into the origin. Drag the gold target v to see whether Ax = v can be solved. Undo with A⁻¹ plays the transformation backwards when that's possible.

Worked exampleSolve with an inverse

Solve x + 2y = 5, 3x + 4y = 11. A = 1 2; 3 4 has det = 4 − 6 = −2 ≠ 0, so

A⁻¹ = 1−24 −2; −3 1 = −2 1; 1.5 −0.5,   x = A⁻¹5; 11 = −10+11; 7.5−5.5 = 1; 2.

Check: 1 + 4 = 5 ✓ and 3 + 8 = 11 ✓.

Watch outCommon misconceptions

  • "Every matrix has an inverse." Only those with det ≠ 0. (Nonsquare matrices never have a two-sided inverse.)
  • "The null space of an invertible matrix is empty." It always contains 0. For an invertible matrix it's only 0.
  • "Computers solve systems by computing A⁻¹." Usually not. Elimination (LU factorisation) is faster and more accurate. The inverse is mainly a way to think.

In ML & deep learningWhere this shows up

Linear regression is solving a linear system: the best weights satisfy (XᵀX)w = Xᵀy. When features are redundant, XᵀX is singular (det = 0) and there's no unique answer. Ridge regression adds λI to make it invertible. Rank measures how much information survives a layer: a 4096→64→4096 bottleneck has rank at most 64. The null space is the set of input changes a layer can't see at all.

Practice (pick one answer per question)

Find the inverse of 2 1; 5 3.

  1. 3 −1; −5 2
  2. 3 −5; −1 2
  3. 2 −1; −5 3
  4. −3 1; 5 −2

det = 6 − 5 = 1, so the inverse is 3 −1; −5 2. Check the first column of the product: (2·3 + 1·(−5), 5·3 + 3·(−5)) = (1, 0) ✓.

Use it to solve 2x + y = 4, 5x + 3y = 11.

  1. x = 1, y = 2
  2. x = 2, y = 1
  3. x = −1, y = 6
  4. x = 4, y = 11

3 −1; −5 24; 11 = (12 − 11, −20 + 22) = (1, 2). Check: 2 + 2 = 4 ✓ and 5 + 6 = 11 ✓.

For A = 1 2; 2 4, find the rank, the column space and the null space.

  1. Rank 1; column space = line through (1, 2); null space = line through (2, −1)
  2. Rank 2; column space = the plane; null space = {0}
  3. Rank 1; column space = line through (2, −1); null space = line through (1, 2)
  4. Rank 1; column space and null space are both the line through (1, 2)

det = 0 and the columns are (1, 2) and 2·(1, 2), so rank 1. The column space is the line through (1, 2). Null space: x + 2y = 0, so it's the line through (2, −1). Check: A(2, −1) = (2 − 2, 4 − 4) = (0, 0) ✓.

With the same A, does Ax = (3, 6) have a solution? What about Ax = (5, 1)?

  1. (3, 6): infinitely many solutions. (5, 1): none
  2. (3, 6): exactly one, (3, 0). (5, 1): none
  3. Both have infinitely many solutions
  4. Neither has a solution

(3, 6) = 3·(1, 2) is in the column space, so yes, infinitely many: x = (3, 0) + t(2, −1) for any t. (5, 1) isn't a multiple of (1, 2), so there is no solution.

Find the rank and null space of 1 2 3; 4 5 6; 7 8 9.

  1. Rank 2; null space = line through (1, −2, 1)
  2. Rank 3; null space = {0}
  3. Rank 1; null space = a plane
  4. Rank 2; null space = line through (1, 1, 1)

Row 3 = 2·row 2 − row 1, so there are at most two independent rows, and rows 1 and 2 aren't proportional: rank 2. For the null space, solve x + 2y + 3z = 0 and 4x + 5y + 6z = 0. Subtract 4 × the first from the second: −3y − 6z = 0, so y = −2z. Then x = −2y − 3z = 4z − 3z = z. The null space is the line through (1, −2, 1). Check row 3: 7 − 16 + 9 = 0 ✓.

Find the inverse of 1 0 1; 0 2 0; 1 0 2.

  1. 2 0 −1; 0 0.5 0; −1 0 1
  2. 2 0 1; 0 0.5 0; 1 0 1
  3. 1 0 −1; 0 2 0; −1 0 2
  4. 2 0 −1; 0 2 0; −1 0 1

The answer is 2 0 −1; 0 0.5 0; −1 0 1. Check by multiplying. Row 1 of A, (1, 0, 1), times the three columns gives 2 − 1 = 1, then 0, then −1 + 1 = 0. Row 2, (0, 2, 0), gives 0, 1, 0. Row 3, (1, 0, 2), gives 2 − 2 = 0, then 0, then −1 + 2 = 1. That's the identity ✓. (The determinant is 2, which is why the halves appear.)

A 3×3 matrix has rank 2. What is the dimension of its null space, and what could the solution set of Ax = v look like?

  1. The null space is a line; the solutions are either a whole line or there are none
  2. The null space is a plane; there are always infinitely many solutions
  3. The null space is {0}; there is exactly one solution
  4. The null space is a line; there is always exactly one solution

By rank–nullity, 3 − 2 = 1, so the null space is a line. If v is in the column space (a plane), the solutions form a whole line: one particular solution plus anything in the null space. Otherwise there are none.

If Ax = v has two different solutions p and q, what follows?

  1. p − q is a nonzero null-space vector, so p + t(p − q) solves it for every t: infinitely many solutions
  2. A must be the zero matrix
  3. There are exactly two solutions
  4. v must be the zero vector

Say Ap = Aq = v with p ≠ q. Then A(p − q) = 0, so n = p − q is a nonzero vector in the null space. For any t, A(p + tn) = v + t·0 = v, and different t give different vectors.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 8

Nonsquare matrices as transformations between dimensions

Watch: Nonsquare matrices as transformations between dimensions | Chapter 8

An m×n matrix takes n-dimensional inputs (one column per input basis vector) to m-dimensional outputs (each column has m coordinates).

Nothing says the output space has to match the input space. A 3×2 matrix like 2 0; −1 1; 3 2 has two columns, because the input is 2D with two basis vectors, and three rows, because each landing spot is a point in 3D. It lays the flat plane into space as a tilted plane through the origin.

  • 3×2: 2D → 3D. The image (column space) is at most a plane inside 3D, so it can never fill space.
  • 2×3: 3D → 2D. Three basis vectors land in the plane, so something gets squashed and at least a line of inputs collapses to 0.
  • 1×2: 2D → the number line. Each basis vector lands on a single number. These matter a lot in the next chapter.

Composition still works when the sizes fit: an (m×n)(n×p) product makes sense because the middle space matches. Outputs of the right-hand map must be valid inputs of the left-hand one.

A 3×2 matrix carries the flat 2D grid into 3D. Scrub from "flat in the floor" to the transformed plane, and drag to turn the view. The green and red arrows are the two columns. If they line up, the image is only a line.

Worked example2D in, 3D out

2 0; −1 1; 3 21; 2 = 1·2; −1; 3 + 2·0; 1; 2 = 2; 1; 7. Two input numbers, three output numbers.

Watch outCommon misconceptions

  • "A 3×2 matrix takes 3D inputs." Count columns for the input dimension. A 3×2 matrix takes 2D inputs.
  • "Nonsquare matrices have determinants." They don't. "Area scaling" makes no sense between different spaces.
  • "2D → 3D can fill space if the numbers are big." Two directions can never span three dimensions.

In ML & deep learningWhere this shows up

Almost every layer is nonsquare. A layer taking 784 pixels to 128 hidden units is a 128×784 matrix. Encoders squash high dimensions down; decoders and up-projections map back up. The "(m×n)(n×p)" size rule is behind most shape mismatch errors you'll hit in PyTorch: when you see one, ask which space each matrix maps from and to.

Practice (pick one answer per question)

Apply 1 0; 0 1; 1 1 to (2, 3).

  1. (2, 3, 5)
  2. (2, 3)
  3. (5, 5, 3)
  4. (2, 3, 6)

2·(1, 0, 1) + 3·(0, 1, 1) = (2, 3, 5).

Apply 1 2 3; 0 1 −1 to (1, 1, 1).

  1. (6, 0)
  2. (1, 1)
  3. (6, 0, 0)
  4. (1, 3, 2)

(1 + 2 + 3, 0 + 1 − 1) = (6, 0).

Which of these products are defined: (2×3)(3×2), (3×2)(2×3), (2×3)(2×3)? What size is each result?

  1. (2×3)(3×2) → 2×2; (3×2)(2×3) → 3×3; (2×3)(2×3) is not defined
  2. All three are defined
  3. (2×3)(3×2) → 3×3; (3×2)(2×3) → 2×2; (2×3)(2×3) is not defined
  4. Only (2×3)(2×3) is defined

(2×3)(3×2) gives a 2×2. (3×2)(2×3) gives a 3×3. (2×3)(2×3) is not defined: the right-hand matrix outputs 2D, but the left-hand one needs 3D inputs.

Compute 1 2 3; 0 1 −11 0; 0 1; 1 1.

  1. 4 5; −1 0
  2. 4 −1; 5 0
  3. 1 2 3; 0 1 −1; 1 3 2
  4. 4 5; 1 0

Columns: the left matrix times (1, 0, 1) is (1 + 3, 0 − 1) = (4, −1), and times (0, 1, 1) is (2 + 3, 1 − 1) = (5, 0). Result 4 5; −1 0.

Find the null space of 1 2 3; 0 1 −1. Why must every 2×3 matrix have a nonzero null space?

  1. The line through (−5, 1, 1). A 2×3 matrix has rank ≤ 2, so its null space has dimension ≥ 1
  2. The line through (1, 1, 1). A 2×3 matrix has rank 3
  3. Only {0}: the matrix is one-to-one
  4. A plane: the null space of a 2×3 matrix always has dimension 2

From row 2, y = z. From row 1, x = −2y − 3z = −5z. So the null space is the line through (−5, 1, 1). Check: −5 + 2 + 3 = 0 ✓ and 1 − 1 = 0 ✓. In general the rank is at most 2 (there are only 2 output dimensions), so by rank–nullity the null space has dimension at least 3 − 2 = 1.

Give an equation for the plane that 1 0; 0 1; 1 1 maps onto.

  1. z = x + y
  2. z = x − y
  3. x + y + z = 0
  4. z = 0

Outputs look like (x, y, x + y), so the plane is z = x + y (or x + y − z = 0).

The 1×2 matrix [3 4] maps the plane to the number line. Which inputs land on 0? Which vector u gives [3 4]x = u·x for every x?

  1. The line through (4, −3) maps to 0, and u = (3, 4)
  2. The line through (3, 4) maps to 0, and u = (4, −3)
  3. Only (0, 0) maps to 0, and u = (3, 4)
  4. The line through (4, −3) maps to 0, and u = (−4, 3)

3x + 4y = 0 is the line through (4, −3). And [3 4]x = 3x + 4y = (3, 4)·(x, y), so u = (3, 4). Every 1×2 matrix secretly is a vector; that's the "duality" of chapter 9.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 9

Dot products and duality

Watch: Dot products and duality | Chapter 9

v·w = (length of w's shadow on v) × (length of v), with a minus sign if the shadow points backwards. It's also the same thing as applying a 1×2 matrix: every linear map to the number line is "dot with some vector".

The numbers: multiply matching coordinates and add: (a, b)·(c, d) = ac + bd.

The picture: project w onto the line through v, then multiply the projection's length by |v|. So:

  • positive: they point roughly the same way (angle under 90°);
  • zero: perpendicular;
  • negative: roughly opposite (angle over 90°).

Equivalently, v·w = |v||w|cos θ. Swapping the roles (projecting v onto w) gives the same number. If both had length 1 it would be obvious by mirror symmetry, and scaling either vector scales both versions equally.

Why on earth do the numbers and the picture agree? Duality. Take a unit vector û = (ux, uy) and the map "project onto the line of û and read off the position". That map is linear, so it's a 1×2 matrix, and its columns are where î and ĵ land. By symmetry, î projects onto û's line at exactly ux (the same number as û's shadow on the x-axis), and ĵ lands at uy. So the matrix is [ux uy], and applying it is uxx + uyy = û·x. Projection is the dot product. A longer v just multiplies everything by its length.

The bigger lesson: 1×n matrices and n-dimensional vectors are two faces of the same thing. A vector can be thought of as "the linear map that dots with it". That's what duality means here, and it comes back in chapter 11.

Drag v (gold) and w (purple). The teal segment is w's projection onto v's line. Squish onto the number line animates the 1×2 matrix [vx vy]: every grid point slides to its value v·x on a number line along v.

Worked exampleAngle from a dot product

v = (3, 1), w = (2, 4). v·w = 6 + 4 = 10. |v| = √10 and |w| = √20, so cos θ = 10/√200 = 1/√2 and θ = 45°. The projection of w onto v's line has length 10/√10 = √10 ≈ 3.16.

Watch outCommon misconceptions

  • "The dot product is a vector." It's a single number (a scalar).
  • "v·w = 0 means one of them is zero." It means they're perpendicular (or one is zero).
  • "Projection length = v·w." Only if v has length 1. In general it's v·w / |v|.

In ML & deep learningWhere this shows up

The dot product may be the most-used operation in AI. A single neuron computes w·x + b. A linear classifier's decision boundary w·x + b = 0 is a line (or plane) perpendicular to w. Cosine similarity between embeddings powers semantic search, recommendations and retrieval-augmented generation (RAG). And attention in transformers scores every pair of tokens with a dot product, q·k/√d. You'll build both below.

Practice (pick one answer per question)

(2, −1, 3)·(4, 0, −2) = ?

  1. 2
  2. 14
  3. −6
  4. (8, 0, −6)

8 + 0 − 6 = 2.

Are (3, 4) and (4, −3) perpendicular?

  1. Yes: their dot product is 0
  2. No: their dot product is 24
  3. No: perpendicular vectors must have different lengths
  4. Only if both have length 1

12 − 12 = 0, so yes.

Find the angle between (1, 0) and (1, 1).

  1. 45°
  2. 90°
  3. 30°
  4. 60°

cos θ = 1 / (1·√2), so θ = 45°.

Project w = (2, 3) onto the line through v = (1, 1). Give the length and the projected vector.

  1. Length 5/√2 ≈ 3.54; projected vector (2.5, 2.5)
  2. Length 5; projected vector (5, 5)
  3. Length 2.5; projected vector (2.5, 2.5)
  4. Length 5/√2; projected vector (2, 3)

Length = v·w/|v| = 5/√2 ≈ 3.536. Vector = (v·w/v·v)v = (5/2)(1, 1) = (2.5, 2.5). Check that the leftover is perpendicular: (2, 3) − (2.5, 2.5) = (−0.5, 0.5), and (−0.5, 0.5)·(1, 1) = 0 ✓.

Describe every (x, y) with (x, y)·(1, 2) = 5.

  1. A line perpendicular to (1, 2)
  2. The line through the origin along (1, 2)
  3. A circle of radius 5
  4. Just the point (1, 2)

x + 2y = 5: a line perpendicular to (1, 2). Every point on it has the same shadow on (1, 2)'s direction.

Projecting onto the line through the unit vector (0.6, 0.8) and reading off the position is a linear map to the number line. What is its 1×2 matrix? Where does (5, 5) go?

  1. [0.6 0.8], and (5, 5) → 7
  2. [0.8 0.6], and (5, 5) → 1.4
  3. [0.6 0.8], and (5, 5) → 5
  4. The column (0.6, 0.8), and (5, 5) → (3, 4)

By duality the matrix is [0.6 0.8]. (5, 5) → 3 + 4 = 7.

Why are the diagonals of a rhombus perpendicular?

  1. (v + w)·(v − w) = |v|² − |w|² = 0, because the sides have equal length
  2. (v + w)·(v − w) = |v|² + |w|², which is always 0
  3. Because v·w = 0 in every rhombus
  4. Because the two diagonals have equal length

A rhombus has sides v, w with |v| = |w|, and its diagonals are v + w and v − w. Then (v + w)·(v − w) = v·v − w·w = |v|² − |w|² = 0. (The cross terms cancel because the dot product is symmetric.)

When does |v·w| = |v||w| hold (equality in Cauchy–Schwarz)?

  1. When v and w are parallel (one is a multiple of the other)
  2. When they are perpendicular
  3. When they have equal length
  4. Never: the inequality is always strict

Geometrically, v·w = |v| × (signed length of w's shadow), and a shadow is never longer than the thing casting it. Equality holds when the shadow is the whole of w, that is, when w lies on v's line: they're parallel. Algebraically, |cos θ| ≤ 1.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 10

Cross products

Watch: Cross products | Chapter 10

In 3D, v × w is a vector perpendicular to both, whose length is the area of the parallelogram they span. The right-hand rule picks which of the two perpendicular directions.

The 2D warm-up. For 2D vectors, "v × w" usually means the signed area of their parallelogram, which is the determinant with v and w as columns. It's positive if w is counter-clockwise from v. (Chapter 6 proves this.)

The real 3D cross product is a vector p = v × w with three properties:

  • its length equals the area of the parallelogram spanned by v and w;
  • it's perpendicular to both v and w;
  • its direction follows the right-hand rule: index finger along v, middle finger along w, and your thumb points along v × w.

In coordinates:

(v₁, v₂, v₃) × (w₁, w₂, w₃) = (v₂w₃ − v₃w₂,  v₃w₁ − v₁w₃,  v₁w₂ − v₂w₁).

A common way to remember it is a "determinant" with î, ĵ, k̂ in the first column. That's a notational trick, not a real determinant (the next chapter explains why it works). Swapping the order flips the direction, so w × v = −(v × w), and v × v = 0.

Set v and w with the number boxes and drag to turn the view. The teal arrow is v × w: perpendicular to the shaded parallelogram, with length equal to its area. Try swapping v and w.

Worked exampleCompute and check

(2, 0, 1) × (1, 3, 0) = (0·0 − 1·3,  1·1 − 2·0,  2·3 − 0·1) = (−3, 1, 6).

Check that it's perpendicular to both: (2, 0, 1)·(−3, 1, 6) = −6 + 0 + 6 = 0 ✓ and (1, 3, 0)·(−3, 1, 6) = −3 + 3 + 0 = 0 ✓. The area of the parallelogram is √(9 + 1 + 36) = √46 ≈ 6.78.

Watch outCommon misconceptions

  • "v × w = w × v." No: they're negatives of each other.
  • "|v × w| = |v||w|." Only when they're perpendicular. In general it's |v||w| sin θ.
  • "Cross products work in any dimension." This one is special to 3D. (In 2D you get a number; in higher dimensions people use other tools.)

In ML & deep learningWhere this shows up

Cross products matter most in 3D vision, graphics and robotics. Surface normals of mesh triangles (for lighting and 3D reconstruction) are cross products, and so are torque and angular velocity in robot dynamics. In two-camera geometry the "essential matrix" contains the matrix version of "cross with t". Core deep-learning code rarely uses them, but 3D deep learning does.

Practice (pick one answer per question)

2D: find the signed area for v = (3, 1) and w = (2, 4).

  1. 10
  2. 14
  3. −10
  4. 2

det = 3·4 − 2·1 = 10. Positive, so w is counter-clockwise from v.

î × ĵ = ?

  1. k̂ = (0, 0, 1)
  2. −k̂ = (0, 0, −1)
  3. (1, 1, 0)
  4. The zero vector

(1,0,0) × (0,1,0) = (0·0 − 0·1, 0·0 − 1·0, 1·1 − 0·0) = (0, 0, 1) = k̂.

(2, 1, 0) × (1, 3, 0) = ?

  1. (0, 0, 5)
  2. (0, 0, 7)
  3. (0, 0, −5)
  4. (2, 3, 0)

(1·0 − 0·3, 0·1 − 2·0, 2·3 − 1·1) = (0, 0, 5). It points straight up, and 5 is the 2D area of those two vectors.

(1, 2, 3) × (4, 5, 6) = ?

  1. (−3, 6, −3)
  2. (3, −6, 3)
  3. (−3, −6, −3)
  4. (4, 10, 18)

(2·6 − 3·5, 3·4 − 1·6, 1·5 − 2·4) = (−3, 6, −3). Check: (1,2,3)·(−3,6,−3) = −3 + 12 − 9 = 0 ✓.

Find the area of the triangle with corners (0,0,0), (1,2,3) and (4,5,6).

  1. (3√6)/2 ≈ 3.674
  2. 3√6 ≈ 7.35
  3. 27/2
  4. √54 ≈ 7.35

Half the parallelogram: ½|(−3, 6, −3)| = ½√54 = (3√6)/2 ≈ 3.674.

Find a normal vector to the plane through (1,0,0), (0,1,0) and (0,0,1), and the plane's equation.

  1. Normal (1, 1, 1); plane x + y + z = 1
  2. Normal (1, 1, 1); plane x + y + z = 0
  3. Normal (1, −1, 1); plane x − y + z = 1
  4. Normal (1, 1, 1); plane x + y + z = 3

Two edges are (−1, 1, 0) and (−1, 0, 1). Their cross product is (1·1 − 0·0, 0·(−1) − (−1)·1, (−1)·0 − 1·(−1)) = (1, 1, 1). The plane is x + y + z = 1.

Why is v × v = 0, and what does it imply?

  1. The parallelogram is flat (area 0). Expanding (v+w)×(v+w) = 0 then forces w×v = −(v×w)
  2. Because v is parallel to itself. It implies v×w = w×v
  3. Because |v|² = 0. It implies nothing about w×v
  4. It isn't: v×v = |v|²

A parallelogram on one repeated vector is flat, with area 0. Since the cross product is linear in each slot, 0 = (v+w) × (v+w) = v×v + v×w + w×v + w×w = v×w + w×v.

Find the volume of the box (parallelepiped) with edges (1,0,0), (1,1,0) and (1,1,1).

  1. 1
  2. 0
  3. 3
  4. 2

Volume = |(1,0,0) · ((1,1,0) × (1,1,1))|. Here (1,1,0) × (1,1,1) = (1·1 − 0·1, 0·1 − 1·1, 1·1 − 1·1) = (1, −1, 0), and dotting with (1,0,0) gives 1. (It equals the determinant of the triangular matrix with those columns: 1·1·1.)

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 11

Cross products in the light of linear transformations

Watch: Cross products in the light of linear transformations | Chapter 11

The volume of the box with edges x, v, w is a linear function of x, so by duality it equals p·x for one special vector p. That p is v × w, and the geometry says why it's perpendicular and has length equal to the area.

Fix v and w and let x = (x, y, z) vary. Define

f(x) = det[ x  v  w ] = signed volume of the box with edges x, v, w.

Step 1, f is linear: the determinant is linear in each column. So f is a linear map from 3D to the number line, and has a 1×3 matrix.

Step 2, duality: every 1×3 matrix is "dot with some vector" (chapter 9). So there's a vector p with f(x) = p·x for every x.

Step 3, compute p: expand the determinant down its first column, x(v₂w₃ − v₃w₂) + y(v₃w₁ − v₁w₃) + z(v₁w₂ − v₂w₁), and read off the coefficients. They are exactly the cross product formula. That's why the "fake determinant with î, ĵ, k̂" trick works: it's this calculation with the unknowns replaced by basis vectors.

Step 4, geometry tells us what p is: the box's volume = (area of the base parallelogram on v, w) × (height of x above that base). The height is the component of x perpendicular to the base. So f(x) = "project x onto the perpendicular direction, then multiply by the area". And dotting with p means projecting onto p and multiplying by |p|. For those to agree for every x, p must be perpendicular to v and w, with length equal to the area. The sign makes (v, w, p) right-handed.

Move x with the sliders. The box (edges x, v, w) changes volume, and the readout shows that det[x v w] equals p·x where p = v × w (teal). Slide x parallel to the base and the volume doesn't change. Only the height counts.

Worked exampleRecovering p

Take v = (1, 0, 0) and w = (0, 2, 0). Then det[x v w] = x(0·0 − 0·2) + y(0·0 − 1·0) + z(1·2 − 0·0) = 2z. So p = (0, 0, 2) = v × w: it points straight up (perpendicular to the floor where v and w lie), with length 2, the area of the 1 × 2 rectangle.

Watch outCommon misconceptions

  • "The î ĵ k̂ determinant is a genuine determinant." You can't put vectors inside a matrix of numbers. It's a memory aid whose meaning is the duality argument above.
  • "Duality only works for dot products." It's a general principle: any linear map to numbers is "pair with some fixed vector".

In ML & deep learningWhere this shows up

The duality idea, "every linear map to a number is a dot product with some vector", is what the gradient is. The change in loss from a tiny step d is approximately ∇L·d: the gradient is the vector that represents the linear map "how much does the loss change?". That's why the gradient points uphill, and why gradient descent steps the other way.

Practice (pick one answer per question)

With v = î and w = ĵ, write f(x) = det[x î ĵ] as a formula in x, y, z. What is p?

  1. f(x) = z,  p = (0, 0, 1)
  2. f(x) = x,  p = (1, 0, 0)
  3. f(x) = x + y,  p = (1, 1, 0)
  4. f(x) = −z,  p = (0, 0, −1)

f = z (the height of x above the floor, since the base is the unit square). p = (0, 0, 1) = î × ĵ.

v = (1, 1, 0) and w = (0, 1, 1). Compute p = v × w, then check f(1, 0, 0) = p·(1, 0, 0) with a direct determinant.

  1. p = (1, −1, 1), and both ways give 1
  2. p = (1, 1, 1), and both ways give 1
  3. p = (−1, 1, −1), giving −1
  4. p = (1, −1, 1), but the determinant gives 0

p = (1·1 − 0·1, 0·0 − 1·1, 1·1 − 1·0) = (1, −1, 1), so p·(1, 0, 0) = 1. Directly, det with rows (1,0,0), (1,1,0), (0,1,1) = 1·(1·1 − 0·1) − 0 + 0 = 1 ✓. (A determinant doesn't change when you swap rows for columns.)

Why is f(v) = 0? What does that tell you about p·v?

  1. The box with edges v, v, w is flat, so p·v = 0: p is perpendicular to v
  2. p·v = |v|², so p is parallel to v
  3. f(v) = 1, so p·v = 1
  4. f(v) is undefined

The box with edges v, v, w is flat, so its volume is 0. So p·v = 0: p is perpendicular to v. The same argument gives p ⟂ w.

With v = (1,2,3) and w = (4,5,6), compute f(1, 1, 1) two ways and explain the answer.

  1. 0 both ways, because (1, 1, 1) lies in the plane of v and w
  2. 0, because v and w are parallel
  3. −3 both ways
  4. 54

p = (−3, 6, −3), so p·(1,1,1) = −3 + 6 − 3 = 0. Directly, rows (1,1,1), (1,2,3), (4,5,6): 1(12 − 15) − 1(6 − 12) + 1(5 − 8) = −3 + 6 − 3 = 0 ✓. It's zero because (1,1,1) = ⅓[(4,5,6) − (1,2,3)] lies in the plane of v and w, so the box is flat.

Why must |v × w| equal the area of the parallelogram?

  1. Take x a unit vector perpendicular to the base: the volume is area × 1, and it also equals p·x = |p|
  2. Because |v × w| = |v||w| always
  3. Because every 2×2 determinant is an area
  4. Because p is parallel to v

Choose x to be a unit vector perpendicular to the base. Then the box has height 1, so its volume is the base area. But the volume is also p·x = |p|, because x points along p. So |p| is the area.

Why is u·(v × w) = v·(w × u)?

  1. Both are the determinant of the same three vectors; moving u from first to last takes two swaps, so the sign doesn't change
  2. Because the cross product is commutative
  3. Because dot products are symmetric, so order never matters
  4. It's false: one is always the negative of the other

The left side is det[u v w] by the duality definition. The right side is det[v w u]. Moving u from the first column to the last takes two swaps (past v, then past w), and each swap flips the sign, so the determinant is unchanged. Geometrically, it's the same box.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 12

Cramer's rule, explained geometrically

Watch: Cramer's rule, explained geometrically | Chapter 12

The unknown y equals the signed area of the parallelogram on î and x. The transformation scales that area by det A and turns it into the parallelogram on (column 1, b). So y = det[col₁ | b] / det A.

We want x = (x, y) with Ax = b, and we know where x ends up (at b), but not where it started. The trick is to find a quantity that (1) equals a coordinate of x and (2) changes in a predictable way under A.

A false start: x = x·î. Dot products usually change under a transformation, so that doesn't work in general. It does work for rotations, which preserve dot products: there, x = (column 1)·b.

The working idea: areas. The parallelogram on î and x has base 1 and height y, so its signed area is y. After A:

  • every area gets multiplied by det A, so the new area is det(A)·y;
  • the new parallelogram is spanned by Aî (column 1 of A) and Ax = b, which we know, so we can compute its area directly as det[col₁ | b].
det(A)·y = det[col₁ | b]  ⇒  y = det[col₁ | b]det A,    and likewise   x = det[b | col₂]det A.

(For x, use the parallelogram on x and ĵ: its area is x.) In 3D, the same idea works with volumes. Cramer's rule is beautiful but slow for big systems; elimination is how real solvers work.

Drag the gold vector. At slider 0 you see the input x; at slider 1 you see its image b = Ax. The shaded parallelogram is spanned by î and x before (area = y) and by col₁ and b after (area = det A · y). Switch to the x-version to use ĵ instead.

Worked exampleA 2×2 system

Solve 3x + 2y = 1, x + 4y = −3. det A = det 3 2; 1 4 = 12 − 2 = 10.

x = det1 2; −3 4 / 10 = (4 + 6)/10 = 1,    y = det3 1; 1 −3 / 10 = (−9 − 1)/10 = −1.

Check: 3 − 2 = 1 ✓ and 1 − 4 = −3 ✓.

Watch outCommon misconceptions

  • "Cramer is the best way to solve systems." For anything bigger than 3×3 it's far slower than elimination.
  • "It works when det A = 0." It divides by det A, so no. That's the squashing case from chapter 7.

In ML & deep learningWhere this shows up

Cramer's rule is a thinking tool, not something ML libraries use: it needs n+1 determinants, while LU, Cholesky and QR factorisations are far faster and more stable. Its lesson transfers, though: the solution divides by det A, so when det A is tiny (an ill-conditioned system) small noise in the data causes huge swings in the answer. That's a big reason regularisation such as ridge exists.

Practice (pick one answer per question)

Solve 2x + y = 5, x + 3y = 10 with Cramer's rule.

  1. x = 1, y = 3
  2. x = 3, y = 1
  3. x = 2, y = 1
  4. x = 1, y = 2

det A = 6 − 1 = 5. x = det5 1; 10 3/5 = (15 − 10)/5 = 1. y = det2 5; 1 10/5 = (20 − 5)/5 = 3. Check: 2 + 3 = 5 ✓ and 1 + 9 = 10 ✓.

Why does the parallelogram on î and (x, y) have signed area y?

  1. Its base î has length 1, and its height above the x-axis is y
  2. Because its area is x·y
  3. Because det[î (x, y)] = x
  4. It doesn't: its area is x

Its base is î, of length 1 along the x-axis, and its height is the distance of (x, y) above that axis, which is y (negative if below, which also flips the orientation).

Solve 3x − 2y = 4, 5x + 4y = 14.

  1. x = 2, y = 1
  2. x = 1, y = 2
  3. x = 44, y = 22
  4. x = 2, y = −1

det A = 12 + 10 = 22. x = det4 −2; 14 4/22 = (16 + 28)/22 = 2. y = det3 4; 5 14/22 = (42 − 20)/22 = 1. Check: 6 − 2 = 4 ✓ and 10 + 4 = 14 ✓.

For the rotation A = 0 −1; 1 0 and b = (3, 2), find x using dot products only.

  1. x = 2, y = −3
  2. x = 3, y = 2
  3. x = −2, y = 3
  4. x = −3, y = 2

Rotations keep dot products, so x = (col₁)·b = (0, 1)·(3, 2) = 2 and y = (col₂)·b = (−1, 0)·(3, 2) = −3. Check: A(2, −3) = (0·2 + (−1)(−3), 1·2 + 0) = (3, 2) ✓.

Find z only for 2x + y − z = 3, x − y + z = 0, x + 2y + z = 6.

  1. z = 1
  2. z = −1
  3. z = 2
  4. z = 9

det A (rows (2,1,−1), (1,−1,1), (1,2,1)) = 2(−1 − 2) − 1(1 − 1) + (−1)(2 + 1) = −6 − 0 − 3 = −9. Replace the third column with b = (3, 0, 6): rows (2,1,3), (1,−1,0), (1,2,6), so det = 2(−6 − 0) − 1(6 − 0) + 3(2 + 1) = −12 − 6 + 9 = −9. So z = −9/−9 = 1. (The full solution is (1, 2, 1). Check: 2 + 2 − 1 = 3 ✓, 1 − 2 + 1 = 0 ✓, 1 + 4 + 1 = 6 ✓.)

If you double every entry of b, what happens to the solution? Explain it with Cramer's formula.

  1. The solution doubles
  2. The solution stays the same
  3. The solution halves
  4. Every entry of the solution gets squared

Each numerator det[… b …] is linear in the b column, so it doubles, while det A stays the same. The solution doubles, as linearity predicts: A(2x) = 2b.

In 3D, which volume equals z, and what does it become under A?

  1. The box on î, ĵ, x; under A it becomes det[col₁ col₂ b] = det(A)·z
  2. The box on x, x, x; it stays z
  3. The box on î, ĵ, k̂; it becomes det A
  4. The box on b, ĵ, k̂; it becomes z/det A

The box with edges î, ĵ, x has base the unit square and height z, so its signed volume is z. A multiplies volumes by det A and sends the edges to col₁, col₂ and b. So det(A)·z = det[col₁ col₂ b], which gives z = det[col₁ col₂ b]/det A.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 13

Change of basis

Watch: Change of basis | Chapter 13

The same arrow has different coordinates in different bases. The matrix whose columns are the new basis vectors (written in our coordinates) translates their coordinates into ours, its inverse goes the other way, and A⁻¹MA is "M, said in their language".

Imagine a friend, Jennifer, who uses the basis b₁ = (2, 1), b₂ = (−1, 1). Both are written in our coordinates. To her, those are just "(1, 0)" and "(0, 1)". When she says "(−1, 2)" she means −1·b₁ + 2·b₂.

  • Her coordinates → ours: multiply by A = [b₁ b₂] = 2 −1; 1 1. Her (−1, 2) is our −1·(2, 1) + 2·(−1, 1) = (−4, 1).
  • Ours → hers: multiply by A⁻¹ = 131 1; −1 2.

It feels backwards: geometrically A moves our grid onto hers, but numerically it converts her numbers into ours. Both are true at once.

Translating a transformation. Say we want a 90° rotation M, expressed in Jennifer's language. Take her vector, translate it into ours (A), rotate (M), and translate back (A⁻¹):

MJennifer = A⁻¹ M A   (read right to left).

Whenever you see A⁻¹MA, read it as "the same transformation M, seen from another point of view". This is the setup for chapter 14: choose a clever basis and M can become very simple.

The purple grid is Jennifer's (drag her basis vectors b₁ and b₂). Drag the gold vector: the readout gives its coordinates in our grid and in hers, and the dashed path shows it built as c₁b₁ + c₂b₂.

Worked exampleA rotation in Jennifer's language

R = 0 −1; 1 0. First RA = −1 −1; 2 −1. Then A⁻¹(RA) = 131 1; −1 2−1 −1; 2 −1 = 131 −2; 5 −1.

Sanity checks: a rotation keeps areas, and this matrix's det is (1·(−1) − (−2)·5)/9 = 9/9 = 1 ✓. A 90° rotation has trace 0, and so does this one ✓. Different numbers, same motion.

Watch outCommon misconceptions

  • "A converts our coordinates into hers." The other way round. A takes her coordinates to ours.
  • "A⁻¹MA = M, the A's cancel." Matrices don't commute, so they don't cancel. A⁻¹MA = M only if M commutes with A.
  • "Changing basis moves the vectors." The arrows stay put. Only their descriptions change.

In ML & deep learningWhere this shows up

Changing basis is one of ML's most common moves. PCA rewrites data in the basis of its main directions of variation. Whitening picks a basis where features are uncorrelated. Fourier and wavelet bases underlie audio and image processing. In transformers, the query, key and value matrices re-express each token vector in three learned coordinate systems, one for each role it plays.

Practice (pick one answer per question)

Use Jennifer's basis b₁ = (2, 1), b₂ = (−1, 1) unless told otherwise.

Jennifer says (3, 2). What is that in our coordinates?

  1. (4, 5)
  2. (3, 2)
  3. (8, 1)
  4. (5, 4)

3(2, 1) + 2(−1, 1) = (6 − 2, 3 + 2) = (4, 5).

What are Jennifer's coordinates for her own b₁?

  1. (1, 0)
  2. (2, 1)
  3. (0, 1)
  4. (1, 1)

(1, 0). In her language, her first basis vector is always (1, 0).

Our vector (3, 0): what does Jennifer call it?

  1. (1, −1)
  2. (3, 0)
  3. (6, 3)
  4. (1, 1)

A⁻¹(3, 0) = ⅓(3 + 0, −3 + 0) = (1, −1). Check: (2, 1) − (−1, 1) = (3, 0) ✓.

Our vector (5, 4) in Jennifer's coordinates?

  1. (3, 1)
  2. (1, 3)
  3. (5, 4)
  4. (2, 3)

A⁻¹(5, 4) = ⅓(5 + 4, −5 + 8) = (3, 1). Check: 3(2, 1) + (−1, 1) = (5, 4) ✓.

Which product expresses M in Jennifer's coordinates, and why?

  1. A⁻¹MA: translate her vector into ours (A), apply M, then translate back (A⁻¹)
  2. AMA⁻¹: translate ours into hers first
  3. MA⁻¹A, which is just M
  4. A⁻¹AM, which is just M

The input is in her language. The first thing to apply (rightmost) must translate her language into ours, which is A. Then apply M in our language, and translate the result back with A⁻¹. AMA⁻¹ is the opposite: it would express in our language a transformation that was written in hers.

Let M = 3 1; 0 2. Use the basis of eigenvectors (1, 0) and (1, −1) to compute M⁵.

  1. 243 211; 0 32
  2. 243 32; 0 32
  3. 243 1; 0 32
  4. 15 5; 0 10

P = 1 1; 0 −1 (eigenvectors as columns). M(1, −1) = (2, −2) = 2(1, −1), and M(1, 0) = (3, 0). So P⁻¹MP = D = 3 0; 0 2. Here P⁻¹ = P, since P² = I. Then M⁵ = PD⁵P⁻¹ = 1 1; 0 −1243 0; 0 321 1; 0 −1 = 243 32; 0 −321 1; 0 −1 = 243 211; 0 32.

Check: the top-right entry should be 3⁴ + 3³·2 + 3²·2² + 3·2³ + 2⁴ = 81 + 54 + 36 + 24 + 16 = 211 ✓.

Which quantities do M and A⁻¹MA always have in common?

  1. Determinant, trace and eigenvalues
  2. Only the determinant
  3. Every entry
  4. Nothing, in general

Determinant: det(A⁻¹MA) = det(A⁻¹)det(M)det(A) = det M, because det(A⁻¹)det(A) = 1. (It also has to be true: area scaling doesn't depend on which grid you describe it with.) Trace: tr(XY) = tr(YX) for any matrices, so tr(A⁻¹(MA)) = tr((MA)A⁻¹) = tr(M). Since the eigenvalues are determined by trace and det in 2×2, similar matrices also have the same eigenvalues.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 14

Eigenvectors and eigenvalues

Watch: Eigenvectors and eigenvalues | Chapter 14

An eigenvector is a vector that stays on its own line during the transformation; it only gets stretched, squashed or flipped. The eigenvalue λ is the stretch factor. You find them by solving det(A − λI) = 0.

Most vectors get knocked off their own span (the line through them) by a transformation. A few special ones don't. They land on a multiple of themselves:

Av = λv.

Those are eigenvectors, and λ is the eigenvalue. For a 3D rotation, the eigenvector is the axis, with λ = 1. Eigenvectors cut a transformation down to its essence: "stretch by 3 along this line, by 2 along that one".

How to find them. Rewrite Av = λv as (A − λI)v = 0. We want a nonzero v, so A − λI must squash some line to zero, and that happens exactly when det(A − λI) = 0 (chapter 7). Solve that equation for λ, then find v as the null space of A − λI.

  • Rotation by 90°: det(A − λI) = λ² + 1 has no real roots. Every vector gets turned, so there are no real eigenvectors.
  • Shear 1 1; 0 1: (1 − λ)² = 0, so λ = 1, and the only eigenvectors lie on the x-axis. That's not enough to form a basis.
  • Scaling by 2: λ = 2, and every vector is an eigenvector.

Eigenbasis. If the eigenvectors span the space, use them as the basis (chapter 13). In that basis the matrix is diagonal, with the eigenvalues on the diagonal. Diagonal matrices are trivial to raise to powers, which is why this matters for anything that repeats a step many times: population models, Markov chains, Fibonacci, Google's original PageRank, and vibrating systems.

Ring of vectors on the unit circle, transformed. Those that stay on their own line (eigen-directions) glow teal; the dashed lines show the eigenvectors with their λ. Drag the gold vector: it turns teal when Av lines up with v.

Worked exampleFull calculation

A = 3 1; 0 2. det(A − λI) = (3 − λ)(2 − λ) − 1·0 = 0 gives λ = 3 or λ = 2.

  • λ = 3: A − 3I = 0 1; 0 −1, so y = 0 and v = (1, 0).
  • λ = 2: A − 2I = 1 1; 0 0, so x + y = 0 and v = (1, −1). Check: A(1, −1) = (3 − 1, −2) = (2, −2) = 2(1, −1) ✓.

Watch outCommon misconceptions

  • "Every matrix has real eigenvectors." Rotations don't (in 2D).
  • "An eigenvector is one specific vector." Any nonzero multiple works too. It's really an eigen-line (or eigenspace).
  • "λ = 0 is impossible." λ = 0 means the eigenvector gets squashed to 0. It happens exactly when det A = 0.
  • "The zero vector is an eigenvector." It's excluded by definition, because A0 = λ0 for every λ, which tells you nothing.

In ML & deep learningWhere this shows up

Eigenvectors are everywhere in ML. PCA keeps the top eigenvectors of the covariance matrix. Google's original PageRank was the dominant eigenvector of the web's link matrix. Spectral normalization stabilises GAN training using the largest singular value, computed by power iteration. In RNNs, recurrent weights with eigenvalues above 1 make gradients explode and below 1 make them vanish. The eigenvalues of the loss Hessian describe how curved the loss landscape is, which affects which learning rates are safe.

Practice (pick one answer per question)

Eigenvalues and eigenvectors of 2 0; 0 5?

  1. λ = 2 along î, and λ = 5 along ĵ
  2. λ = 5 along î, and λ = 2 along ĵ
  3. λ = 7 along (1, 1)
  4. It has no eigenvectors

λ = 2 with î, and λ = 5 with ĵ. A diagonal matrix just stretches each axis.

Is (1, 1) an eigenvector of 3 1; 1 3? Is (1, −1)?

  1. Both: (1, 1) with λ = 4, and (1, −1) with λ = 2
  2. Only (1, 1), with λ = 4
  3. Only (1, −1), with λ = 2
  4. Neither

(1, 1) → (4, 4) = 4(1, 1): yes, λ = 4. (1, −1) → (2, −2) = 2(1, −1): yes, λ = 2.

Why does the 90° rotation 0 −1; 1 0 have no real eigenvalues?

  1. det(A − λI) = λ² + 1, which has no real roots
  2. Every vector is an eigenvector, with λ = 1
  3. Its eigenvalues are 0 and 1
  4. It has eigenvalue −1 along the x-axis

det −λ −1; 1 −λ = λ² + 1 > 0 for every real λ, so there are no solutions. Every nonzero vector gets turned by 90°, so none stays on its own line.

Find all eigenvectors of the shear 1 1; 0 1.

  1. Only the multiples of (1, 0), with λ = 1
  2. (1, 0) and (0, 1), both with λ = 1
  3. Every vector
  4. (1, 1), with λ = 2

(1 − λ)² = 0, so λ = 1. A − I = 0 1; 0 0 forces y = 0, so the eigenvectors are the multiples of (1, 0). There's only one line, so there's no eigenbasis.

Find the eigenvalues and eigenvectors of 4 1; 2 3.

  1. λ = 5 with (1, 1); λ = 2 with (1, −2)
  2. λ = 5 with (1, −2); λ = 2 with (1, 1)
  3. λ = 4 and λ = 3
  4. λ = 7 with (1, 1); λ = 10 with (1, −2)

det(A − λI) = (4 − λ)(3 − λ) − 2 = λ² − 7λ + 10 = (λ − 5)(λ − 2). For λ = 5: A − 5I = −1 1; 2 −2, giving (1, 1). For λ = 2: 2 1; 2 1, giving (1, −2). Check: A(1, −2) = (4 − 2, 2 − 6) = (2, −4) = 2(1, −2) ✓.

If Av = λv, then v is also an eigenvector of A² and (when A is invertible) of A⁻¹. With which eigenvalues?

  1. λ² for A², and 1/λ for A⁻¹
  2. 2λ for A², and −λ for A⁻¹
  3. λ for both
  4. λ² for A², but v isn't an eigenvector of A⁻¹

A²v = A(λv) = λAv = λ²v. For the inverse, apply A⁻¹ to Av = λv to get v = λA⁻¹v. λ ≠ 0 because A is invertible, so A⁻¹v = (1/λ)v.

Fibonacci: (Fn+1, Fn) = 1 1; 1 0(Fn, Fn−1). Find the eigenvalues and explain why Fn+1/Fn → the golden ratio.

  1. (1 ± √5)/2. The −0.618 part shrinks away, so the ratio tends to φ ≈ 1.618
  2. 1 and 0; the ratio tends to 1
  3. ±1; the ratio keeps oscillating
  4. 2 and −1; the ratio tends to 2

λ² − λ − 1 = 0 gives λ = (1 ± √5)/2 ≈ 1.618 and −0.618. Write the starting vector in the eigenbasis. Each step multiplies the components by 1.618 and −0.618 respectively. The second shrinks away, so the vector lines up with the λ = 1.618 eigenvector, (φ, 1). The ratio of its entries is φ = (1 + √5)/2.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 15

A quick trick for computing eigenvalues

Watch: A quick trick for computing eigenvalues | Chapter 15

For a 2×2 matrix, the eigenvalues are m ± √(m² − p), where m is the mean of the diagonal entries and p is the determinant.

Three facts give a shortcut that skips the characteristic polynomial:

  1. The trace is the sum of the eigenvalues: a + d = λ₁ + λ₂. So their mean is m = (a + d)/2, half the trace.
  2. The determinant is their product: ad − bc = λ₁λ₂ = p. (The area factor is the product of the stretches along the eigen-directions.)
  3. Two numbers with mean m and product p are m + d and m − d for some d, and their product is (m + d)(m − d) = m² − d² = p. So d = √(m² − p).
λ = m ± √(m² − p),    m = a + d2,   p = ad − bc.

If m² − p is negative, the eigenvalues are complex. That signals a rotation-like part with no real eigen-directions. (Careful: the letter d in the formula is the distance, not the matrix entry d.)

Type a matrix. The number line shows the mean m, the two eigenvalues m ± d, and the distance d = √(m² − p). Press Random quiz to get a fresh matrix and test yourself before revealing.

Worked exampleIn your head

8 4; 2 6: m = 7, p = 48 − 8 = 40, so d = √(49 − 40) = 3, and λ = 10 and 4. Check: they sum to 14 (the trace) and multiply to 40 (the det) ✓.

Watch outCommon misconceptions

  • "Half the trace is an eigenvalue." It's the average of the two. It equals each of them only when they're equal.
  • "There's an equally simple formula for 3×3." Trace = sum and det = product still hold, but three unknowns need more than these two facts.

In ML & deep learningWhere this shows up

Quick 2×2 eigenvalues help you read small systems at a glance. At a point where the gradient is zero, the Hessian's eigenvalues say whether you're at a minimum (both positive), a maximum (both negative) or a saddle point (mixed signs). Saddle points, not bad local minima, are what slow down training in high dimensions. Complex eigenvalues in a 2D update rule mean the updates circle rather than converge, which happens in GAN training dynamics.

Practice (pick one answer per question)

Eigenvalues of 6 2; 2 3?

  1. 7 and 2
  2. 4.5 and 4.5
  3. 9 and 0
  4. 6 and 3

m = 4.5, p = 18 − 4 = 14, d = √(20.25 − 14) = √6.25 = 2.5, so 7 and 2. Check: (2, 1) → (14, 7) = 7(2, 1) ✓.

Eigenvalues of 2 7; 1 8?

  1. 9 and 1
  2. 5 and 5
  3. 8 and 2
  4. 10 and 0

m = 5, p = 16 − 7 = 9, d = √(25 − 9) = 4, so 9 and 1.

Eigenvalues of 3 1; 4 1?

  1. 2 ± √5
  2. 2 ± √3
  3. 4 and −1
  4. 3 and 1

m = 2, p = 3 − 4 = −1, d = √(4 + 1) = √5, so 2 ± √5 (≈ 4.236 and −0.236).

Eigenvalues of 5 −2; 2 1?

  1. 3, repeated
  2. 5 and 1
  3. 3 ± 2
  4. 3 ± 3i

m = 3, p = 5 + 4 = 9, d = √(9 − 9) = 0, so 3, repeated. (Its only eigenvectors are the multiples of (1, 1), so it's shear-like.)

Eigenvalues of 0 −1; 1 0? What does that tell you?

  1. ±i, which signals a rotation
  2. ±1, which signals a reflection
  3. 0, repeated
  4. 1 and −1

m = 0, p = 1, d = √(−1) = i, so ±i. Complex eigenvalues signal rotation: this matrix is the 90° turn.

Build a 2×2 matrix with eigenvalues 7 and −1 that isn't diagonal.

  1. 3 4; 4 3
  2. 7 0; 0 −1 (it's diagonal)
  3. 3 1; 1 3
  4. 6 7; 0 0

You need trace 6 and det −7. For example 3 4; 4 3: trace 6, det 9 − 16 = −7 ✓. (Its eigenvectors are (1, 1) and (1, −1).)

Physics' Pauli matrices are 0 1; 1 0, 0 −i; i 0 and 1 0; 0 −1. Find their eigenvalues in one line each.

  1. ±1 for all three
  2. ±1, ±i and ±1
  3. 0 for all three
  4. ±i for all three

All have m = 0. Their determinants: 0 − 1 = −1; then 0 − (−i)(i) = 0 − 1 = −1 (because (−i)(i) = −i² = 1); then −1. So each has d = √(0 + 1) = 1, and the eigenvalues are ±1 for all three.

Code it (optional: real Python runs in your browser and is graded by test cases)

Chapter 16

Abstract vector spaces

Watch: Abstract vector spaces | Chapter 16

A vector is anything you can add and scale following a short list of rules. Functions qualify, so ideas like basis, linear transformation, matrix and eigenvector apply to them too. The derivative, for instance, is a linear transformation.

So what is a vector, really: an arrow, or a list of numbers? The modern answer: it doesn't matter. Anything that can be added and scaled in a sensible way counts. "Sensible" means these rules (the axioms) hold:

u + (v + w) = (u + v) + wv + w = w + v
there's a 0 with 0 + v = vevery v has a −v with v + (−v) = 0
a(bv) = (ab)v1·v = v
a(v + w) = av + aw(a + b)v = av + bv

Functions are vectors. You can add them, (f + g)(x) = f(x) + g(x), and scale them, (2f)(x) = 2f(x), and every rule holds. Linear transformations of functions follow the same two rules as before: L(f + g) = L(f) + L(g) and L(cf) = cL(f). The derivative passes, because (f + g)' = f' + g' and (cf)' = cf'.

Matrices for functions. Polynomials up to degree 3 have the basis 1, x, x², x³. So a + bx + cx² + dx³ "is" the column (a, b, c, d). The derivative sends 1 → 0, x → 1, x² → 2x and x³ → 3x², and those images in coordinates are the columns of its matrix:

D = 0 1 0 0; 0 0 2 0; 0 0 0 3; 0 0 0 0,    Da; b; c; d = b; 2c; 3d; 0.

Everything from the earlier chapters has a matching idea for functions: dot product ↔ integral of f·g, eigenvectors ↔ eigenfunctions (eλx for the derivative), null space ↔ the constants (whose derivative is 0). That's why linear algebra shows up all over differential equations, quantum mechanics, signal processing and machine learning.

Set the coefficients of f(x) = a + bx + cx² + dx³ with the sliders. The gold curve is f and the teal curve is f′. The readout multiplies the derivative matrix by the coefficient vector, and its answer matches the teal curve's formula.

Worked exampleDifferentiate with a matrix

f = 5 + 3x + 2x² − x³ is (5, 3, 2, −1). D times it gives (3, 2·2, 3·(−1), 0) = (3, 4, −3, 0), which is 3 + 4x − 3x². Ordinary calculus gives the same: f′ = 3 + 4x − 3x² ✓.

Watch outCommon misconceptions

  • "Vectors are lists of numbers, period." Lists are one example. Coordinates only appear once you pick a basis.
  • "Squaring a function is a linear transformation." (f + g)² ≠ f² + g², so no.
  • "Abstract means useless." Fourier analysis, quantum states and the weights of a neural network are all vectors in this sense.

In ML & deep learningWhere this shows up

Treating functions as vectors is the foundation of kernel methods (SVMs live in a space of functions), Fourier features, and the view of a neural network as a point in a giant function space. Automatic differentiation in PyTorch and JAX relies on the derivative being a linear map: backprop computes vector–Jacobian products, which is this chapter's derivative-as-a-matrix idea at scale.

Practice (pick one answer per question)

Is the set of polynomials of degree ≤ 2 a vector space? Give a basis and its dimension.

  1. Yes; basis 1, x, x²; dimension 3
  2. Yes; dimension 2
  3. No: x² · x² has degree 4
  4. Yes; infinite dimension

Yes: sums and scalar multiples stay degree ≤ 2, and the rules hold. A basis is 1, x, x², so the dimension is 3.

Coordinates of 3 − 2x + 5x² in the basis 1, x, x²?

  1. (3, −2, 5)
  2. (5, −2, 3)
  3. (3, 2, 5)
  4. (−2, 5, 3)

(3, −2, 5).

Use the derivative matrix D above on 1 + 2x + 3x² + 4x³.

  1. 2 + 6x + 12x²
  2. 2 + 3x + 4x²
  3. 1 + 4x + 9x² + 16x³
  4. 6x + 12x²

D(1, 2, 3, 4) = (2, 6, 12, 0), which is 2 + 6x + 12x². Check by calculus: 2 + 6x + 12x² ✓.

Which are linear? L₁(f) = f + 1, L₂(f) = x·f(x), L₃(f) = f(2), L₄(f) = f(x)².

  1. L₂ and L₃
  2. L₁ and L₂
  3. Only L₂
  4. All four

L₁: no (L₁(0) = 1 ≠ 0). L₂: yes. L₃: yes (evaluation at a point is linear, a "1×∞ matrix"). L₄: no.

Do the solutions of f″ + f = 0 form a vector space? If so, name a basis.

  1. Yes; basis sin x and cos x
  2. Yes; basis eˣ and e⁻ˣ
  3. No: it isn't closed under addition
  4. Yes; basis 1 and x

If f and g are solutions, then (af + bg)″ + (af + bg) = a(f″ + f) + b(g″ + g) = 0, so the set is closed under adding and scaling, which is all you need for a subset of the function space. A basis is sin x and cos x, so the dimension is 2.

What is the null space of the derivative (on polynomials)? How does that explain the "+ C" in antiderivatives?

  1. The constants, which is why antiderivatives have a "+ C"
  2. Only the zero polynomial
  3. All polynomials of degree 1
  4. The polynomials with no constant term

The null space is the constants, since their derivative is 0. As in chapter 7, the solutions of D(F) = f are one particular solution plus anything in the null space: F + C.

Find the matrix of d/dx on the space spanned by sin x and cos x (basis order: sin, cos). What transformation is it, and what are its eigenvalues?

  1. 0 −1; 1 0: a 90° rotation, with eigenvalues ±i
  2. 0 1; −1 0: a reflection, with eigenvalues ±1
  3. 1 0; 0 −1, with eigenvalues ±1
  4. 0 1; 1 0, with eigenvalues ±i

d/dx(sin) = cos = (0, 1) and d/dx(cos) = −sin = (−1, 0), so the matrix is 0 −1; 1 0: a 90° rotation! Its eigenvalues are ±i (chapter 15), matching the complex eigenfunctions eix and e−ix (d/dx eix = i·eix).

Code it (optional: real Python runs in your browser and is graded by test cases)

Final tests

Ten full-length tests, each covering all 16 chapters and testing ideas both one at a time and in combination:

  • Part A: 20 single-concept multiple-choice questions (calculations, conceptual and ML questions).
  • Part B: 5 multi-concept multiple-choice questions that need two or three chapters at once, such as eigenvalues with determinants, projections with linear systems, or transformations with areas.
  • Part C: 3 Python coding problems (1 single-concept, 2 multi-concept, many ML-flavoured), graded by test cases.

All questions are new (none repeat the chapter quizzes) and each multiple-choice question has exactly one correct answer. There's an optional 75-minute timer. When you submit you get your score out of 28, single- vs multi-concept and chapter-by-chapter breakdowns, worked answers, and the reference code. Your best score for each test is saved in this browser.

One-page cheat sheet

Everything from the 16 chapters, compressed. On paper, it prints on its own (figures hidden).

Vectors & combinations

(a, b) + (c, d) = (a + c, b + d);   k(a, b) = (ka, kb)

Length |v| = √(v₁² + v₂² + …)

Span = all av + bw + …;  basis = independent + spanning

Matrix × vector

a b; c dx; y = xa; c + yb; d

Columns = where î, ĵ (, k̂) land.

Matrix × matrix

BA = "A first, then B". Column j of BA = B·(column j of A).

(m×n)(n×p) = m×p.  AB ≠ BA in general; (AB)C = A(BC).

Determinant

det a b; c d = ad − bc = signed area factor

3×3: a(ei − fh) − b(di − fg) + c(dh − eg) for a b c; d e f; g h i

det(AB) = det A · det B;  det(A⁻¹) = 1/det A;  det(kA) = kⁿ det A

Inverse & systems

a b; c d−1 = 1ad − bcd −b; −c a

Ax = v: unique solution iff det A ≠ 0.

rank + nullity = number of columns

Dot product

v·w = Σ vᵢwᵢ = |v||w|cos θ

= 0 ⇔ perpendicular.  Projection of w on v: (v·w/v·v)v

Duality: 1×n matrix [u₁ … uₙ] ⇔ dot with u.

Cross product (3D)

v×w = (v₂w₃ − v₃w₂, v₃w₁ − v₁w₃, v₁w₂ − v₂w₁)

|v×w| = area = |v||w| sin θ; ⟂ both; right-hand rule

x·(v×w) = det[x v w] = box volume

Cramer's rule

xᵢ = det(Aᵢ) / det A, where Aᵢ = A with column i replaced by b.

Change of basis

A = [new basis vectors as columns, in our coords]

their coords → ours: A;  ours → theirs: A⁻¹

M in their language: A⁻¹MA

Eigen-stuff

Av = λv, v ≠ 0  ⇔  det(A − λI) = 0

2×2 shortcut: λ = m ± √(m² − p), m = trace/2, p = det

Eigenbasis P: P⁻¹AP = diagonal; Aⁿ = PDⁿP⁻¹

Special matrices (2D)

Rotate θ: cos θ, −sin θ; sin θ, cos θ   Shear: 1 k; 0 1

Reflect across x-axis: 1 0; 0 −1   Project onto x-axis: 1 0; 0 0

Abstract spaces

Vector space = set with + and scaling obeying 8 axioms.

Linear: L(f + g) = L(f) + L(g), L(cf) = cL(f). Derivative is linear.

Glossary

Basis
A set of linearly independent vectors that spans the space. Every vector has exactly one recipe in terms of them. (Ch 2)
Basis vectors î, ĵ, k̂
The standard basis: unit vectors along the x, y and z axes. (Ch 2, 5)
Change of basis
Re-expressing vectors or transformations in another coordinate system, using A and A⁻¹. (Ch 13)
Column space
All possible outputs Ax; the span of the columns. (Ch 7)
Composition
Applying one transformation after another; its matrix is the product. (Ch 4)
Cramer's rule
Solving Ax = b with ratios of determinants. (Ch 12)
Cross product
In 3D, the vector perpendicular to v and w whose length is the area of their parallelogram. (Ch 10, 11)
Determinant
The factor by which a transformation scales area/volume; negative if orientation flips. (Ch 6)
Diagonal matrix
Nonzero entries only on the main diagonal; it just stretches each axis. (Ch 14)
Dot product
Sum of products of matching coordinates; projection length × length. (Ch 9)
Duality
The correspondence between vectors and linear maps to numbers (1×n matrices). (Ch 9, 11)
Eigenvalue / eigenvector
Av = λv: v stays on its own line and is scaled by λ. (Ch 14)
Identity matrix I
The "do nothing" transformation: ones on the diagonal, zeros elsewhere.
Inverse A⁻¹
The transformation that undoes A: A⁻¹A = I. Exists iff det A ≠ 0. (Ch 7)
Kernel
Another name for null space.
Linear combination
A sum of scaled vectors, av + bw + …. (Ch 2)
Linear transformation
A map that preserves addition and scaling: grid lines stay parallel and evenly spaced, origin fixed. (Ch 3)
Linearly dependent / independent
Dependent: some vector is a combination of the others (redundant). Independent: none is. (Ch 2)
Matrix
A grid of numbers recording a linear transformation: the columns are the images of the basis vectors. (Ch 3)
Null space
All inputs that A sends to the zero vector. (Ch 7)
Orientation
The handedness of a basis (is ĵ counter-clockwise from î?); flipped when det < 0. (Ch 6)
Projection
The shadow of one vector on the line (or plane) of another. (Ch 9)
Rank
The dimension of the column space: how many dimensions survive the transformation. (Ch 7)
Scalar
An ordinary number, used to scale vectors. (Ch 1)
Shear
A transformation that slides layers parallel to an axis, like pushing a deck of cards. det = 1.
Span
Everything reachable by linear combinations of given vectors. (Ch 2)
Trace
Sum of the diagonal entries; equals the sum of the eigenvalues. (Ch 15)
Vector space
Any set whose elements can be added and scaled following the eight axioms. (Ch 16)

Where to go next: the best linear algebra resources

You asked for "the most valuable resource on linear algebra on this planet". If I had to pick one, it's Gilbert Strang's MIT course 18.06: free full lectures by the most influential linear algebra teacher of the last fifty years, with problem sets and exams. 3Blue1Brown gives you the pictures; Strang gives you the fluency and the applications. After that, choose by what you need:

★ MIT 18.06SC Linear Algebra (Gilbert Strang): freeLecture videos, recitations, problem sets with solutions, and exams. The self-paced version of the most famous linear algebra course in the world. Start here after this page. 3Blue1Brown: Essence of Linear Algebra (the playlist)The 16 videos this page follows. Rewatch them after the practice questions; they land differently the second time. 3blue1brown.com: Linear algebra lessonsText versions of each chapter with the animations, written by the same author. Interactive Linear Algebra (Margalit & Rabinoff, Georgia Tech): free textbookA complete, rigorous textbook with interactive 3D figures. The best free bridge from intuition to a full university course. Strang: Introduction to Linear Algebra (book site)The textbook that goes with 18.06, plus the author's notes, problem solutions and video links. Axler: Linear Algebra Done Right (free PDF from the author)The proof-based second course. Read it once the ideas here feel natural and you want to know why everything is true. Chapter 16 is where it starts. Austin: Understanding Linear Algebra: free textbookGentle, activity-based, with lots of computation practice and applications. Khan Academy: Linear algebraShort videos and exercises on the mechanics (row reduction, determinants, projections). Good for drilling. Mathematics for Machine Learning (Deisenroth, Faisal, Ong): free PDFIf you're here for AI/ML: linear algebra, matrix decompositions and how they power PCA, regression and more. Setosa: Eigenvectors and eigenvalues, explained visuallyA short interactive essay with real-world examples, nice after chapter 14.

A suggested path

  1. This page: one chapter a day, with the video, figure and questions (about 2–3 weeks).
  2. MIT 18.06SC, lectures 1–10 alongside the problem sets.
  3. Interactive Linear Algebra (or Strang's book) for the full course.
  4. Axler when you want proofs; Mathematics for Machine Learning if you want ML.