EVERYTHING AIAI engineering, made visual
0/23 complete
LESSON 03 · MATHEMATICS × AI · BUILD

Watch a grid
become the matrix.

A matrix is a machine that reshapes space. Do A, then B, and the whole journey is one combined matrix — written B @ A. The same two machines in the other order land somewhere else.

75 MIN · 9 CHAPTERSPREREQ · LESSONS 01–02
FIG. 03 / SAME MACHINES, DIFFERENT ORDER
ORDER · A THEN B A B point
LESSON 03TYPE · BUILD~75 MINPREREQ · LESSONS 01–02ORIGINAL LESSON ↗
THE 60-SECOND VERSIONThen show me how ↓
01 / THE COLUMNS ARE DESTINATIONS

To know the matrix, watch where the basis lands.

Multiply M by [1, 0] and you get its first column; multiply by [0, 1] and you get the second. Those two landing spots describe the whole transformation — every other point follows because the grid stretches with them.

M e₁ = (a, c) M e₂ = (b, d)
02 / COMPOSITION READS RIGHT TO LEFT

Doing A then B is the matrix B @ A.

Composition is just multiplication of the machines. The matrix closest to the point acts first, exactly like f(g(x)) is read from the inside out. Swap the order and the endpoint usually changes.

B @ A @ p = B @ (A @ p)
03 / DIRECTIONS THAT SURVIVE

Eigenvectors only stretch, never turn.

Out of every arrow in the plane, a few come back along the same line after the matrix hits them. The stretch factor is the eigenvalue λ. Repeated multiplication then grows them like λᵗ — the whole RNN stability story.

A v = λ v
MENTAL MODEL IN ONE SENTENCE

A matrix is not a grid of numbers — it is a verb. Its columns say where the basis arrows land, its determinant says what happens to area, and its eigenvalues say which directions survive being multiplied by it again and again.

By the end you will read any 2×2 matrix as a transformation, compose two of them and predict the order effect, find eigenvalues from the characteristic equation, rebuild a matrix as A = V D V⁻¹, and explain in one sentence why a signal in an RNN explodes or vanishes.

THE COLUMNS ARE DESTINATIONS

Read the columns,
see the space move.

A matrix is a machine that reshapes space. To know everything it does, you only need to know where it sends two arrows: e₁ = [1, 0] and e₂ = [0, 1].

Multiply any matrix by [1, 0] and you get its first column. Multiply by [0, 1] and you get its second column. So a matrix is a compact way of saying “the x-arrow goes here, the y-arrow goes there, and the whole grid stretches to match.”

That single fact lets you read a matrix by eye. Take M = [[2, 0], [0, 0.5]]. Its first column is (2, 0), so the x-arrow doubles; its second column is (0, 0.5), so the y-arrow halves. Numeric check: M @ [3, 1] = (6, 0.5), which is exactly 3 · [2, 0] + 1 · [0, 0.5]. Every point rides along as a mix of the two columns — that property is called linearity.

e₁e₂M p = (2.9, 1.6)M = [[1.1, 0.7], [0.2, 1.2]]col 1 = M e₁ = (1.1, 0.2)col 2 = M e₂ = (0.7, 1.2)p = (2, 1) = 2·e₁ + 1·e₂ → M p = 2·(col 1) + 1·(col 2) = (2.9, 1.6)
The dashed arrows are the basis before the matrix; the solid arrows are where they land. Those landing spots are the columns, and every other point is a mix of them. That is all a matrix is saying.
Derivation: the rotation matrix comes from the unit circle

A rotation by angle θ keeps lengths and angles fixed. The definition of sine and cosine is all we need to write its matrix.

  1. Rotate e₁ = [1, 0] by θ counter-clockwise. It stays on the unit circle and now sits at angle θ, so it lands at [cos θ, sin θ]. That is column 1.
  2. e₂ = [0, 1] starts at 90°. After rotating it sits at 90° + θ, so it lands at [cos(90° + θ), sin(90° + θ)] = [−sin θ, cos θ]. That is column 2.
  3. Put the columns side by side: R(θ) = [[cos θ, −sin θ], [sin θ, cos θ]].
θ = 90°: cos = 0, sin = 1 → R = [[0, −1], [1, 0]] R @ [3, 1] = [0·3 + (−1)·1, 1·3 + 0·1] = [−1, 3] ✓ straight up and left θ = 45°: cos = sin = 0.7071 R @ [1, 0] = [0.7071, 0.7071] ← the x-arrow half-turned R @ [0, 1] = [−0.7071, 0.7071] ← the y-arrow half-turned det R = cos θ · cos θ − (−sin θ)(sin θ) = cos²θ + sin²θ = 1 rotations never change area.
THE FOUR BASIC MOVES

Turn, stretch, slant,
mirror.

Every linear transformation in 2D is some combination of four moves, and each has a two-by-two matrix you can read at a glance.

Rotation slides every point along a circle. Scaling stretches or compresses along each axis independently. Shearing shifts one coordinate in proportion to the other, sliding rows sideways. Reflection flips space across an axis. Each one is a small matrix, and each one tells you its own area story through the determinant.

Rotation[[cos θ, −sin θ], [sin θ, cos θ]]45° turn. Lengths and angles kept.det = 1Scaling[[sx, 0], [0, sy]]x doubled, y halved.det = sx·syShear[[1, k], [0, 1]]Rows slide sideways.det = 1Reflection[[−1, 0], [0, 1]]Mirror across the y-axis.det = −1
Every transformation a network applies is built from these four moves (and their 3D versions). Dashed square = before; shaded = after. Notice the shear: the square tilts, but the area — the determinant — is unchanged.
MoveMatrixWhat happens to spacedet
Rotation by θ[[cos θ, −sin θ], [sin θ, cos θ]]Every point slides along a circle; lengths and angles preserved.1
Scaling[[sx, 0], [0, sy]]Stretch or squash along each axis independently.sx·sy
Shear in x[[1, k], [0, 1]]x shifts by k·y; rectangles become parallelograms, area unchanged.1
Reflection (y-axis)[[−1, 0], [0, 1]]Mirror image; area preserved, orientation flipped.−1
Worked check: rotation preserves distances, shear bends without stretching area

Numbers make both claims checkable. Rotate the unit square’s corners by 45°, then shear them with k = 1.

Rotation R @ (x, y) = (0.7071x − 0.7071y, 0.7071x + 0.7071y) corners: (0,0) (1,0) (1,1) (0,1) R @ each: (0,0) (0.7071, 0.7071) (0, 1.4142) (−0.7071, 0.7071) distance between (0.7071,0.7071) and (0,1.4142): √(0.7071² + 0.7071²) = √(0.5 + 0.5) = 1 ✓ side still 1 diagonal (−0.7071,0.7071) → (0.7071,0.7071): √(1.4142²) = 1.4142 = √2 ✓ diagonal still √2 Rᵀ R = I, so no length can change. Shear Sh = [[1, 1], [0, 1]] → (x, y) ↦ (x + y, y) corners: (0,0) (1,0) (2,1) (1,1) base 1, height 1, so area = 1 (a slanted parallelogram, not a stretched one) det Sh = 1·1 − 1·0 = 1 ✓ same number as rotation, different shape

The determinant sees the parallelogram’s area, not its slantedness. That is why a shear and a rotation can share det = 1 while looking nothing alike.

COMPOSITION: ORDER MATTERS

Do this, then that.
Right to left.

Applying A and then B is the same as applying one single matrix: B @ A. The matrix nearest the vector acts first, and swapping the order usually lands somewhere else.

Rotate 90° then scale by (2, 0.5) and the point (1, 0) lands at (0, 0.5). Scale first and the same point lands at (0, 2). Same two machines, four times the distance — because matrix multiplication is not commutative. The combined matrices are different too: S @ R = [[0, −2], [0.5, 0]] while R @ S = [[0, −0.5], [2, 0]].

S @ R : rotate 90°, then scale (2, 0.5)(1, 0)R(0, 1)S(0, 0.5)R @ S : scale (2, 0.5), then rotate 90°(1, 0)S(2, 0)R(0, 2)start (1,0)rotate first: (0, 0.5)scale first: (0, 2)same start, two endings
Composition is matrix multiplication and it reads right to left. Swapping the order swaps which machine the point meets first, and here the two endpoints differ by a factor of four.

Composition: A then B, or B then A

Pick two machines and an order. The animation applies the first, then the second; the readout compares the two orders on the same point.

Machine ARotate 90°
Machine BScale (2, 0.5)
A then B → combined matrix M = B @ A M = [[0, -2.00], [0.50, 0]] M @ [1, 0] = [0, 0.50] the other order N = A @ B = [[0, -0.50], [2.00, 0]] N @ [1, 0] = [0, 2.00] different destinations: M ≠ N, so order matters ✓

Rotate 90° then scale (2, 0.5) sends [1, 0] to [0, 0.5]. The other order sends it to [0, 2]. Same two machines; four times the distance.

Why B @ A means A first, and why swapping changes the answer
  1. Applying A to a point p gives A p. Applying B to that result gives B(A p).
  2. Matrix multiplication is associative, so B(A p) = (B A) p. The single matrix that performs “A then B” is therefore B @ A.
  3. Read compositions right to left, the way you read f(g(x)) from the inside out. The matrix nearest the vector acts first.
  4. Commutativity is a different property, and it fails. Compare the two products entry by entry: S @ R has a 2 in the top-right, R @ S has a 0.5 there. Different matrices.
R = [[0, −1], [1, 0]] S = [[2, 0], [0, 0.5]] A then B is B @ A: S @ R = [[2·0 + 0·1, 2·(−1) + 0·0], [0·0 + 0.5·1, 0·(−1) + 0.5·0]] = [[0, −2], [0.5, 0]] S @ R @ [1, 0] = [0, 0.5] rotate first ✓ R @ S @ [1, 0] = [0, 2] scale first ✗ different associative: (A @ B) @ C = A @ (B @ C) ← grouping never matters commutative: A @ B = B @ A ← order often matters
THE DETERMINANT: AN AREA METER

One number says
what happened to area.

Draw the unit square, apply the matrix, and measure the parallelogram you get. Its signed area is the determinant — the fastest way to tell whether a transformation is invertible.

For M = [[a, b], [c, d]] the determinant is ad − bc. It is the factor by which the transformation scales area in 2D — and volume in 3D. Numeric check: [[2, 1], [0.5, 1.5]] has det = 2·1.5 − 1·0.5 = 2.5, so the unit square lands as a parallelogram with area 2.5.

det = 1 means area is preserved (rotation, shear). det = 0 means the plane was crushed onto a line or point: information is destroyed and no inverse exists. A negative determinant means area is preserved in size but flipped — the same number, opposite orientation. That sign is the only thing separating a rotation (det = 1) from a reflection (det = −1).

The determinant is an area meter

Edit the matrix and watch the unit square land as a parallelogram. The bars on the right compare one unit of area with what the image now holds.

M =
M = [[1.00, 1.00], [0, 1.00]] det M = a·d − b·c = 1.00·1.00 − 1.00·0 = 1.00 area factor |det| = 1.00 orientation: preserved (det > 0) inverse exists: A⁻¹ undoes the map exactly.

Rotation and shear have det = 1: the shape changes, the area does not. Scaling by (2, 0.5) also has det = 1 — a squash here is paid for by a stretch there. In 3D this same number measures volume.

Derivation: why det = ad − bc is the area of the image

The matrix [[a, b], [c, d]] sends e₁ = [1, 0] to the first column u = (a, c) and e₂ = [0, 1] to the second column v = (b, d). The unit square lands as the parallelogram spanned by u and v. Draw it inside the rectangle of width a + b and height c + d, then cut away everything that is not the parallelogram: two triangles of area ½ac, two of area ½bd, and two small rectangles of area bc each.

(a + b)(c + d) − ac − bd − 2bc = ad − bc so the image of the unit square has signed area ad − bc. Zero area = the columns point the same way = a crushed dimension = no inverse. Numeric check, M = [[2, 1], [0.5, 1.5]]: det = 2·1.5 − 1·0.5 = 2.5 corners of the image: (0,0), (2, 0.5), (3, 2), (1, 1.5) shoelace area = ½|2·2 − 3·0.5 + 3·1.5 − 1·2 + 1·0 − 0·1.5 + 0·0.5 − 2·0| = ½|2.5 + 2.5| = 2.5 ✓ matches the determinant det of a product is the product of dets: det(B @ A) = det(B) · det(A) ← areas multiply, so scale factors multiply

That last line matters for deep networks: applying 10 layers multiplies 10 area factors together. Any single det near zero can squash the whole product flat.

EIGENVECTORS: DIRECTIONS THAT SURVIVE

Most arrows turn.
These only stretch.

Hit a plane with a matrix and almost every arrow changes direction. A few special arrows come back along the same line, scaled by a factor λ. Those are the eigenvectors, and λ is the eigenvalue.

The whole definition is one equation: A v = λ v, with v not the zero vector. It says: apply the matrix, and the result points along the same line as v — only its length changed. Numeric check with A = [[2, 1], [1, 2]]:

A @ [1, 1] = [2·1 + 1·1, 1·1 + 2·1] = [3, 3] = 3 · [1, 1] → λ = 3 A @ [1, −1] = [2·1 + 1·(−1), 1·1 + 2·(−1)] = [1, −1] = 1 · [1, −1] → λ = 1 the diagonal direction triples; the anti-diagonal is untouched. Every other arrow is a mix of those two behaviours.

Eigen-directions: the arrows that stay put

Edit the matrix. Purple dashed lines are the directions the matrix only stretches — the labels are their stretch factors. Try Rotate 90° to see the complex case.

M =
M = [[2.00, 1.00], [1.00, 2.00]] trace = 4.00 det = 3.00 characteristic equation: λ² − 4.00λ + 3.00 = 0 λ₁ = 3.00 λ₂ = 1.00 eigenvector 1 ≈ [0.71, 0.71] eigenvector 2 ≈ [0.71, -0.71] A @ [0.71, 0.71] = [2.12, 2.12] λ · v = 3.00 · [0.71, 0.71] = [2.12, 2.12] ✓ A @ [0.71, -0.71] = [0.71, -0.71] λ · v = 1.00 · [0.71, -0.71] = [0.71, -0.71] ✓

Two shortcuts catch slips: the eigenvalues always add up to the trace (3 + 1 = 4) and multiply to the determinant (3 · 1 = 3). A negative discriminant means no real direction survives.

Derivation: the characteristic equation, and [[2, 1], [1, 2]] solved completely
  1. Start from the definition: A v = λ v, with v not the zero vector.
  2. Move everything to one side. λv is the same as λI v (I is the identity), so A v − λI v = 0, i.e. (A − λI) v = 0.
  3. A matrix that sends a nonzero vector to zero has squashed a dimension. From Lesson 02, that means its determinant is zero: det(A − λI) = 0. This is the characteristic equation.
  4. For a 2×2 matrix, A − λI = [[a − λ, b], [c, d − λ]], and its determinant is (a − λ)(d − λ) − bc = λ² − (a + d)λ + (ad − bc). So the eigenvalues solve λ² − trace·λ + det = 0.
A = [[2, 1], [1, 2]]: trace = 4, det = 3 λ² − 4λ + 3 = 0 → (λ − 1)(λ − 3) = 0 → λ = 3 or λ = 1 Eigenvector for λ = 3: (A − 3I) v = [[−1, 1], [1, −1]] v = 0 row 1: −v₁ + v₂ = 0 → v₂ = v₁ → v = [1, 1] (any multiple works) check: A @ [1, 1] = [2+1, 1+2] = [3, 3] = 3 · [1, 1] ✓ Eigenvector for λ = 1: (A − I) v = [[1, 1], [1, 1]] v = 0 row 1: v₁ + v₂ = 0 → v₂ = −v₁ → v = [1, −1] check: A @ [1, −1] = [2−1, 1−2] = [1, −1] = 1 · [1, −1] ✓ Two shortcuts catch slips: the eigenvalues add up to the trace (3 + 1 = 4) and multiply to the determinant (3 · 1 = 3).

A negative discriminant under the square root gives complex eigenvalues: the algebra telling you the transformation contains a rotation, and no real arrow survives. Try the Rotate 90° preset in the lab — the pair becomes ±i and the plan view shows a pure spin.

EIGENDECOMPOSITION: A = V D V⁻¹

Change coordinates,
stretch, change back.

If a matrix has two independent eigenvectors, it can be written as three simpler machines: V, D, V⁻¹. D is diagonal — the hard part is only a pair of coordinate changes.

A = V D V⁻¹. Here V holds the eigenvectors as its columns, D is the diagonal matrix of eigenvalues, and V⁻¹ is the inverse that undoes V. Read right to left: V⁻¹ translates the point into eigenvector coordinates, D stretches each coordinate by its eigenvalue, and V translates the result back to ordinary coordinates.

For A = [[2, 1], [1, 2]], the eigenvectors are [1, 1] and [1, −1], so V = [[1, 1], [1, −1]] / √2 and D = [[3, 0], [0, 1]]. Numeric check: V D V⁻¹ = [[2, 1], [1, 2]] exactly, which is the claim of the decomposition.

A p = V D V⁻¹ p : the same trip, told in three stepsV⁻¹into eigen-coordinatesDstretch by λ₁, λ₂Vback to normalevery arrow becomes a scalar multiplynothing is lost, nothing is invented
Eigendecomposition is a change of viewpoint: A looks complicated in ordinary coordinates and diagonal in eigenvector coordinates. Between the two changes of coordinates, the matrix is just two stretches.
Derivation: why A = V D V⁻¹, and a numeric rebuild
  1. Put the eigenvectors side by side as the columns of V. Applying A to each column gives back that column times its eigenvalue: A V = V D. (D is diagonal, so multiplying it on the right scales column i by λᵢ.)
  2. Multiply both sides on the right by V⁻¹ — allowed because the eigenvectors are independent, so V is invertible: A = V D V⁻¹.
  3. The three factors are all easy to apply: two coordinate changes and a diagonal stretch. That is the whole idea of a change of basis.
A = [[2, 1], [1, 2]], V = (1/√2)·[[1, 1], [1, −1]], D = [[3, 0], [0, 1]] V⁻¹ = V here (this V is its own inverse: V @ V = I): V D V = ½·[[1, 1], [1, −1]] @ [[3, 0], [0, 1]] @ [[1, 1], [1, −1]] = ½·[[3, 1], [3, −1]] @ [[1, 1], [1, −1]] = ½·[[4, 2], [2, 4]] = [[2, 1], [1, 2]] ✓ in eigen-coordinates the same A is just diag(3, 1): anything along [1, 1] gets ×3, anything along [1, −1] gets ×1.

A symmetric matrix has perpendicular eigenvectors, so its V is a rotation or reflection and V⁻¹ = Vᵀ — the friendliest case, and the one PCA lives in.

Eigenvalues from the characteristic equation — Pythonpython
def eigenvalues_2x2(m):
    (a, b), (c, d) = m
    trace, det = a + d, a * d - b * c
    disc = trace ** 2 - 4 * det
    if disc < 0:                    # complex pair: this matrix rotates
        return (complex(trace / 2, (-disc) ** 0.5 / 2),
                complex(trace / 2, -(-disc) ** 0.5 / 2))
    r = disc ** 0.5
    return ((trace + r) / 2, (trace - r) / 2)

eigenvalues_2x2([[2, 1], [1, 2]])   # (3.0, 1.0)

import numpy as np
vals, vecs = np.linalg.eig(np.array([[2, 1], [1, 2]], dtype=float))
# vals = [3, 1]
# vecs columns ≈ [0.707, 0.707] and [-0.707, 0.707]

V, D = vecs, np.diag(vals)
np.allclose(V @ D @ np.linalg.inv(V), [[2, 1], [1, 2]])  # True: A = V D V⁻¹
Build the polynomial from trace and determinant, solve the quadratic, then compare with numpy.linalg.eig.
REPEATED MULTIPLICATION: EXPLODE OR VANISH

A hundred steps
is a hundred multiplications.

A recurrent network updates its hidden state as h ← W h. Every step multiplies by W, so each eigen-direction is raised to a power — and that power decides whether the signal explodes or disappears.

Write the update as h_t = W @ h_(t−1). After T steps, h_T = W^T @ h_0. Decompose h₀ into W’s eigenvectors: each component is multiplied by its own eigenvalue once per step, so after T steps it has been multiplied by λᵀ.

That makes the magnitude of λ the whole story. Along λ = 1.05 the signal grows by 1.05¹⁰⁰ ≈ 131× in a hundred steps — explosion. Along λ = 0.95 it shrinks to 0.95¹⁰⁰ ≈ 0.006 of itself — vanishing. The spectral radius, the largest |λ|, is the single number that predicts which regime the network lands in.

Repeated multiplication: explode or vanish

An RNN multiplies its state by the same matrix at every step. Press play to walk the trajectory h ← A h and watch each eigen-direction grow or shrink by its own factor.

A = [[1.05, 0], [0, 0.95]] h₀ = [1, 1] h_20 = A^20 h₀ = [2.65, 0.36] after 20 steps the state is ×2.677 its starting length λ₁ = 1.05 → 1.05^20 = 2.6533 λ₂ = 0.95 → 0.95^20 = 0.3585 spectral radius = 1.050 |λ| > 1 → the state explodes exponentially

A diagonal matrix stretches each axis by its eigenvalue: 1.05²⁰ ≈ 2.65 while 0.95²⁰ ≈ 0.36. After 100 steps those become ≈ 131 and ≈ 0.006 — the exploding/vanishing signal problem in one picture.

Worked check: one matrix, two fates

Take a diagonal weight matrix so the eigen-directions are just the axes: W = [[1.05, 0], [0, 0.95]] and h₀ = [1, 1]. Then h_T = [1.05ᵀ, 0.95ᵀ], entry by entry.

T λ = 1.05 λ = 0.95 1 1.0500 0.9500 10 1.6289 0.5987 20 2.6533 0.3585 50 11.4674 0.0769 100 131.5013 0.0059 h_10 = [1.63, 0.60] h_20 = [2.65, 0.36] h_100 = [131.50, 0.01] ← one direction exploded, the other vanished spectral radius = max(|λ₁|, |λ₂|) = 1.05 > 1 → explodes over time negative λ flips sign every step; complex λ rotates the spiral |λ| = 1 keeps the component's size forever (rotation without drift)

In a real RNN, W is not diagonal, but the same statement holds in its eigenvector coordinates: the h₀-component along each eigenvector is multiplied by λᵀ. Vanishing and exploding gradients are what happens when training pushes through those same powers in reverse.

BUILD IT

Write the machines once.
Read any matrix forever.

Two dozen lines of Python reconstruct every transformation in this lesson — and the composition rule is just nested loops around a sum.

Notice that mat_mul never looks at the numbers as geometry. It only obeys the shape rule from Lesson 02: row i of the left matrix meets column j of the right one. The geometry emerges from the multiplication — which is why the same six lines implement rotations, shears, and whole neural network layers.

Transformations and composition from scratch — Pythonpython
import math

def rotation_2d(theta):
    c, s = math.cos(theta), math.sin(theta)
    return [[c, -s], [s, c]]

def scaling_2d(sx, sy):
    return [[sx, 0], [0, sy]]

def shearing_2d(kx, ky):
    return [[1, kx], [ky, 1]]

def reflection_y():
    return [[-1, 0], [0, 1]]

def mat_vec_mul(matrix, vector):
    return [sum(row[j] * vector[j] for j in range(len(vector)))
            for row in matrix]

def mat_mul(a, b):
    inner = len(a[0])
    return [[sum(a[i][k] * b[k][j] for k in range(inner))
             for j in range(len(b[0]))]
            for i in range(len(a))]

R = rotation_2d(math.pi / 2)     # rotate 90°
S = scaling_2d(2, 0.5)           # scale (2, 0.5)
point = [1.0, 0.0]

print(mat_vec_mul(mat_mul(S, R), point))   # [0.0, 0.5]  rotate first
print(mat_vec_mul(mat_mul(R, S), point))   # [0.0, 2.0]  scale first

# B @ A applies A first. Swapping the order changes the destination.
Every move in this lesson is one small matrix; composition is one call to mat_mul.

Now compute a composition by hand. Fill in all four entries of M = B @ A, then reveal the arithmetic if you get stuck.

Compose it yourself

M is the single matrix that applies A first, then B, so M = B @ A. Fill in the four entries, then check. Rows of B meet columns of A.

A =
1.002.0001.00
B =
2.0001.001.00
M = B @ A
Fill all four entries, then press Check. M = B @ A applies A first, then B. Convention: B @ A @ p = B @ (A @ p).
CHECK YOURSELF

Five questions.
Then the terms worth keeping.

Answer before you look. The composition-order and eigenvalue-magnitude questions are exactly the ones that come up when training a recurrent network misbehaves.

0 / 5 answered · 0 correct

01What is an eigenvector of a matrix?

02What does the determinant of a 2D transformation represent geometrically?

03Why is R @ S different from S @ R?

04In an RNN, what happens when the weight matrix has eigenvalues with magnitude greater than 1?

05A = [[2, 1], [1, 2]] has eigenvalues 3 and 1. What does A = V D V⁻¹ reveal?

Key terms, demystified

Click a card to swap the lazy description for what it actually means.

Exercises from the lesson

Three short problems. Try first; a worked answer is one click away.

  1. Apply rotation by 45°, scaling by (2, 3), and shear with k = 1 to the unit square's four corners [0,0], [1,0], [1,1], [0,1]. Verify that the rotation preserves every corner-to-corner distance.
    Show one worked answer

    Rotation R = [[0.7071, −0.7071], [0.7071, 0.7071]] sends the corners to (0, 0), (0.7071, 0.7071), (0, 1.4142), (−0.7071, 0.7071). All four distances between neighboring corners are still 1 and both diagonals are still √2, because RᵀR = I. Scaling S = [[2, 0], [0, 3]] sends the corners to (0, 0), (2, 0), (2, 3), (0, 3): it stretches side lengths to 2 and 3 and multiplies area by 6. Shear Sh = [[1, 1], [0, 1]] sends them to (0, 0), (1, 0), (2, 1), (1, 1): only the second coordinate of the top edge moved, and the area is still 1 because det Sh = 1·1 − 1·0 = 1.

  2. Find the eigenvalues of [[4, 2], [1, 3]] by hand with the characteristic equation, then check both eigenvectors satisfy A v = λv.
    Show one worked answer

    Trace = 4 + 3 = 7 and det = 4·3 − 2·1 = 10, so the characteristic equation is λ² − 7λ + 10 = 0, which factors as (λ − 5)(λ − 2) = 0. Eigenvalues 5 and 2. For λ = 5: (A − 5I) = [[−1, 2], [1, −2]] gives v = [2, 1]; check A @ [2, 1] = [4·2 + 2·1, 1·2 + 3·1] = [10, 5] = 5 · [2, 1] ✓. For λ = 2: (A − 2I) = [[2, 2], [1, 1]] gives v = [1, −1]; check A @ [1, −1] = [4 − 2, 1 − 3] = [2, −2] = 2 · [1, −1] ✓. Sanity checks: the eigenvalues sum to the trace (5 + 2 = 7) and multiply to the determinant (5 · 2 = 10).

  3. Compose rotate 30°, scale by (1.5, 0.8), then shear with kx = 0.3 into one matrix M (apply R first, then S, then Sh). Compute det M and verify it equals the product of the three individual determinants.
    Show one worked answer

    Apply R first, so M = Sh @ S @ R. With R = [[0.8660, −0.5], [0.5, 0.8660]], S @ R = [[1.2990, −0.75], [0.4, 0.6928]], and M = Sh @ (S @ R) = [[1.4190, −0.5422], [0.4, 0.6928]]. The determinants are det R = 1, det S = 1.5 · 0.8 = 1.2, det Sh = 1, so the product is 1.2. Direct check: det M = 1.4190 · 0.6928 − (−0.5422)(0.4) = 0.9831 + 0.2169 = 1.2 ✓. A circle of 8 points would come back as the same circle stretched by area 1.2, sheared and turned — the determinant only tracks area, not shape.

Terms this lesson borrows from later lessons (or outside)

You do not need to master these here. Each one gets a proper treatment in its own lesson; the one-line meaning is enough to keep reading. Orange dotted underlines in the prose point back to this list.

  • gradientThe list of derivatives of the loss with respect to every parameter. It points in the direction that increases the loss fastest; training steps the other way. (Lesson 4)
  • trainingRepeatedly adjusting a model's weights to reduce its loss on example data. (Lesson 4)
  • varianceHow spread out a set of numbers is: the average squared distance from their mean. (Lesson 6)
  • covariance matrixA matrix whose entry (i, j) measures how features i and j vary together; the diagonal holds each feature's variance. (Phase 2 — PCA)
  • hidden stateThe vector an RNN carries from one time step to the next; its working memory.
  • NumPyNumerical Python: the standard array library, fast because its loops run in compiled C. Its eig returns eigenvectors as columns.
  • spectralMethods that analyse a graph or matrix through its eigenvalues and eigenvectors (its “spectrum”).
  • adjacency matrixA matrix with a 1 at (i, j) when node i is connected to node j; it encodes a graph as a matrix. (Lesson 21)
  • LaplacianA matrix built from a graph's connections (degree matrix minus adjacency matrix) whose eigenvectors reveal clusters. (Lesson 21)
KEEP GOING

A picture is a start.
Practice is the rest.

This lesson is a port of an open course. Everything here traces back to it — and the next step is running the code yourself.

Lesson text adapted from AI Engineering from Scratch (Phase 01, Lesson 03) and the Math Foundations Notebook reference build. Interactive figures, the transformation and eigen labs, the RNN trajectory, worked exercise answers, and the composition trainer are original to this page. Every lab runs in your browser.