“It is by logic that we prove, but by intuition that we discover.” - Henri Poincaré
Linear algebra appears in subjects ranging from machine learning to network design. Knowing how to multiply matrices is useful, but it helps to understand what those calculations mean. A matrix changes a vector, and the way it changes depends on the vector’s direction. Understanding that relationship gives us a way to break complicated calculations into simpler pieces and see why eigenvectors and eigenvalues are useful.
My aim is to build that understanding through pictures and small examples. We’ll start with arrows on a plane and follow one matrix through most of the primer, introducing each idea as we need it. Along the way, we’ll see how to measure alignment, split a vector into perpendicular pieces, and find directions that make a measurement smallest or largest. This also lays the groundwork for Understanding Networks Through Spectral Graph Theory, where we’ll use these ideas to study connections and bottlenecks in a network.
1. Vectors and coordinates
An arrow describes a movement
Suppose we walk three units right and one unit up. The vector x = (3, 1) is a record of that trip. Start at the origin, and you can draw it as an arrow ending at the point (3, 1).
We can draw the same movement starting anywhere. As long as the arrow still goes three right and one up, it’s still (3, 1). A vector’s entries describe changes in coordinates, not a fixed starting point.[1]
Order matters: (1, 3) means one right and three up, which is a different trip. In the ordinary coordinate pictures, the first entry is always the horizontal movement and the second is the vertical one.
Make the arrow longer or shorter
Multiply both entries by two and we get 2x = (6, 2): the same direction, twice as far. Multiply by ½ and it’s half as long.
A negative multiplier also flips the arrow around: −x goes three units left and one unit down. A number we multiply a vector by is called a scalar,[2] and we apply the same number to every entry.
Doubling both coordinates doubles the length. Same axes, same scale, same direction. Just more arrow.
Follow one arrow, then another
We can also reach (3, 1) in two steps: first move by (1, −1), then by (2, 2). Adding the vectors records the whole journey:
(1, −1) + (2, 2) = (3, 1)
Tip to tail. Draw the second arrow starting where the first one ends. The sum runs straight from the very start to the very end, and it lands in the same place whichever arrow you take first. Entry by entry, you just add the matching numbers.
Keep this split in mind. The two pieces are perpendicular, and we’ll return to them throughout the primer.
The second piece, (2, 2), is twice the arrow (1, 1). So we can write the same sum as:
x = 1(1, −1) + 2(1, 1) = (3, 1)
Scaling vectors and then adding them is called a linear combination. The multipliers 1 and 2 are its coefficients: one copy of the first arrow and two copies of the second.
2. How a matrix transforms a vector
Build a matrix from two rules
How do we turn one vector into another? Call the input entries x₁ and x₂. Each output entry gets its own rule:
First output: double x₁, then add x₂.
Second output: add x₁ to twice x₂.
A matrix records the multipliers in these rules, with one row for each output. We’ll call our matrix M and use it throughout the primer:
M = 2112
The notation Mx means “the output you get by feeding x to M”:
Mx = (2x₁ + x₂, x₁ + 2x₂)
Two rules make M linear. Scaling an input scales its output, and adding inputs adds their outputs.
Read the rows to find the output
For our input (3, 1), the first row gives 2 × 3 + 1 × 1 = 7. The second gives 1 × 3 + 2 × 1 = 5. So the output is Mx = (7, 5).
M changes this arrow's length and its direction. No single scalar could do this: 3 became 7 while 1 became 5, and those aren't the same multiplier.
Keep the matrix fixed and change the input
M follows two rules for every input:
Scaling: multiplying an input by a number multiplies its output by the same number.
Adding: adding two inputs and then applying M gives the same result as applying M to each input separately and adding the outputs.
These rules make M linear. They let us find an output by transforming simpler pieces and adding the results.
The picture shows both rules. On the left, doubling (3, 1) doubles its output (7, 5). On the right, we split the input into (3, 0) and (0, 1); their outputs add up to (7, 5).
Pieces in, pieces out. Left: multiplying the input by a factor multiplies its output by the same factor. Right: adding inputs adds their outputs, M(a + b) = Ma + Mb. Here a = (3, 0) and b = (0, 1); their outputs (6, 3) and (1, 2) add to (7, 5).
The scaling rule also means that zero in gives zero out: M leaves the origin in place.[3]
Read the columns to see where the unit steps go
What happens to a single horizontal step, e₁ = (1, 0)? M sends it to (2, 1), which is the first column of the matrix. A single vertical step, e₂ = (0, 1), goes to (1, 2), the second column.
Each column is where one unit step lands. Follow the blue horizontal step and the orange vertical step from input to output. Both panels use the same scale.
Our input (3, 1) is three horizontal unit steps plus one vertical unit step. Since M is linear, its output is three copies of the first column plus one copy of the second:
Mx = 3(2, 1) + (1, 2) = (7, 5)
Rows are for computing the output one coordinate at a time. Columns show how the transformed unit steps build the output. Same answer, two ways of looking at it.
3. The dot product
We need a way to check whether two arrows are perpendicular. Later, the same calculation will measure how much of one arrow lies along another.
A test for right angles
Take the arrows a = (2, 1) and b = (1, −2). Multiply matching entries, then add. The result is a single number called their dot product:
a · b = 2 × 1 + 1 × (−2) = 0
The two products, 2 and −2, cancel. A zero dot product tells us that these arrows are perpendicular.
For any two vectors with entries (a₁, a₂) and (b₁, b₂), the same calculation is:
a · b = a₁b₁ + a₂b₂
The sign tells you about the angle
For two nonzero vectors, a positive dot product means the angle between them is less than 90°. A negative one means it’s more than 90°. Exactly zero means exactly 90°.
Watch the angle as the second arrow moves. The first arrow stays put in all three panels. The middle pair is perpendicular, and its dot product is zero.
Two nonzero vectors are perpendicular exactly when their dot product is zero. We’ll use this test to find a perpendicular remainder in Chapter 5. Vectors with a zero dot product are called orthogonal.[4]
Perpendicular arrows have a dot product of zero. Resizing them leaves the right angle unchanged.
Our earlier pair passes the test: (1, −1) and (2, 2) give 1 × 2 + (−1) × 2 = 0. The arithmetic confirms the right angle without trusting anybody’s drawing skills. With more entries, the rule is the same: multiply matching entries and add.
The number also depends on length
Double either arrow and the dot product doubles, even though the angle stays the same. So the dot product depends on both the angle and the lengths of the arrows.
We can simplify things by making the reference arrow one unit long. The dot product then tells us how much of the other arrow lies along that direction. A positive value means that part points with the reference arrow; a negative value means it points against it. First, we’ll build this unit arrow, then see why the measurement works.
Optional: the same calculation in matrix notation
In matrix notation, a vector’s entries are usually stacked in a column. The transpose, written aᵀ, turns that column into a row. Multiplying the row aᵀ by the column b multiplies matching entries and adds them, just as we did above.
So aᵀb and a · b are two ways to write the same dot product.
4. Length and unit vectors
Length versus squared length
To make an arrow one unit long, we first need to know its length. Squared length is just the length multiplied by itself.
For a separate example, take an arrow of length 3. Its squared length is 3 × 3 = 9. If we double every coordinate:
Measurement
Length-3 arrow
After doubling
Length
3
6
Squared length
3 × 3 = 9
6 × 6 = 36
The length doubles, but the squared length becomes four times as large. To get the length back, take the square root: √9 = 3.
Optional: squared growth in a pizza example
Doubling a pizza's diameter quadruples its area. Doubling an arrow quadruples its squared length.
Find length from the coordinates
For our arrow (3, 1), the horizontal and vertical steps make a right triangle, so Pythagoras gives squared length 3² + 1² = 10. Its length is √10, about 3.16.[5]
Dotting x with itself adds up those same squared coordinates. We write the length of x as ‖x‖, with double bars. It’s also called the Euclidean norm:
‖x‖² = x · x = x₁² + x₂²
Make a one-unit measuring step
To measure along a direction, we want a standard step. An arrow of length exactly one does the job. It’s called a unit vector.
Our x has length √10, so dividing every coordinate by √10 makes its length one. Both entries shrink by the same factor, so the direction doesn’t change. Call the new arrow x̂, read “x-hat”:
x̂ = x/‖x‖ = (3, 1)/√10
Same direction, length one. The tip of x̂ lands on the circle of radius one. We shortened the arrow without turning it, which gives us a one-unit step along x's direction.
As a check, x̂ has squared length 9/10 + 1/10 = 1. Dividing a nonzero vector by its length is called normalization.[6] In Chapter 8, we’ll apply the same operation to our reference arrows.
How the dot product includes both length and angle
Let θ be the angle between two nonzero arrows a and b. Then a · b = ‖a‖ ‖b‖ cos θ. The lengths explain why scaling either arrow changes the dot product. The cosine explains the sign: at 90°, it is zero. If b has length one, only a’s length and its alignment with b remain in the measurement.
5. Projection: find the part along a line
Split one arrow into two useful pieces
Start with x = (3, 1). We want the part along the diagonal through d = (1, 1).
Imagine dropping a perpendicular from the tip of x onto that diagonal. The arrow from the origin to the landing point is the projection, or shadow, of x on the line. Call it p. The remaining step from p’s tip to x’s tip is r.
A perpendicular drop finds the projection. The remaining step meets the reference line at a right angle.
For our example, the two pieces are:
x = p + r = (2, 2) + (1, −1)
Follow p along the line, then r to the tip of x. The faint alternative connection is longer than the perpendicular one. The coordinates of r describe its movement from p's tip, even though it doesn't start at the origin.
The piece p = (2, 2) follows the diagonal. The remainder r = (1, −1) is perpendicular to it: its dot product with d = (1, 1) is 1 − 1 = 0. These are the two checks that make this the projection split.
Optional: how do we find (2, 2)?
A point on the diagonal has equal coordinates, so write the unknown projection as $p=(a,a)$. The arrow from $p$ to our original point $x=(3,1)$ is:
\[r=x-p=(3-a,\;1-a)\]
The diagonal points in the direction $(1,1)$. We want $r$ to be perpendicular to that direction, so their dot product must be zero. Multiply matching coordinates and add:
\[r\cdot(1,1)=(3-a)\times1+(1-a)\times1=0\]
Since both multiplications are by 1, this simplifies to:
\[(3-a)+(1-a)=0\]
Combining terms gives $4-2a=0$, so $a=2$. Our projection is therefore $p=(2,2)$.
The remaining arrow is $r=(1,-1)$, which is perpendicular to the diagonal. This perpendicular connection is the shortest path from $x$ to the line.
Find a projection with a dot product
Let u be an arrow of length one along the chosen line. Think of u as a one-unit step in that direction.
The dot product x · u gives us a number. For example, if that number is 3, the projection is 3u: an arrow three units long in the direction of u. The original arrow x may also have a perpendicular piece.
If the number is −3, the projection points three units in the opposite direction.
To get the projection arrow, multiply that number by u:
p = (x · u)u
The number x · u is called the coefficient. The resulting arrow p is the component of x along the line.
Optional: the same component with two measuring steps
The diagonal arrow d = (1, 1) has length √2. Divide each entry by √2 to make a one-unit arrow:
u = (1, 1)/√2
The dot product tells us how many u steps to take:
x · u = (3 + 1)/√2 = 2√2
So we can reach the projection using either 2 steps of d or 2√2 steps of u:
p = 2d = 2√2 u = (2, 2)
The reference arrow gets shorter; the component stays put. Both drawings use the same coordinate scale. The bigger coefficient makes up for the shorter step.
The unit arrow u is shorter than d, so we need more steps to reach the same point. The number of steps changes, but the projection stays at (2, 2).
The squared lengths add
Because p and r meet at a right angle, Pythagoras applies. Their squared lengths add to x’s squared length:
‖x‖² = ‖p‖² + ‖r‖² = 8 + 2 = 10
This will help us measure how much of an input lies in each of two perpendicular directions.[7]
6. Eigenvectors and eigenvalues
M can change both an arrow’s length and direction. We want to find directions where it only scales the arrow. If we can split an input along those directions, we can get its output by scaling the pieces and adding them.
Watch three arrows go through the same matrix
Use our same matrix:
M = 2112
Compare our input x = (3, 1) with two diagonal arrows, q₁ = (1, −1) and q₂ = (1, 1). Press Play transformation or drag from Before to After. This shows one application of M. The frames in between are animation steps, not repeated matrix multiplications.
BeforeAfter M
Follow the arrows from where they start to where M sends them. This is one application of M.
The same M transforms the whole grid. The ordinary axes stay fixed so we can compare before and after. Dashed arrows mark where x and q₂ began; q₁ doesn't move at all.[8]
Input
Output
What happened?
x = (3, 1)
Mx = (7, 5)
It grew and turned.
q₁ = (1, −1)
Mq₁ = (1, −1)
It stayed exactly the same: multiply by 1.
q₂ = (1, 1)
Mq₂ = (3, 3)
It stayed on its line and grew: multiply by 3.
Name the arrow and the number
A nonzero arrow that the matrix multiplies by one number is an eigenvector.[9] That number is its eigenvalue. In symbols:
Mv = λv
Read this as: “applying M to v has the same effect as multiplying v by λ.” The eigenvector tells us the direction; the eigenvalue tells us the multiplier. For M, q₁ has eigenvalue λ₁ = 1 and q₂ has eigenvalue λ₂ = 3.
Eigenvectors must be nonzero. The zero vector satisfies M0 = λ0 for every λ, so it cannot identify a particular eigenvalue.
The direction matters more than the length
Any nonzero multiple of q₁ is still an eigenvector with eigenvalue 1. Any nonzero multiple of q₂ still has eigenvalue 3. Making an arrow longer does not change which eigenvector line it lies on.
For other matrices, a negative eigenvalue reverses the arrow along the same line.[10] A zero eigenvalue sends a nonzero arrow to the origin. The zero arrow itself is excluded: multiplying it by any number gives zero, so it cannot identify a particular multiplier.
Optional: check every direction, and apply M more than once
The chart shows how much M turns an arrow for each starting direction. The two eigenvector lines are the only lines it leaves unturned.
Directions 180° apart turn by the same amount, because M(−x) = −Mx. The pattern repeats after half a turn.
Other arrows turn toward the q₂ line, by at most 30° in one application. Repeated applications move them closer to that line unless they started exactly on q₁.[11]
Along q₂, each application multiplies by 3. Two applications multiply by 3 × 3 = 9.
The list of eigenvalues, including repeats, is called the spectrum.[12]
In ordinary coordinates, x = (3, 1) means three horizontal unit steps and one vertical unit step. We can reach exactly the same point using the eigenvectors q₁ = (1, −1) and q₂ = (1, 1) as our reference steps:
x = q₁ + 2q₂ = (1, −1) + (2, 2) = (3, 1)
Using q₁ and q₂, x has coordinates (1, 2): one q₁ step and two q₂ steps. Its ordinary horizontal and vertical coordinates are still (3, 1). Changing coordinates changes the description of x. It does not move x.
The same arrow can have different coordinates. Three horizontal steps and one vertical step reach the same point as one q₁ step and two q₂ steps.
Transform each piece, then add
M keeps the q₁ component the same and triples the q₂ component. So 1q₁ + 2q₂ becomes 1q₁ + 6q₂. Using q₁ and q₂, the output coordinates are (1, 6). Adding the component arrows gives the output in ordinary coordinates:
Mx = q₁ + 6q₂ = (1, −1) + (6, 6) = (7, 5)
Reference steps
Input coordinates
Output coordinates
Horizontal and vertical unit steps
(3, 1)
(7, 5)
q₁ and q₂
(1, 2)
(1, 6)
Changing coordinates keeps x fixed. Applying M produces Mx. All three stages use the same ordinary scale. The first two split the same input into different pieces. In the third, the q₁ piece stays put and the q₂ piece triples. The faint original x shows how much it changed.
This works because M is linear: we can transform the pieces separately and then add the results. Eigenvector coordinates make each separate transformation a simple multiplication.
What makes a valid coordinate system?
A basis is a set of reference arrows that can build every vector by scaling and adding. Each vector must have exactly one choice of coefficients.
In the plane, any two nonparallel arrows form a basis. Our q₁ and q₂ qualify. Two arrows pointing along the same line do not: they cannot reach points away from that line.
Optional: “span” and “linearly independent”
Enough directions, and only one recipe per point. Left: with e₁ and 2e₁, every combination stays on the horizontal line, and even points on the line have two descriptions. Right: q₁ and q₂ point in different directions, so their combinations tile the whole plane, and each point gets exactly one recipe.
Reference arrows span the plane if their combinations reach every point. They are linearly independent if none is a combination of the others. Together, these properties give enough directions and a unique recipe.
The arrows e₁ and 2e₁ fail both tests. They only reach the horizontal line, and even there a point can have different recipes: (2, 0) is two copies of e₁ or one copy of 2e₁.
We can now understand every input from the matrix’s responses along its eigenvector lines.[13] Next, we will see why perpendicular reference directions are especially useful.
8. Why perpendicular reference arrows help
We can already transform x by splitting it along q₁ and q₂. Now we want an easy way to find those pieces for any input. Perpendicular unit reference arrows let us do that with dot products.
Use reference arrows of length one
Our original reference arrows q₁ and q₂ each have length √2. Divide each by √2 and call the resulting unit arrows u₁ and u₂. Each u arrow points in the same direction as its matching q arrow:
u₁ = q₁/√2 = (1, −1)/√2 u₂ = q₂/√2 = (1, 1)/√2
This changes the size of a reference step. It does not change x or its pieces. The same pieces now need √2 steps along u₁ and 2√2 steps along u₂.
The figure compares before: q₁ and q₂ with after: u₁ and u₂. From here on, we’ll use u₁ and u₂ for the unit reference arrows.
Before: q₁, q₂. After: u₁, u₂. Each q arrow has length √2; each u arrow has length 1. The blue and orange arrows show the same full components in both panels. Only the reference steps and coefficients change: 1q₁ = √2u₁ and 2q₂ = 2√2u₂. Both drawings use the same scale.
Together, u₁ and u₂ form an orthonormal basis: the reference arrows are perpendicular to each other and each has length one.
Because these directions are perpendicular, projecting x onto either line recovers just the component along that line.
Each reference arrow is one unit long, so ignoring its sign, the coefficient gives the length of its component. A coefficient of 3 means three units along the reference arrow; −3 means three units in the opposite direction.
Squaring the coefficient gives the piece’s squared length. Since u₁ and u₂ are perpendicular unit arrows, we find each coefficient by taking a dot product:
Reference arrow
Coefficient
Squared length of the piece
u₁
c₁ = x · u₁ = √2
(√2)² = 2
u₂
c₂ = x · u₂ = 2√2
(2√2)² = 8
How the squared length is shared
Our split is x = (1, −1) + (2, 2). The pieces are perpendicular, so their squared lengths add: 2 + 8 = 10.
The first piece accounts for 2/10 = 20% of x’s squared length, and the second accounts for 8/10 = 80%. These percentages describe squared length. We’ll use these shares in Chapter 9 to compare input directions.
Why symmetry lets us choose perpendicular eigenvectors
M has matching entries across its main diagonal: the upper-right and lower-left entries are both 1. A matrix with this mirror property is called symmetric. Turning its rows into columns gives the same matrix, written Mᵀ = M.
M matches its reflection across the main diagonal. For a real symmetric matrix, the spectral theorem guarantees a basis of perpendicular unit eigenvectors.
The spectral theorem says that every real symmetric matrix has an orthonormal basis of eigenvectors, with real eigenvalues. We can choose enough perpendicular unit eigenvectors to describe every input.
For our two-dimensional example, this means we can write any input as:
x = c₁u₁ + c₂u₂
The coefficients c₁ and c₂ are numbers: they tell us how many steps to take along each unit arrow. The components c₁u₁ and c₂u₂ are the actual arrows that add up to x. Because u₁ and u₂ are perpendicular unit arrows, dot products give us the coefficients:
c₁ = x · u₁ c₂ = x · u₂
We’ll follow four steps for each input: find the coefficients, build the component arrows, scale each component by its eigenvalue, and add the outputs. Both examples use the same unit arrows, u₁ = (1, −1)/√2 and u₂ = (1, 1)/√2.
Example 1: x = (3, 1)
1. Find the coefficients. Dotting with u₁ subtracts the second coordinate from the first and divides by √2. Dotting with u₂ adds the coordinates and divides by √2:
Adding the pieces gives our input back: x = (1, −1) + (2, 2) = (3, 1).
3. Scale each component by its eigenvalue. M’s eigenvalues are 1 along u₁ and 3 along u₂. The first piece stays (1, −1); the second becomes 3 × (2, 2) = (6, 6).
4. Add the outputs. Together, the scaled pieces give Mx:
The figure shows this example. On the left, M acts on unit arrows. On the right, it applies the same eigenvalues to the complete pieces of x = (3, 1).
For M, scale each piece and add. The first piece stays the same; the second triples. Their sum is (7, 5). The left panel shows all unit inputs forming a circle and their outputs forming an ellipse. The whole arrow can turn because its two pieces grow by different amounts.
Example 2: x = (4, 2)
1. Find the coefficients. Use the same dot products with the new input:
In both examples, c₁ is √2. But c₂ changes from 2√2 to 3√2, so the second component changes from (2, 2) to (3, 3). The coefficients describe the input; the eigenvalues describe how M scales its pieces. The eigenvalues stay the same because we are using the same M.
Each eigenvector piece stays on its own line. The complete input can still turn. For a different symmetric matrix, a multiplier can also be negative, reversing a piece, or zero, removing it.
We’ll return to our original input x = (3, 1) for the rest of the primer.
Optional: what can go wrong without symmetry?
Consider A with rows (1, 1) and (0, 2). Its eigenvector lines, through (1, 0) and (1, 1), meet at 45° rather than 90°.
Not every matrix gives perpendicular eigenlines. Left: M's unit arrows u₁ and u₂ lie on eigenlines that meet at 90°. Right: the matrix A with rows (1, 1) and (0, 2) has eigenlines through (1, 0) and (1, 1), only 45° apart. Rotation by 90° is worse still: it knocks every arrow off its line, so it has no real eigenvectors at all.[14]
Perpendicular directions let us measure one piece at a time. When we project x onto the u₁ line, the u₂ piece contributes zero along that direction. So the projection gives us exactly the u₁ piece. The same works the other way around.
For A, the two complete pieces are (2, 0) and (1, 1). Add their coordinates to get the input: x = (2 + 1, 0 + 1) = (3, 1).
Projecting onto the horizontal line keeps only the horizontal part of each piece:
The first piece, (2, 0), is already horizontal, so it stays (2, 0).
The second piece, (1, 1), loses its upward movement but keeps its one unit to the right, becoming (1, 0).
Add these projections: (2, 0) + (1, 0) = (3, 0). The result includes a horizontal part from the second piece too. If the second piece were perpendicular to the horizontal line, its projection would be zero, leaving only the first piece, (2, 0).
Perpendicular pieces make two calculations easy. On the left, each projection finds the corresponding piece, and squared lengths add: 2 + 8 = 10. On the right, the reference lines are slanted. Projections no longer recover the pieces, and 4 + 2 is not the whole input's squared length, 10.
Perpendicular pieces also have squared lengths that add. This is Pythagoras’ rule: for M’s pieces, 2 + 8 = 10, the squared length of x. It is the squared lengths that add this way, rather than the ordinary distances.
For A’s pieces, the squared lengths are 4 and 2. Adding them gives 6, while x still has squared length 10. We need an extra term: twice the dot product of the pieces. Their dot product is (2, 0) · (1, 1) = 2, so the full calculation is 4 + 2 + 2 × 2 = 10. When pieces are perpendicular, their dot product is zero and that extra term disappears.
We can still use nonperpendicular eigenvectors to split an input and scale its pieces. We lose the two shortcuts: finding each piece directly by projection, and adding squared lengths without an extra term. Some matrices, such as a 90° rotation, do not even have real eigenvectors.
Optional: why eigenvectors with different eigenvalues are perpendicular for a symmetric matrix
Let v and w be eigenvectors of a real symmetric matrix M, with eigenvalues α and β. Symmetry lets us move M from one side of the dot product to the other: vᵀMw = (Mv)ᵀw. Substituting Mw = βw and Mv = αv gives β(v · w) = α(v · w). If α and β are different, this can hold only when v · w = 0. So the vectors are perpendicular. The full spectral theorem also guarantees enough eigenvectors to form a basis, including when eigenvalues repeat; within a repeated eigenvalue’s space we simply choose perpendicular ones.
Optional: resizing the reference arrows versus resizing the input
Normalize the references: replace q₁ and q₂ with their unit versions u₁ and u₂. The input stays fixed, and its coefficients change.
Normalize the input: resize x itself to length one. The reference steps stay fixed, and all of x’s pieces resize together.
Which thing shrank? Left: normalizing the references shortens the measuring sticks; x and its pieces stay put and the coefficients grow. Right: normalizing the input, as we did with x̂ in Chapter 4, shrinks x and both of its pieces together, by the same factor, while the sticks stay fixed.
For x, normalizing the input gives x̂ = (3, 1)/√10. Its two squared-length shares are still 20% and 80%.
9. Measure the output along the input’s direction
Chapter 8 showed how to find the whole output arrow. Now we want to compare directions: which input direction gives the most output along its own line, and which gives the least? This will give us another way to understand the largest and smallest eigenvalues.
To make that comparison fair, start with inputs of length one. Otherwise, a longer input could give more output simply because it was larger to begin with.
Use the dot product to measure along the input
We already know how to measure an arrow along a chosen direction: dot it with a unit arrow in that direction. Here, the arrow we measure is the output, and the unit reference is the input itself. Any sideways part contributes zero.
Our running input is x = (3, 1), with length √10. Divide it by √10 to get the unit input x̂. Its output shrinks by the same factor:
x̂ = (3, 1)/√10 Mx̂ = (7, 5)/√10
Now dot the unit input with its output:
x̂ · Mx̂ = 3 × 7 + 1 × 510 = 2.6
The output goes 2.6 units along the input’s direction. Its projection is the arrow 2.6x̂. The full output also has a sideways part, so 2.6 is not its full length.[15] The measurement is signed: a negative result would mean the projection points opposite to the input.
Same input length, different amounts of output along it. All three inputs have length one. Along u₁ the amount is 1, along x̂ it is 2.6, along u₂ it is 3. The mixed input's output has a sideways part; the eigenvector inputs' outputs don't.
For u₁, the amount along the input is 1. For u₂, it is 3. An eigenvector’s output stays entirely on its input line, so this measurement gives exactly its eigenvalue.
Why does our direction give 2.6?
We can also calculate this from the two eigenvector pieces. Along a unit eigenvector with eigenvalue λ, an input coefficient c becomes an output coefficient λc. Their contribution to the dot product is:
c × (λc) = λc²
That is why each eigenvalue multiplies a squared coefficient. The two eigenvector lines are perpendicular, and M keeps each piece on its own line, so we can add the two contributions without any extra terms.
In Chapter 8, the original x had coefficients √2 and 2√2. We have now divided x by √10, so both coefficients are divided by √10 too. The reference arrows u₁ and u₂ stay the same:
Reference
Coefficient in the unit input x̂
Squared coefficient
u₁
√2/√10 = 1/√5
1/5 = 20%
u₂
2√2/√10 = 2/√5
4/5 = 80%
Because x̂ has length one, these squared coefficients add to one. They are its shares of squared length. Multiply each share by its eigenvalue and add:
x̂ · Mx̂ = 1 × 20% + 3 × 80% = 2.6
This is a weighted average of the eigenvalues: 20% of the weight goes to 1, and 80% goes to 3.
The amount along a unit input stays between 1 and 3. Each bar shows the input's shares of squared length along u₁ and u₂. The dot shows the resulting measurement. The eigenvectors reach the two ends; the horizontal input (1, 0) has a 50/50 split and gives 2. Our unit input x̂ has an 80% share along u₂, putting its result at 2.6.
More share along u₁ moves the result toward 1; more along u₂ moves it toward 3. The shares cannot be negative and add to 100%, so the result always stays between 1 and 3. The eigenvector directions give the smallest and largest amounts along the input. We can find these limits without trying every possible direction.
A name for the calculation: quadratic form
The same input-output dot product can be calculated for an input of any length:
Q(x) = x · Mx = xᵀMx
This is called a quadratic form. Q is just its label. We will call its value the raw score, because it includes the effect of input size. Double the input and the output doubles too, so their dot product becomes four times as large.
For the original x = (3, 1), the raw score is:
Q(x) = 3 × 7 + 1 × 5 = 26
For its unit version, Q(x̂) = 2.6. Only when the input has length one does the raw score directly give the signed length of the output’s projection. Chapter 11 will show how to get that same fair comparison from an input of any size.
Optional: check the calculation at both sizes
For the unit input x̂, the two contributions are 1 × 0.2 = 0.2 and 3 × 0.8 = 2.4. Together they give 2.6:
Two pieces, two multipliers, one score. The u₁ piece of x̂ has squared length 0.2 and multiplier 1; the u₂ piece has squared length 0.8 and multiplier 3. Their input-times-output products, 0.2 and 2.4, add to 2.6. The coefficient labels are rounded to three decimal places.
For the original x, the squared coefficients are 2 and 8, adding to 10. Its raw score is 1 × 2 + 3 × 8 = 26:
Size and score use the same pieces differently. Squared length counts each squared coefficient once. The score gives the u₂ piece a multiplier of 3.
The output arrow, the raw score, and the output’s squared length are three different things:[16]
Calculation
Answer
What it measures
Mx
(7, 5)
The output arrow.
Q(x) = x · Mx
26
The dot product of input and output.
‖Mx‖²
74
The output’s squared length.
Written in ordinary coordinates, the quadratic form is Q(x) = 2x₁² + 2x₁x₂ + 2x₂². Each term multiplies two input entries, which explains the word “quadratic.”
We have seen that our matrix gives a positive result for every unit input. Could another matrix give zero, even when the input is not zero?
10. When a matrix sends an arrow to zero
For our matrix M, every unit input gives a measurement between 1 and 3. It can never give zero. A different matrix can give zero by removing an entire direction.
Keep the horizontal part, remove the vertical part
Let N keep the horizontal coordinate of an arrow and remove its vertical coordinate. This is projection onto the horizontal line:
N(a, b) = (a, 0)
Compare two inputs, both of length one:
Input
Output after N
Input · output
Horizontal: (1, 0)
(1, 0)
1
Vertical: (0, 1)
(0, 0)
0
N leaves the horizontal input unchanged. It sends the vertical input v = (0, 1) to zero, even though v has length one. The zero result tells us that N removes vertical movement. That direction has eigenvalue zero.
A length-one input gives zero. The vertical input v has length one, and its output Nv is the zero arrow. N removes all movement in this direction, so its eigenvalue is zero.
The measurement depends only on the horizontal part
For any input (a, b), the output is (a, 0). Their dot product is:
(a, b) · (a, 0) = a × a + b × 0 = a²
The raw score depends only on the horizontal coordinate a. Changing the vertical coordinate b makes no difference.
An entirely vertical arrow has a = 0, so it gives zero. Any arrow with a horizontal part gives a positive result. The result can never be negative, because it is a square.
N removes the vertical input (0, 1), giving zero output. With M, the same input has a positive score of 2.
Positive and nonnegative results
For real symmetric matrices, these properties have standard names:
Name
Input · output
Positive definite
Every nonzero input gives a positive result.
Positive semidefinite
Every input gives a result that is zero or positive.
M is positive definite. N is positive semidefinite: its results are never negative, and vertical inputs give zero. Every positive definite matrix also counts as positive semidefinite, since a positive result is never negative.[17]
The eigenvalues give a quick test. All positive means positive definite; all zero or positive means positive semidefinite. M has eigenvalues 1 and 3. N has eigenvalue 1 along the horizontal line and 0 along the vertical line.
Find the directions the matrix sends to zero
If we look for N’s smallest measurement among unit inputs, a vertical input gives zero. We have found a direction N removes.
To study what N keeps, remove the vertical component first. Then compare the remaining nonzero horizontal arrows at length one. They all give 1, because N leaves them unchanged.[18]
Optional: does a zero score always mean zero output?
For a positive semidefinite matrix, yes. Each eigenvector piece contributes its eigenvalue times its squared coefficient. All contributions are zero or positive, so a total of zero means every contribution is zero. Every nonzero piece must lie along an eigenvector with eigenvalue zero, and the matrix sends all those pieces to zero.
For a symmetric matrix with both positive and negative eigenvalues, contributions can cancel, giving a zero score even when the output is nonzero.[19] In that case, the output is perpendicular to the input, so their dot product is zero.
11. Compare directions regardless of length
In Chapter 9, we resized each input to length one before comparing directions. We can get the same measurement directly from the original input, using one division.
One direction, two lengths
Our input x = (3, 1) has raw score 26. Half of x is x/2 = (1.5, 0.5), with raw score 6.5. The shorter arrow points in exactly the same direction, but its raw score is smaller.
Now divide each raw score by the input’s squared length:
Input
Raw score
Squared length
After dividing
x
26
10
2.6
x/2
6.5
2.5
2.6
Both give 2.6. Dividing by squared length removes the effect of input size, so the two arrows get the same result.
Resizing can't change the ratio. Both arrows point in the running example's direction. Their raw scores differ only because their sizes differ, and dividing by squared length removes exactly that.
Why divide by squared length?
Normalizing an input divides it by its length. Its output is divided by the same amount. The dot product multiplies entries from both arrows, so the result is divided by length twice—once for the input and once for the output. Together, those two factors give ‖x‖ × ‖x‖ = ‖x‖².
We can therefore calculate the measurement for a unit input without actually resizing the arrow:
R(x) = Q(x)‖x‖²
Dividing the raw score by the input’s squared length gives the Rayleigh quotient.[20] For our example, R(x) = 26/10 = 2.6.
R(x) is the measurement that the same direction would have at length one. This is the same result we found in Chapter 9 for x̂. The input must be nonzero, because we cannot divide by a squared length of zero.
Turn the input and compare the results
Call the unit input in the next picture v. Since its squared length is 1, R(v) = Q(v). It starts at v = x̂, our running direction.
Click “Along u₁”, then “Along u₂.” The quotient changes from 1 to 3. Now choose “Along x̂”: it gives 2.6. Use the slider to explore other directions.
Rayleigh quotient R(v): 2.6
20% of squared length along u₁; 80% along u₂.
Use the buttons to compare u₁, u₂, and x̂. Move the slider to try other directions; the angle is measured from the positive horizontal axis.
Every direction gets the same input length. The first view shows input v, output Mv, and the blue projection R(v)v. The second splits v into its eigenvector pieces. The bottom chart plots R(v) for every direction; the dot marks the current input.
The blue arrow, R(v)v, is the output’s projection onto the input line. For any nonzero input x, the same rule gives the projection R(x)x. The full output can also have a sideways part, so R(x) is generally different from the ratio of the full output length to the input length.[21] At an eigenvector, the sideways part disappears.
What changes when you turn?
Chapter 9 showed that the measurement is a weighted average of the eigenvalues. Our original x and its unit version x̂ both have 20% of their squared length along u₁ and 80% along u₂:
R(x) = 0.2 × 1 + 0.8 × 3 = 2.6
Resizing an arrow scales both pieces together, keeping those shares unchanged. Turning it can change the shares. Resizing leaves the quotient unchanged; turning can change it.
The experiment suggests where the smallest and largest quotients occur. Next, we will use the weighted-average rule to prove that the eigenvector directions reach both limits.
12. Use eigenvalues to find the minimum and maximum
Chapter 11 gave us a number for each direction. Now we want to find the smallest and largest possible values. For an input of length one, these tell us the least and most output along the input’s own direction.
Our running direction gives 2.6. That is one possible value; it does not tell us where the limits are.
Why every quotient stays between 1 and 3
For our symmetric matrix M, the quotient is a weighted average of the eigenvalues 1 and 3. The weight on each eigenvalue is the share of the input’s squared length along its eigenvector. These shares cannot be negative and add to 100%.
Putting all the weight on 1 gives an average of 1. Moving any of that weight to 3 raises the average. Even when all the weight is on 3, the result is only 3. So every nonzero input has a quotient between 1 and 3, including the two ends.
The eigenvectors reach both limits
We can put all the weight on 1 by choosing u₁ as the input. It has no u₂ piece. Likewise, choosing u₂ puts all the weight on 3.
Compare these two unit inputs with our running unit input x̂. The shares below are percentages of squared length:
Unit input
u₁ share
u₂ share
Quotient
u₁
100%
0%
1
x̂
20%
80%
2.6
u₂
0%
100%
3
This proves both limits: no direction gives less than 1, and u₁ gives exactly 1; no direction gives more than 3, and u₂ gives exactly 3. Finding a minimum takes both parts: show that nothing can go lower, then find an input that reaches that value.
The eigenvector directions reach both limits. The u₁ line gives 1 and the u₂ line gives 3. Every other direction gives a value between them.
Resizing or reversing an arrow leaves its quotient unchanged. Every nonzero arrow on the u₁ line therefore gives the minimum, and every nonzero arrow on the u₂ line gives the maximum. In the chart, 135° points along −u₁, which is on the same line as u₁.
The same rule works in more dimensions
For any real symmetric matrix, every nonzero input’s quotient is a weighted average of its eigenvalues. The same argument works however many entries the input has:
The smallest eigenvalue is the minimum quotient. An eigenvector with that eigenvalue reaches it.
The largest eigenvalue is the maximum quotient. An eigenvector with that eigenvalue reaches it.[22]
This gives us a way to find the minimum without checking every direction: find the smallest eigenvalue and an eigenvector that goes with it. The eigenvalue tells us the minimum value; the eigenvector tells us an input direction that achieves it. Spielman, Chapter 2.
What we learned
We started with arrows and a matrix that transforms them. By finding useful reference directions, we learned to break that transformation into simpler pieces. For a real symmetric matrix, we can choose perpendicular eigenvectors: each piece stays on its own line, and its eigenvalue tells us how the matrix scales it.
That same picture helped us compare input directions. After removing the effect of input length, the measurement becomes a weighted average of the eigenvalues. Its smallest and largest values are therefore the smallest and largest eigenvalues, and their eigenvectors tell us which directions reach those limits.
These ideas extend beyond arrows on a plane. In the spectral graph theory primer, a vector will assign values to nodes, and a matrix will describe their connections. The same tools will help us find bottlenecks and understand how well a network holds together.
Unlike most directions you get from relatives, these work no matter where you start.↩
William Rowan Hamilton gave “scalar” and “vector” their mathematical meanings in the mid-1840s, while developing his quaternions. Real numbers, he explained, sit on a single scale running from negative to positive infinity. “Vector” comes from the Latin for “carrier.”↩
This is why the rule “add 1 to every entry” isn't linear in this sense, even though in one dimension f(x) = x + 1 draws a perfectly straight line. It moves the origin. That kind of rule is called affine, and someone will point this out if you get it wrong.↩
For two nonzero arrows in the plane, “orthogonal” and “perpendicular” mean the same thing. “Orthogonal” also works in more dimensions, and for things like functions, where “perpendicular” starts to sound odd. Technically the zero vector is orthogonal to everything, which is about as meaningful as it sounds.↩
√10 ≈ 3.162 is close enough to π that Zhang Heng in 2nd-century China and Brahmagupta in 7th-century India both used it as a value for π. We are not doing that here.↩
The zero vector can't be normalized: its length is zero, and dividing by zero remains, as ever, not allowed.↩
Without the right angle there would be an extra cross term: ‖p + r‖² = ‖p‖² + 2 p · r + ‖r‖². Here p · r = 0, so it vanishes.↩
The wobble in the hand-drawn grid is drawn on the plane itself, so M transforms the wobbles along with everything else. That's what a linear map does to any drawing you make on the plane. (The arrow tips sit exactly where the math says, though.)↩
“Eigen” is German for “own,” as in “the matrix's own vectors.” English borrowed half the word and never gave it back.↩
Flipping still counts as staying on the line. The arrow is on the same line through the origin, just facing the other way down the hallway.↩
Keep applying M and almost every arrow swings closer and closer to the q₂ line, because each application triples the q₂ component and leaves the q₁ component alone. Repeating a matrix to find its dominant eigenvector is called the power method; Google's original PageRank was computed this way. (The “almost”: arrows exactly on the q₁ line have no q₂ component to triple, so they stay put.)↩
David Hilbert made “spectrum” the standard word in the early 1900s (Wilhelm Wirtinger had borrowed it from optics a few years before). A couple of decades later, quantum mechanics showed that the lines in atomic spectra really are computed from eigenvalues. Hilbert reportedly said he'd used the name with no idea it would apply to the actual spectra of physics. The word went from optics to math and straight back again.↩
Of which there are a lot. Uncountably many, in fact.↩
Rotation by 180° is sneakier: it flips every arrow, which counts as staying on the line, so every nonzero arrow is an eigenvector with eigenvalue −1.↩
Remember the job interview in Chapter 6? x started explaining that it turns a little, and M said “Next!” The chart there says how little: about 17°. That turn is the sideways part in the picture.↩
One input, three different answers. Linear algebra is like this sometimes.↩
Positive semidefinite is the matrix version of “no complaints.” Not necessarily any compliments. Just no complaints.↩
An almost-vertical unit input can have a score as close to zero as we like. Removing the vertical component restricts the comparison to the perpendicular, horizontal direction.↩
Without nonnegativity, a zero can be a coincidence. The matrix with rows (1, 0) and (0, −1) gives (1, 1) a score of 1 − 1 = 0, yet sends it to (1, −1), not to zero.↩
Named after Lord Rayleigh, who also explained why the sky is blue and shared in the discovery of argon, which won him the 1904 Nobel Prize in Physics. He was having a good few decades.↩
For our x, ‖Mx‖/‖x‖ = √74/√10 ≈ 2.72, which is bigger than R(x) = 2.6. The sideways remainder adds length without adding anything along x.↩
Mathematicians call this the variational characterization of eigenvalues: “variational” because it comes from varying the direction and looking for the lowest and highest values. Physics is full of these. A soap film settles into a shape that (locally) minimizes its area, and light follows a path whose travel time is stationary, which is usually a minimum.↩