Units 1–2 gave us arrows and spaces, but nothing had a size yet. This unit hands you a ruler and a protractor: how long, how far, and "are these two pointing the same way?" Then the twist: you get to design your own ruler. Much of machine learning is exactly that: choosing the right way to measure "similar".
≈ 50 min read + play10 interactive widgets · 9 in 3D13 inline checks8 step-by-step derivations✍ 8 solved practice problems
drag the space to orbit
1
The quest for "similar"
Imagine this
You finish a film on Netflix. Two seconds later it says: "Because you watched this, try…". How does it choose?
Behind the screen, you are a list of numbers: how much you like action, romance, comedy, and so on. Every film is a list of numbers too. The app looks for films whose list is close to yours. Spotify does the same with songs. Google does it with web pages. ChatGPT does it with the meaning of words.
So everything rests on one small question: what does "close" actually mean?
At school, "close" meant one thing: put a ruler between the two points and read the distance. That works. But it is only one way to measure.
Think of choosing a film. Maybe the director matters to you far more than the running time. Then a good "closeness" score should care more about the director and less about the running time. That is a different ruler. It is not wrong. It just measures what you care about.
This unit teaches you how to build your own rulers, and how to make sure they never break. Here is the path, one step at a time:
①Length — what rules must any "length" follow? (norms)
②The dot product — one number that tells you if two lists agree.
③Your own ruler — the recipe for making new ones (inner products and the matrices behind them).
④Distance and angle — "how far apart?" and "pointing the same way?"
⑤Perfect grids — how to turn any set of directions into clean, square ones (Gram–Schmidt).
In one sentence: machine learning keeps asking "how similar are these two things?", and this unit is about the rulers that answer it.
2
Norms — what "length" is allowed to mean
Imagine this
You stand at a street corner. Your friend is 3 blocks east and 4 blocks north. How far away is she?
A crow flies straight over the buildings: 5 blocks. A taxi has to follow the streets, 3 blocks and then 4 blocks: 7 blocks.
Who is right? Both. They just measure "far" in different ways.
So "length" is not one fixed thing. It is a choice of rule. Mathematicians call such a rule a norm, and they write the length of an arrow x as ∥x∥ (read it: "the length of x").
You can invent any rule you like. But it must keep three common-sense promises, or it is not really a length:
The promise
In everyday words
In symbols
Scaling
Walk twice as far, and the length doubles. Walking backwards is still the same distance.
∥λx∥=∣λ∣∥x∥
No shortcut
A detour is never shorter than going straight.
∥x+y∥≤∥x∥+∥y∥
Only "nowhere" is zero
Lengths are never negative. Only staying put has length 0.
∥x∥≥0, and =0 only for x=0
The two rules from our story, written out. For the point (3,4):
∥x∥1=∣x1∣+∣x2∣+⋯ taxi: add up the blocks · 3+4=7
∥x∥2=x12+x22+⋯ crow: Pythagoras · 9+16=5
Each rule has a "fingerprint": the shape made by all the points at length exactly 1. We call it the unit ball. For the crow it is a round circle (a sphere in 3D). For the taxi it is a diamond. Why a diamond? Because for a taxi, one block east costs the same as one block north, so the points with "1 block total" form a tilted square.
Two rulers, one citythe crow flies ℓ₂ · the taxi drives ℓ₁ · drag to orbit
Try: drag x onto an axis and watch the two rulers agree; then switch on "zoom to unit balls" to see the circle-vs-diamond fingerprint up close.
drag the picture to orbit
‖x‖₂ (crow) = 5‖x‖₁ (taxi) = 7
—
The dashed shapes are each norm's unit ball — everything of length 1. The crow's is a circle; the taxi's is a diamond, because trading x-blocks for y-blocks costs the same. The shape of the unit ball is the norm's fingerprint — in Section 5 we bend the circle into an ellipse.
The realization
A norm is just a rule for measuring length. Different rules give different shapes of "all points at distance 1": a circle for the crow, a diamond for the taxi. When a machine-learning model measures error or closeness, it has quietly picked one of these rules, and the pick changes the answer.
Pause & predict
A new rule: "the length of x = how many of its numbers are not zero." So (5,0,2) has length 2. Is this a real length (a norm)?
Pause & predict
A taxi drives from the corner to the point (3,4) on a perfect street grid. How far does the meter run, and how far did the crow fly?
In one sentence: a norm is any rule for length that scales properly, allows no shortcuts, and gives zero only to "nowhere".
3
The dot product — one number that reads two vectors
Imagine this
You and a friend rate four films from −2 (hated it) to +2 (loved it). Do you have the same taste?
Here is a quick test. For each film, multiply your rating by your friend's rating. Then add the four answers.
😀You both loved it, or you both hated it → the product is positive. Agreement adds points.
😠One loved it, one hated it → the product is negative. A clash takes points away.
😐One of you didn't care (0) → the product is 0. That film doesn't count.
Big positive total: same taste. Big negative total: opposite taste. Near zero: your tastes are unrelated.
That score has a name: the dot product. You just invented it. For two lists x and y it is
x⋅y=xTy=x1y1+x2y2+⋯+xnyn
Pair up, multiply, add. (The xTy form is Unit 1's "row times column", giving one number.) One example, slowly. Take x=(1,2,−1) and y=(3,−1,2):
One agreement, two clashes. The total is a little below zero, so these two lean slightly away from each other.
The agreement scaletwo friends · four movies · one balance scale
Try: press ▶ and watch each movie drop its weights. Then drag one friend's rating and see the scale tip. Can you make it balance at exactly 0?
drag the picture to orbit
Your ratings are fixed. Drag your friend's ratings. Same sign = agree (green cubes). Opposite signs = clash (orange cubes).
score xᵀy = —direction match cos ω = —
—
Aha — the ruler was hiding inside
Now compare a list with itself: xTx=x12+x22+⋯. That is exactly the crow's length, squared! For (3,4): 9+16=25=52.
So length is just "how much you agree with yourself." This tiny fact is the key to the whole unit. Whoever decides how two lists are multiplied also decides what "length" means. Change the multiplication, and you get a new geometry.
There is also a picture behind the score. For two arrows with an angle ω between them:
xTy=∥x∥∥y∥cosω
Read it like this. Pointing the same general way (angle below 90°): positive. At a perfect right angle: exactly zero, because the agreements and the clashes cancel. Pointing opposite ways: negative. So the "rating game" number and the angle are one and the same thing. Sections 6 and 7 show why this is always allowed.
The realization
xTy=i∑xiyi
The dot product is an agreement score. Every "people like you also watched…" system is built on this one line of arithmetic.
Pause & predict
Compute (2,−1,3)⋅(1,4,−2). Would a film app say these two people have the same taste?
In one sentence: multiply matching entries and add them up; the total says how much two lists agree, and a list's agreement with itself is its length squared.
4
Inner products — the blueprint under the dot product
Imagine this
A chef tastes a great dish and asks: "What makes this work? Salt, acid, heat." Once she knows the three things that matter, she can cook new dishes that also work.
We will do the same with the dot product. What makes it such a good agreement score? Find the key ingredients. Then we can cook up new scores that work just as well.
It turns out only three ingredients matter. Call our score ⟨x,y⟩ (read it: "the score of x with y").
①Fair with sums and scaling. Double one list, and the score doubles. Split a list into two parts, and the score splits too. Why we need it: it lets us do ordinary algebra with the score. (The formal name is bilinear: ⟨λx+ψy,z⟩=λ⟨x,z⟩+ψ⟨y,z⟩, and the same for the second slot.)
②Same both ways. How much you agree with me equals how much I agree with you: ⟨x,y⟩=⟨y,x⟩. (Name: symmetric.)
③Agreeing with yourself is always positive.⟨x,x⟩>0 for every list that is not all zeros. Why we need it: this number is about to become "length squared", and a length squared can't be negative. (Name: positive definite.)
The realization
Any score with these three ingredients is called an inner product. The dot product is just the most famous one. Every inner product gives you its own length, its own distance and its own angle, and they all behave sensibly. The natural next question: how do we cook up new ones? (Next section.)
Pause & predict
Try this score on 2-number lists: ⟨x,y⟩=x1y1−x2y2 (the second pair counts negative). It is fair with sums and the same both ways. Which ingredient does it break?
In one sentence: an inner product is any agreement score that is fair with sums, the same both ways, and always positive for a list with itself.
5
The engine room — symmetric positive-definite matrices
Imagine this
A mixing desk in a music studio has a slider for each channel. Push the bass slider up and the bass counts for more in the final sound.
A matrix can be a mixing desk for our agreement score. It decides how much each direction counts, and even how directions mix together.
Here is the trick. The ordinary dot product secretly has a matrix inside it, the identity I (all sliders at 1):
x⋅y=xTIy
Now swap I for another matrix A. You get a new score:
⟨x,y⟩A=xTAy
Example: A=(2001) gives ⟨x,y⟩A=2x1y1+x2y2. The first direction now counts double.
Does every matrix give a good score? No. It needs the two properties from the last section, turned into matrix language:
②Symmetric:A=AT (the matrix is its own mirror image across the diagonal). This gives "same both ways".
③Positive definite:xTAx>0 for every non-zero x. This gives "lengths are positive".
Such a matrix is called SPD (symmetric positive-definite). The big fact from the slides: every inner product on Rn is xTAy for some SPD matrix A, and every SPD matrix gives one. So "design a ruler" means "pick an SPD matrix".
Two quick facts follow straight away:
•The diagonal is positive. Test the first direction e1=(1,0,…) against itself: e1TAe1=A11. That is a length squared, so A11>0. Same for every diagonal entry.
•A can be undone (it is invertible). If Ax=0 for some non-zero x, then xTAx=0, which is not allowed. So no non-zero arrow is squashed to zero.
What does the matrix do to the picture? Watch the fingerprint, the shape of "all points at length 1", as you change A:
The geometry lensone space, many rulers — the unit ball is the fingerprint · drag to orbit
Try: press diag(2, 1) and read the expansion of xᵀAy below the matrix — then type a₁₂ = 1.5 with a₁₁ = a₂₂ = 1 and watch the SPD test fail the moment det ≤ 0.
drag the picture to orbit
A =a₂₁ mirrors a₁₂ (symmetry, enforced)
det = 1SPD ✓
—
The test vectors are the slides' pair x=(1,1), y=(−1,1); the faint grey circle is the ordinary Euclidean unit ball, kept for comparison. Under I the pair is orthogonal; under diag(2, 1) their inner product becomes −1 and cosω=−31 — orthogonality is a property of the ruler, not just the vectors. The broken engine shows why SPD is non-negotiable: some directions get a negative "squared length", and the unit ball tears open into a hyperbola.
The realization
The matrix Areshapes the unit ball. The identity gives a round ball. A diagonal A squashes it into an egg along the axes. Off-diagonal numbers tilt the egg. A matrix that is not positive-definite tears the ball open, because some arrows would get a negative length squared.
Pause & predict
Why must every number on the diagonal of a positive-definite matrix be positive?
How do you test a matrix for SPD?
"Positive for every arrow" sounds like infinitely many checks. For a 2×2 symmetric matrix (abbd) it boils down to two quick checks:
1the top-left number is positive: a>0;
2the determinant is positive: ad−b2>0.
Example: (2112): 2>0 and 4−1=3>0. SPD ✓. And (1221): 1>0 but 1−4=−3. Not SPD ✗. For bigger matrices, check every top-left square block ("leading minor"). The drawer shows where this comes from: the school trick of completing the square.
If you want the algebra · the 2×2 test, and a 3×3 worked example
Prove it · the 2×2 SPD test (Sylvester's criterion) — derived
Claim. A symmetric A=(abbd) is positive-definite iffa>0 and ad−b2>0 (the two leading minors are positive).
1
Write out the quadratic form for x=(x1,x2):
xTAx=ax12+2bx1x2+dx22Multiply the sandwich out: the two off-diagonal b's give the same cross term bx1x2 twice.
2
Test the first axis. Put x=(1,0): the form equals a. So positive-definiteness forcesa>0.
One well-chosen test vector settles the sign of a. From now on we may divide by a.
3
Complete the square in x1:
ax12+2bx1x2+dx22=a(x1+abx2)2+(d−ab2)x22Expand the right side to check: a(x1+abx2)2=ax12+2bx1x2+ab2x22; the extra ab2x22 is cancelled by the second bracket. Nothing lost, nothing added.
4
Read the sign. The first term is a⋅(square)≥0. If d−ab2>0, both terms are ≥0 and they vanish together only when x2=0andx1+abx2=0, i.e. x1=0. So the form is >0 for every x=0.
A weighted sum of squares with positive weights is positive unless every square is zero — and that only happens at the zero vector.
5
Conversely, if d−ab2≤0, the vector x=(−ab,1) kills the first square and leaves xTAx=d−ab2≤0: not positive-definite. Multiply the condition by a>0: d−ab2>0⟺ad−b2>0. So SPD ⟺a>0 and detA>0. ∎The witness vector in step 5 is exactly how the practice problems "exhibit a vector with negative squared length". The same completing-the-square idea, repeated column by column, gives the n×n version: all leading minors positive.
Worked example · a 3×3 matrix, proved SPD by completing the square (the by-hand technique)
Take A=2−10−12−10−12. Multiply out the form and complete squares left to right, one variable at a time:
Three squares with positive weights 2,23,34: the form is >0 unless x3=0, then x2=0, then x1=0. So A is SPD. Cross-check with Sylvester: the leading minors are 2,3,4 — all positive — and the three weights are their ratios 2,3/2,4/3. Completing the square and the minors test are the same computation in two costumes.
Pause & predict
Is M=(1221) positive-definite? (It is symmetric, and its diagonal is positive.)
In one sentence: to design a ruler, pick a symmetric matrix that gives every non-zero arrow a positive length squared, and test it with the top-left number and the determinant.
6
Lengths, distances — and the inequality that runs everything
Every inner product comes with a free ruler and a free tape measure:
📏Length: agree with yourself, then take the square root: ∥x∥=⟨x,x⟩.
📍Distance between two points: the length of the gap between them, d(x,y)=∥x−y∥.
With the ordinary dot product these are the usual length and distance from school. Any sensible distance (a metric) keeps four promises: it is never negative; it is zero only from a point to itself; A to B equals B to A; and a stop along the way never makes a trip shorter.
Distance and agreement are linked
Expand the distance and the agreement score pops out:
∥x−y∥2=∥x∥2+∥y∥2−2⟨x,y⟩
Keep the two lengths fixed. Then more agreement means less distance. Every point the score goes up, the squared distance goes down by two. So "find the nearest" and "find the most similar" are really the same search. Just don't mix the two up in the middle of a formula: one goes up when the other goes down.
One warning: it doesn't work the other way round. Every inner product gives a length, but not every length comes from an inner product. The taxi's length does not. The picture shows the tell-tale sign.
The tell-tale sign. Take x=(1,0) and y=(0,1) and look at the two diagonals of the square they make. A length that comes from an inner product always passes the parallelogram rule: ∥x+y∥2+∥x−y∥2=2(∥x∥2+∥y∥2). The crow passes: 2+2=4 ✓. The taxi fails: each diagonal costs 2 blocks, so 4+4=8=4 ✗. No inner product can make the diamond.
Imagine this
At noon the sun is straight overhead. You hold a stick at a slant. Its shadow on the ground is never longer than the stick. It matches the stick only when you lay the stick flat.
That everyday fact is the most useful inequality in this unit. It is called Cauchy–Schwarz:
∣⟨x,y⟩∣≤∥x∥∥y∥
In words: the agreement score can never be bigger than the two lengths multiplied. Why is this the shadow fact? The score is ∥x∥ times the shadow of y on x's line. The shadow is never longer than y itself. So the score is never more than ∥x∥∥y∥. The two sides are equal only when the stick lies flat, that is, when y points exactly along x (or exactly opposite).
The shadow can never beat the stickwhy |⟨x,y⟩| ≤ ‖x‖‖y‖
Try: drag the angle. The stick's shadow on the road grows and shrinks, but it can never be longer than the stick — so the score can never pass the ceiling.
drag the picture to orbit
⟨x,y⟩ = —‖x‖‖y‖ = 6.00
—
Sun straight overhead. The shadow of a leaning stick is always shorter than the stick. That is the whole inequality.
The realization
∣⟨x,y⟩∣≤∥x∥∥y∥and∥x+y∥≤∥x∥+∥y∥
A shadow never beats the stick, and a detour never beats the straight road. The first fact makes angles possible (next section). The second fact makes sure every inner product gives a proper length.
If you want the algebra · 3 proofs, step by step
Prove it · distance and inner product are wired together — derived
Claim.∥x−y∥2=∥x∥2+∥y∥2−2⟨x,y⟩ in every inner-product space.
1
Start from the definition of the induced norm, applied to the difference:
∥x−y∥2=⟨x−y,x−y⟩Squared length is the inner product of a vector with itself — no step yet, just the definition.
2
Open the left slot with bilinearity, then the right slot:
=⟨x,x⟩−⟨x,y⟩−⟨y,x⟩+⟨y,y⟩Linearity in each argument lets the minus signs and the sums pass through, exactly like multiplying out (p−q)(p−q).
3
Use symmetry to merge the two middle terms, and the definition of the norm on the outer two:
∥x−y∥2=∥x∥2+∥y∥2−2⟨x,y⟩.∎⟨y,x⟩=⟨x,y⟩ by axiom ②. So what: with the lengths fixed, distance goes down exactly as the inner product goes up — the two gauges are one equation.
Prove it · Cauchy–Schwarz — derived from one clever vector
Claim. For any u,v in an inner-product space, ⟨u,v⟩2≤⟨u,u⟩⟨v,v⟩, i.e. ∣⟨u,v⟩∣≤∥u∥∥v∥.
1
If v=0 both sides are 0 and there is nothing to prove. So assume v=0, which gives ⟨v,v⟩>0.
Positive definiteness (axiom ③) is what lets us divide by ⟨v,v⟩ later.
2
For any number α, the vector u−αv has a squared length, and squared lengths are never negative:
0≤⟨u−αv,u−αv⟩Axiom ③ again — this single inequality is the entire input; the rest is algebra.
3
Multiply out with bilinearity and symmetry (the same expansion as the identity above):
0≤⟨u,u⟩−2α⟨u,v⟩+α2⟨v,v⟩A quadratic in α that is never negative — for every choice of α, including the smartest one.
4
Choose α=⟨v,v⟩⟨u,v⟩ (the shadow coefficient of Section 11) and substitute:
0≤⟨u,u⟩−2⟨v,v⟩⟨u,v⟩2+⟨v,v⟩⟨u,v⟩2=⟨u,u⟩−⟨v,v⟩⟨u,v⟩2Check the middle term: 2α⟨u,v⟩=2⟨u,v⟩2/⟨v,v⟩; and α2⟨v,v⟩=⟨u,v⟩2/⟨v,v⟩. Two of the same thing minus one leaves minus one.
5
Multiply through by ⟨v,v⟩>0 and rearrange:
⟨u,v⟩2≤⟨u,u⟩⟨v,v⟩; take square roots: ∣⟨u,v⟩∣≤∥u∥∥v∥. ∎Equality holds exactly when step 2 was an equality, i.e. u−αv=0: u is a multiple of v. Nothing used the dot product specifically — the proof runs verbatim for every inner product, which is why Problem 8 can "verify" it under a weighted ruler.
Prove it · the triangle inequality follows from Cauchy–Schwarz — derived
Claim.∥x+y∥≤∥x∥+∥y∥ for the norm induced by any inner product — so every inner product really does produce a norm (and a metric).
1
Expand the squared length of the sum (same identity as before, with a plus sign):
∥x+y∥2=∥x∥2+2⟨x,y⟩+∥y∥2Bilinearity opens both slots; symmetry merges the two cross terms into 2⟨x,y⟩.
2
Bound the cross term with Cauchy–Schwarz, ⟨x,y⟩≤∣⟨x,y⟩∣≤∥x∥∥y∥:
∥x+y∥2≤∥x∥2+2∥x∥∥y∥+∥y∥2=(∥x∥+∥y∥)2Replacing a term by something at least as large can only make the right side bigger; the result is a perfect square.
3
Both sides are non-negative, so taking square roots keeps the inequality: ∥x+y∥≤∥x∥+∥y∥. ∎For distances, apply this to x−y=(x−z)+(z−y) and promise ④ of a metric drops out.
Pause & predict
Why do we need Cauchy–Schwarz before we can talk about "the angle between x and y"?
Pause & predict
When is the shadow exactly as long as the stick, so ∣⟨x,y⟩∣=∥x∥∥y∥?
In one sentence: length and distance come free with every inner product, and the score can never beat the product of the lengths, just as a shadow can never beat the stick.
7
Angles — the similarity dial
Imagine this
Two people type into a search box. One types "cheap flights to Goa". The other writes a long paragraph about cheap flights to Goa. Their word counts are very different. Their topic is the same.
We want a score that ignores how much someone says and looks only at which way they point. That score is the angle.
Divide the agreement score by the two lengths. Cauchy–Schwarz promises the answer lies between −1 and +1, so it is the cosine of exactly one angle ω between 0° and 180°:
cosω=∥x∥∥y∥⟨x,y⟩
This is cosine similarity, machine learning's favourite similarity dial:
+1pointing the same way (angle 0°);
0unrelated, at a right angle (90°). We say the two arrows are orthogonal and write x⊥y. This happens exactly when ⟨x,y⟩=0;
−1pointing opposite ways (180°).
Stretching an arrow does not change where it points, so it does not change the cosine. The short query and the long paragraph get a cosine near +1.
The similarity dialtwo arrows on a protractor · the shadow is the score
Try: move only a length slider. The beads on the unit ring do not move, and cos ω does not change. Then press ▶ and watch y swing a full turn.
drag the picture to orbit
⟨x,y⟩ = —angle ω = —distance d(x,y) = —
—
cos ω is the shadow of y's bead on x's line: +1 same way, 0 perpendicular, −1 opposite. Lengths never change it — only directions do.
The realization
cosω is the shadow of a length-1 arrow. Shrink both arrows to length 1, then drop the shadow of one onto the other: its length is cosω. Full shadow: same direction. No shadow: right angle. Negative shadow: opposite. Length never enters. Only direction does.
If you want the algebra · why there is always exactly one angle
Prove it · why the angle is well-defined — derived
Claim. For non-zero x,y there is exactly one ω∈[0,π] with cosω=∥x∥∥y∥⟨x,y⟩.
1
Divide Cauchy–Schwarz, ∣⟨x,y⟩∣≤∥x∥∥y∥, by the positive number ∥x∥∥y∥:
−1≤∥x∥∥y∥⟨x,y⟩≤1Both vectors are non-zero, so both norms are >0 (axiom ③) and dividing keeps the inequality's direction.
2
On [0,π], cosine decreases strictly from 1 to −1 and takes every value in between exactly once. So the ratio in step 1 is cosω for one and only oneω∈[0,π]: ω=arccos(⟨x,y⟩/∥x∥∥y∥). ∎Without step 1 the formula could ask for arccos(1.7), which does not exist. Cauchy–Schwarz is the licence for the protractor.
Pause & predict
Two word-embedding arrows move closer and closer together. What happens to the distance and to the agreement score?
In one sentence: cosine similarity is the agreement score with the lengths divided out, so it measures direction only: +1 same, 0 unrelated, −1 opposite.
8
The high-dimension miracle
Imagine this
Two strangers each answer 1000 yes/no questions completely at random. How much will their answers agree?
On a few questions they will match by luck. On a few they will clash. Over 1000 questions the lucky matches and clashes almost perfectly cancel out. Their agreement score ends up very close to zero.
The slides end one page with a dare: "Pick two random arrows in high dimensions. What happens to the angle between them? Write a small program to see."
The program is below. It picks 300 random pairs of arrows (each number drawn at random), works out the cosine of each pair, and piles the answers into a bar chart. Drag the number of dimensions n and watch.
The slides' dare, run livecos ω for 300 random pairs in ℝⁿ
Try: press ▶ and watch the pile squeeze into a needle at 0. At every stop, compare the measured spread with the predicted 1/√n.
measured spread (std of cos ω) = —predicted 1/√n = —
—
Pick two random arrows. In 2 dimensions any angle is common. In 1000 dimensions they are almost always nearly perpendicular — cos ω lands within about 1/√n of 0, so there is a huge amount of "perpendicular room" for unrelated things.
The realization
In 2D, two random arrows can point any which way. In 1000D, two random arrows are almost always at almost exactly 90°. The spread of the cosine shrinks like 1/n: about 0.03 when n=1000.
Why this matters: a 1000-number embedding space has room for millions of ideas that barely get in each other's way. It also means a cosine of 0.3 between two real embeddings is huge. Random chance would give about 0.
Pause & predict
You pick two random arrows with 1000 numbers each. The angle between them is almost certainly…
In one sentence: in many dimensions, random arrows are almost always at right angles, so real similarity stands out clearly.
9
Orthogonality is in the eye of the ruler
Imagine this
Draw a perfect square corner on a rubber sheet. Now stretch the sheet sideways. The corner is no longer square. It has opened up.
Nothing was redrawn. You only changed the sheet, that is, the way distances are measured. The same thing happens when you change the ruler.
Take x=(1,1) and y=(−1,1). With the ordinary dot product, (1)(−1)+(1)(1)=0. They are at a perfect right angle.
Now use the ruler A=(2001), which counts the first direction double. Predict first:
Pause & predict
x=(1,1) and y=(−1,1) are at a right angle under the dot product. Under the ruler A=diag(2,1), they are…
So the angle is about 109.5∘. The arrows did not move. Only the ruler changed. Here is the rubber-sheet picture, live:
A new ruler bends the right anglestretch the floor sideways and a square corner opens up
Try: drag a. The floor stretches sideways like a photo, the two arrows tilt apart, and the little square corner disappears. Same arrows, new ruler, new angle.
drag the picture to orbit
⟨x,y⟩_A = 0cos ω = 0ω = 90°
—
The ruler A = diag(a, 1) counts the first direction a times more. That is the same as stretching the floor by √a sideways and measuring normally.
The realization
"At a right angle" is not a fact about two arrows alone. It is a fact about two arrows and a ruler. Measuring with A=diag(2,1) is exactly the same as stretching the page sideways by 2 and then measuring normally. Choosing the ruler to fit the problem is what feature weighting and the Mahalanobis distance do in machine learning. (Section 5's lens shows the same thing: press diag(2, 1).)
In one sentence: change the ruler and the same two arrows can stop being at a right angle.
10
Orthonormal matrices — the motions that don't lie
Imagine this
Turn a photo on your phone. The faces in it keep their shapes. Nothing gets longer, nothing gets squashed. Now stretch the photo with two fingers. The faces get wider and the angles in them change.
Turning is an honest motion: every length and angle survives. Stretching or slanting is a lying motion: it moves things and changes their measurements.
Why machine learning cares: turn an embedding space and every similarity, every distance and every nearest neighbour stays exactly the same. So the honest motions are safe to use anywhere.
Which matrices are honest? The ones whose columns are at right angles to each other and each of length 1. They are called orthogonal (or orthonormal) matrices, and they satisfy one neat rule:
ATA=IsoA−1=AT
In words: to undo the motion, just flip the matrix (transpose it). No hard work needed. A turn by an angle θ, (cosθsinθ−sinθcosθ), is one example. So is a mirror flip.
Why does ATA=I keep lengths? Because the new length squared is ∥Ax∥2=xTATAx=xTIx=∥x∥2. The ATA in the middle just disappears. The same happens inside the angle formula, so angles survive too.
A slant (a shear) (10k1) pushes every point sideways by k times its height. Flat arrows stay put and everything else leans over. Watch both motions:
Honest motion vs. lying motiona stiff tile keeps its shape · a rubber tile does not
Try: press ▶ on Rotate — the tile spins and the chips never change. Then press Shear and watch the same tile smear and the chips drift.
drag the picture to orbit
‖u‖: —angle(u,v): —AᵀA = I ✓
—
The two rings on the floor are the ruler: each arrow tip must stay on its ring if its length is honest. Stiff tile — tips ride the rings. Rubber tile — tips slide off.
The realization
ATA=I
This one line is the test for an honest motion. Pass it, and every length, distance and angle is safe. The shear keeps the area (its determinant is 1), but it fails this test, and you can see its arrows slide off the measuring rings.
If you want the algebra · honest motions keep every length and angle
Prove it · orthonormal maps keep every length and every angle — derived
Claim. If ATA=I, then ∥Ax∥=∥x∥ for every x, and the angle between Ax and Ay equals the angle between x and y.
1
Write the dot product of two transformed vectors as a matrix sandwich and use (Ax)T=xTAT:
⟨Ax,Ay⟩=(Ax)T(Ay)=xT(ATA)yTranspose of a product reverses the order (Unit 1); matrix multiplication is associative, so we may group the middle.
2
Replace ATA by I:
⟨Ax,Ay⟩=xTy=⟨x,y⟩This is the whole cancellation. Inner products are untouched — every measurement built from them must be untouched too.
3
Lengths: put y=x in step 2: ∥Ax∥2=⟨Ax,Ax⟩=⟨x,x⟩=∥x∥2.
Squared length is a special case of the inner product, so it is preserved; take square roots.
4
Angles: every factor in the cosine formula is preserved, so the ratio is too:
cosω′=∥Ax∥∥Ay∥⟨Ax,Ay⟩=∥x∥∥y∥⟨x,y⟩=cosω
Same cosine on [0,π] means the same angle. ∎Note what the proof needs: only ATA=I. A shear has det=1 yet ATA=I — and the widget shows it bending both gauges.
Side note: if the columns are orthonormal, so are the rows. For square matrices a left inverse is also a right inverse: if BA=I=AC then B=B(AC)=(BA)C=C.
Pause & predict
Why does an orthonormal A keep every length the same?
In one sentence: a matrix with ATA=I turns or flips space like a stiff tile, so every length and angle survives.
11
The shadow machine — projection
Imagine this
A streetlamp shines straight down on a road. You hold a stick a at a slant. The road runs in the direction b.
The stick's shadow on the road is the part of the stick that goes along the road. The rest of the stick points straight up, at a right angle to the road. So the stick = shadow + leftover.
That split is called projection. How long is the shadow? The shadow is some multiple of the road direction: αb. We want the leftover a−αb to stand at a right angle to the road. That one wish fixes α:
α=⟨b,b⟩⟨a,b⟩,shadow=projb(a)=αb
Quick example: a=(2,3) and the road b=(1,0). Then α=12=2, the shadow is (2,0) and the leftover is (0,3), pointing straight up. If b has length 1, it is even simpler: α=⟨a,b⟩.
The shadow machinesplit any vector into along + across · drag to orbit
Try: swing the stick past 90° from the road and watch α turn negative — the shadow falls behind the lamp post; then turn the road and see the split recomputed.
drag the picture to orbit
shadow coeff α = —⟨a − αb, b⟩ = 0
—
Orange on the road = the shadow (α·b); the grey arrow is the road's unit direction b. Violet = the leftover, at a right angle to the road — the small square certifies it. This one picture is least squares, attention scores, and PCA's first move, all waiting to happen.
The realization
Any arrow = its shadow along a direction + a leftover at a right angle. The shadow amount is α=⟨a,b⟩/⟨b,b⟩. If the stick leans backwards (angle past 90°), α turns negative and the shadow falls behind you. This single split is the heart of least squares, attention scores and PCA.
If you want the algebra · where the shadow formula comes from
Prove it · the shadow coefficient — derived
Claim. The multiple of b whose leftover is orthogonal to b is α=⟨b,b⟩⟨a,b⟩, so projb(a)=αb.
1
State the demand as an equation:
⟨a−αb,b⟩=0"The leftover is perpendicular to the road" — one unknown, α, one equation.
2
Open the left slot with bilinearity:
⟨a,b⟩−α⟨b,b⟩=0Linearity in the first argument lets the subtraction and the scalar α pass through.
3
Solve for α (allowed because b=0 makes ⟨b,b⟩>0):
α=⟨b,b⟩⟨a,b⟩, hence projb(a)=⟨b,b⟩⟨a,b⟩b and a−projb(a)⊥b. ∎If b is a unit vector the denominator is 1 and α is just ⟨a,b⟩. You met this α already — it is the "smartest choice" inside the Cauchy–Schwarz proof. Same coefficient, same geometry.
In one sentence: to find a shadow, ask for the leftover to be at a right angle, and the amount comes out as ⟨a,b⟩/⟨b,b⟩.
12
Gram–Schmidt — cleaning a messy basis
Imagine this
In a city with square blocks, directions are easy: "3 blocks east, 2 blocks north." Now imagine a city whose streets meet at odd angles. Every direction turns into a puzzle.
Square streets make life easy. Gram–Schmidt is a machine that turns any crooked set of streets into square ones.
Unit 2 taught you to find a basis: a set of directions that can reach every point. The best kind is an orthonormal basis: every direction at a right angle to every other, and each of length 1.
Why is it the best? Because finding coordinates becomes easy. With a crooked basis, you must solve equations to find how much of each direction you need. With an orthonormal basis, you just take shadows: the amount of ei in v is ⟨v,ei⟩. No equations.
Coordinates by shadow. With the orthonormal pair e1=(cos30∘,sin30∘), e2=(−sin30∘,cos30∘), the vector v≈(1.13,2.04) has coordinates λ1=⟨v,e1⟩=2 and λ2=⟨v,e2⟩=1.2: each coordinate is just the shadow of v on that axis. In a non-orthonormal basis you would have to solve a 2×2 system instead.
If you want the algebra · why coordinates are just shadows
Prove it · coordinates in an orthonormal basis are inner products — derived
Claim. If {e1,…,en} is orthonormal and v=λ1e1+⋯+λnen, then λi=⟨v,ei⟩.
1
Take the inner product of both sides of the expansion with one basis vector ei:
⟨v,ei⟩=⟨j=1∑nλjej,ei⟩=j=1∑nλj⟨ej,ei⟩Bilinearity pulls the sum and the scalars λj out of the first slot.
2
Orthonormality kills every term but one: ⟨ej,ei⟩=0 for j=i and =1 for j=i. So
⟨v,ei⟩=λi⋅1=λi. ∎The "1" is where unit length earns its keep; with a merely orthogonal basis you would get λi∥ei∥2 and have to divide. The canonical basis of Rn is one orthonormal basis; rotate it and you get infinitely many others.
The cleaning machine is the shadow machine used over and over. Take your crooked directions one at a time:
1Take the first direction. Shrink or stretch it to length 1. Done: that is e1.
2Take the next direction. Cut off its shadow on every clean direction you already have. What is left stands at a right angle to all of them.
3Stretch that leftover to length 1. That is your next clean direction. Repeat step 2 for the rest.
For two directions it is just: e1=∥x1∥x1, then u2=x2−⟨x2,e1⟩e1, then e2=∥u2∥u2. Watch it happen in 3D:
Gram–Schmidt, step by step — in 3Ddrag to orbit · x₁ = (1,1,0), x₂ = (1,2,2)
Try: press ▶ and watch the leftover lift off the shadow; then step to 3 and orbit until you look straight down the e₁ axis — the green right-angle marker should open into a true L.
Step 0/4
drag the picture to orbit
—
The faint floor is the plane z = 0 (x₁ lies in it); the tinted sheet is the plane the two vectors span — Gram–Schmidt never leaves it. The final frame shows the receipt: ⟨e1,e2⟩=−61+61+0=0 and both lengths exactly 1 — a perfect grid for that plane, built from a lopsided pair that started 45∘ apart.
The realization
Gram–Schmidt = cut off the shadows, then resize to 1. Each new direction loses the parts that point along the clean ones, so what is left must be at a right angle to them. Any basis at all can be cleaned this way.
Bonus · the slides' shortcut: Gram–Schmidt by elimination (and why it works)
The course adds a beautiful industrial route. Stack the messy basis as columns of A, then run plain Gaussian elimination on the augmented matrix [ATA∣AT] — when the left half reaches echelon form, the rows on the right are an orthogonal basis. The slides' example: v1=(3,1), v2=(2,2) give ATA=(10888), and elimination lands on
(100.810.3−0.250.10.75)
Check the right-hand rows: (0.3,0.1)⋅(−0.25,0.75)=−0.075+0.075=0 — orthogonal (the first is v1 rescaled; the second is what's left of v2 after removing its v1-shadow). Normalize and you have an orthonormal basis. Why it works, in three moves: ① full column rank makes ATA positive-definite (Ax=0⟺ATAx=0, so the blind spots match and are trivial) — elimination needs no row swaps; ② elimination is multiplication by elementary matrices, i.e. ATA=LU with L lower-triangular (Unit 1's recorded elimination!), and the right half becomes QT=L−1AT; ③ then QTQ=L−1(ATA)L−T=UL−T is upper-triangular and symmetric — hence diagonal — which is precisely the statement that Q's columns are orthogonal. Elimination doesn't just solve systems; run on ATA, it quietly performs Gram–Schmidt.
Same geometry, industrial route.q1=0.1v1 and q2=0.625×(−0.4,1.2) — the second row is precisely the leftover after removing v2's shadow 108v1=(2.4,0.8), rescaled. Elimination found the shadow coefficient 0.8 on its own: it is the multiplier it used to clear the first column.
Pause & predict
In Gram–Schmidt, why does cutting off the shadow ⟨x2,e1⟩e1 from x2 work?
In one sentence: Gram–Schmidt turns any crooked basis into a square one by cutting off shadows and resizing to length 1.
13
The whole story, in five lines
①Length is a choice. A norm is any length rule that scales, allows no shortcuts, and is zero only for "nowhere". The crow (round ball) and the taxi (diamond) both qualify.
②The dot product is an agreement score. Its blueprint (fair with sums, same both ways, positive with itself) defines an inner product. Every SPD matrix A makes one: xTAy. Test SPD with the top-left numbers and determinants.
③Free gifts: length, distance, and (because a shadow never beats the stick) an angle: cosω=⟨x,y⟩/∥x∥∥y∥, ML's similarity dial.
④Right angles depend on the ruler. Honest motions (ATA=I) keep every measurement. Random arrows in high dimensions are almost always at right angles.
⑤Shadows build square grids. Projection splits an arrow into along + across. Gram–Schmidt repeats it to turn any basis into an orthonormal one.
The one thing to remember
Geometry is a choice. Pick the matrix, and you have picked what "long", "near" and "at a right angle" mean. Much of machine learning is the craft of picking that ruler well. And whatever ruler you pick, Gram–Schmidt can always build a perfect square grid for it.
14
Practice arena — the unit's problem set, solved in full
This is Prof. Saurabh's practice set for this unit — Analytic Geometry: eight problems on inner products, positive-definite matrices, norms, angles, orthogonality and projections. Attempt each one on paper before unfolding — the fold-out solution shows every step of the computation, nothing skipped.
Problem 1Easy
On R3 with the standard (Euclidean) inner product, let u=(1,1,0)⊤ and v=(0,1,1)⊤.
(a) Find all vectors w∈R3 orthogonal to both u and v, and write down the unit vectors of this form. [2 M]
(b) Compute the angle ω between u and v. [1 M]
(c) Show that {u,v,w} is a basis of R3, and explain geometrically why w is perpendicular to the plane spanned by u and v. [1 M] (4 marks)
Show the worked solution — every step
Step 1 · Turn "orthogonal to both" into equations (a). Idea: "orthogonal to both" means two dot-product equations. Write w=(w1,w2,w3)⊤:
w⊤u=w1+w2=0,w⊤v=w2+w3=0.
Step 2 · Solve the little system. From these, w1=−w2 and w3=−w2. Letting the free variable be w2=t,
w=t(−1,1,−1)⊤,t∈R.
Step 3 · Normalise for the unit vectors. Divide by the length ∥(−1,1,−1)⊤∥=(−1)2+12+(−1)2=3:
w=±31(−1,1,−1)⊤.
Both signs: the orthogonal line carries exactly two unit vectors.
Step 4 · The angle (b). Use cosω=∥u∥∥v∥u⊤v. Here u⊤v=0+1+0=1 and ∥u∥=∥v∥=2, so
cosω=2⋅21=21⟹ω=60∘.
Step 5 · Basis test (c). Three vectors in R3 form a basis exactly when their determinant is nonzero. With w=(−1,1,−1)⊤,
det[uvw]=det110011−11−1=1(1⋅(−1)−1⋅1)−0+(−1)(1⋅1−1⋅0)=−2−1=−3=0,
so {u,v,w} is a basis.
Step 6 · The geometric picture.u and v span a plane. Since w was constructed to be orthogonal to both u and v, it is orthogonal to every vector in that plane — any such vector is αu+βv, and w⊤(αu+βv)=α⋅0+β⋅0=0. So w is the normal direction to the plane.
Answer. (a) w=t(−1,1,−1)⊤, t∈R; unit vectors ±31(−1,1,−1)⊤. (b) ω=60∘. (c) det[uvw]=−3=0, so it is a basis; w is the plane's normal direction.
Watch out
A "unit vectors" answer needs both signs — +31(−1,1,−1)⊤ and −31(−1,1,−1)⊤. Writing only one loses half the solution set, and forgetting to divide by 3 loses the "unit" part entirely.
Key takeaway
"Orthogonal to both" always translates into a homogeneous linear system — one dot-product equation per constraint. In R3, two independent constraints leave a one-dimensional line of solutions: the normal line of the plane.
Wait — really?
You just computed a cross product without naming it: u×v=(1,−1,1)⊤, which is exactly the t=−1 member of your family t(−1,1,−1)⊤. Solving "orthogonal to both" as a linear system is precisely what the cross product does for a living in R3.
Problem 2Easy
(Similarity vs. dissimilarity of data objects.) Three data points live in R3:
p1=(2,1,0)⊤,p2=(0,1,2)⊤,p3=(2,1,1)⊤.
(a) Build the 3×3 dissimilarity matrix D using Euclidean distance. [2 M]
(b) Which two points are the most similar? [1 M]
(c) Compute the cosine similarity between p1 and p3. [1 M] (4 marks)
Show the worked solution — every step
Step 1 · Pairwise distances (a). Dissimilarity between two points is just the distance d(pi,pj)=∥pi−pj∥. Compute each pair:
d(p1,p2)=∥(2,0,−2)⊤∥=4+0+4=8=22,d(p1,p3)=∥(0,0,−1)⊤∥=1,d(p2,p3)=∥(−2,0,1)⊤∥=4+0+1=5.
Step 2 · Assemble the matrix. Place these in a symmetric matrix with zeros on the diagonal (a point's distance to itself is 0):
D=02212205150.
Step 3 · Most similar pair (b). "Most similar" = smallest dissimilarity. The smallest off-diagonal entry is d(p1,p3)=1, so p1 and p3 are the most similar.
Step 4 · Cosine similarity (c). Cosine similarity is cosθ=∥p1∥∥p3∥p1⊤p3:
p1⊤p3=2⋅2+1⋅1+0⋅1=5,∥p1∥=5,∥p3∥=6,cosθ=565=305=630≈0.913.
(Close to 1, confirming p1 and p3 point in nearly the same direction.)
Answer. (a) D as above, symmetric with zero diagonal. (b) p1 and p3, at distance 1. (c) cosθ=5/30=30/6≈0.913.
Watch out
In a dissimilarity matrix, small means similar — scanning for the largest entry answers the opposite question. And the diagonal zeros are not data: every point is at distance 0 from itself, so only off-diagonal entries compete.
Key takeaway
Two different rulers for "similar": Euclidean distance measures closeness in position, cosine similarity measures alignment of direction. Here they happen to agree (p1,p3 win on both); in general they need not.
Wait — really?
Cosine similarity is blind to length: (2,1,0)⊤ and (4,2,0)⊤ have cosine similarity exactly 1 even though they sit 5 apart. That is why it is the default in text retrieval — a tweet and an essay about the same topic point the same way; they just differ in length.
Problem 3Medium
Let A=[2112] and define a new inner product on R2 by ⟨x,y⟩A=x⊤Ay.
(a) Show A is symmetric positive definite, so ⟨⋅,⋅⟩A is a genuine inner product. [1 M]
(b) The vectors x=(1,0)⊤ and y=(0,1)⊤ are orthogonal in the dot product. Are they still orthogonal under ⟨⋅,⋅⟩A? Find the angle between them in this new inner product. [2 M]
(c) Find a vector y′=(a,1)⊤ that is orthogonal to x with respect to ⟨⋅,⋅⟩A. [1 M] (4 marks)
Show the worked solution — every step
Step 1 · Certify the inner product (a).A is symmetric since A⊤=A. Sylvester's criterion (all leading minors positive):
D1=2>0,D2=detA=2⋅2−1⋅1=3>0.
So A is positive definite. A symmetric, positive-definite matrix always makes x⊤Ay a valid inner product: it is bilinear, symmetric, and x⊤Ax>0 for x=0.
Step 2 · Test orthogonality (b). Compute ⟨x,y⟩A=x⊤Ay. First Ay=A(0,1)⊤=(1,2)⊤, hence
⟨x,y⟩A=x⊤(Ay)=(1,0)⋅(1,2)=1=0.
They are not orthogonal here.
Step 3 · The A-norms. To get the angle we also need
∥x∥A=x⊤Ax=A11=2,∥y∥A=A22=2.
Step 4 · The A-angle.cosθ=∥x∥A∥y∥A⟨x,y⟩A=2⋅21=21⟹θ=60∘.
Takeaway (from the source): orthogonality depends on which inner product you use.
Step 5 · Force orthogonality (c). We need ⟨x,y′⟩A=0. Note x⊤A=(1,0)A=(2,1), so
⟨x,y′⟩A=(2,1)⋅(a,1)=2a+1=0⟹a=−21.
Thus y′=(−21,1)⊤.
Answer. (a) SPD by Sylvester: D1=2>0, D2=3>0. (b) No — ⟨x,y⟩A=1=0; the angle in the A-geometry is θ=60∘. (c) a=−21, i.e. y′=(−21,1)⊤.
Watch out
When you switch inner products, switch everything: the cosine formula needs the A-inner product on top and the A-norms below. Mixing ⟨x,y⟩A=1 with the Euclidean norms ∥x∥=∥y∥=1 would give cosθ=1, i.e. a 0∘ angle — badly wrong.
Key takeaway
Orthogonality is relative to the inner product. The same pair of vectors can be perpendicular in one geometry and at 60∘ in another — and part (c) shows you can always re-engineer a vector to restore orthogonality in the new geometry.
Wait — really?
The coordinate axes themselves — e1 and e2, the gridlines of the plane — meet at 60∘, not 90∘, the moment A defines the geometry. Perpendicularity is not a property of two arrows; it is a property of the inner product that measures them.
Problem 4Medium
On R3 use the weighted inner product ⟨x,y⟩A=x⊤Ay with
A=210120001(SPD).
Let a=(1,−1,0)⊤ and b=(1,0,2)⊤.
(a) Compute ⟨b,a⟩A, ∥a∥A, and ∥b∥A. [2 M]
(b) Find the orthogonal projection p of b onto the line spanned by a, in this inner product. [2 M]
(c) Verify that the residual b−p is A-orthogonal to a (this is what makes p the orthogonal projection). [1 M] (5 marks)
Show the worked solution — every step
Step 1 · One matrix–vector product does most of the work (a). Trick: compute the matrix–vector product once, then take dot products. With
Aa=A(1,−1,0)⊤=(2−1,1−2,0)⊤=(1,−1,0)⊤:⟨b,a⟩A=b⊤(Aa)=(1,0,2)⋅(1,−1,0)=1,∥a∥A2=a⊤(Aa)=(1,−1,0)⋅(1,−1,0)=2.
Step 2 · The norm of b. For ∥b∥A, use Ab=A(1,0,2)⊤=(2,1,2)⊤:
∥b∥A2=b⊤(Ab)=(1,0,2)⋅(2,1,2)=2+0+4=6.
So ⟨b,a⟩A=1, ∥a∥A=2, ∥b∥A=6.
Step 3 · Project (b). Projection formula (same as usual, but every inner product is the A-one):
p=⟨a,a⟩A⟨b,a⟩Aa=21(1,−1,0)⊤=(21,−21,0)⊤.
Step 4 · Check the residual (c). The residual is
r=b−p=(1,0,2)⊤−(21,−21,0)⊤=(21,21,2)⊤.
Check A-orthogonality using the same Aa=(1,−1,0)⊤:
⟨r,a⟩A=r⊤(Aa)=(21,21,2)⋅(1,−1,0)=21−21+0=0.✓
Since r⊥Aa, p is indeed the orthogonal projection of b onto the line through a.
Answer. (a) ⟨b,a⟩A=1, ∥a∥A=2, ∥b∥A=6. (b) p=(21,−21,0)⊤. (c) ⟨b−p,a⟩A=0 ✓ — the residual is A-orthogonal to a.
Watch out
Verify with the same inner product you projected in: the defining property is ⟨b−p,a⟩A=0. In this particular problem a plain dot-product check happens to give 0 too — pure luck, because Aa=a here (see below). In a general weighted geometry the residual is A-orthogonal, not dot-orthogonal, to a.
Key takeaway
The projection recipe never changes: p=⟨a,a⟩⟨b,a⟩a — swap in whichever inner product defines the geometry. The residual-orthogonality check is the certificate that p really is the closest point on the line.
Wait — really?
Aa=a: the vector a=(1,−1,0)⊤ is an eigenvector of A with eigenvalue 1. That is why every A-computation involving a collapsed to a plain dot product — and why the Euclidean projection of b onto a would land on the same p here. Move a off an eigendirection and the two projections part ways.
Problem 5Medium
Consider the symmetric matrix A(t)=[t33t], t∈R.
(a) Classify A(t) for all real t as positive definite, positive semidefinite, indefinite, negative semidefinite, or negative definite. [3 M]
(b) For which t does ⟨x,y⟩=x⊤A(t)y define a valid inner product? At the borderline value t=3, exhibit a nonzero vector v with ⟨v,v⟩=0. [2 M] (5 marks)
Show the worked solution — every step
Looking ahead
This solution uses eigenvalues, which Unit 4 introduces properly: for a symmetric matrix, positive-definite means all eigenvalues are positive. If you have not met them yet, you can classify A(t) with this unit's tools instead — Sylvester's minors D1=t and D2=t2−9 give "positive definite ⟺t>3" — and read the eigenvalue route as a preview.
Step 1 · Find the eigenvalues (a). Method: a symmetric matrix is classified by the signs of its eigenvalues. Solve det(A−λI)=0:
(t−λ)2−9=0⟹t−λ=±3⟹λ=t−3 or λ=t+3.
Step 2 · Read off the signs. Now just read off the signs of the two eigenvalues t−3 and t+3:
t>3t=3−3<t<3t=−3t<−3:both positive⇒positive definite:λ=6,0⇒positive semidefinite:one +,one −⇒indefinite:λ=0,−6⇒negative semidefinite:both negative⇒negative definite
Step 3 · Inner-product range and the degenerate vector (b). An inner product needs a positive-definite matrix, so we need t>3. At t=3 the matrix is only semidefinite, which fails the rule ⟨v,v⟩>0 for v=0. Concretely, take v=(1,−1)⊤. With A(3)=[3333],
⟨v,v⟩=v⊤A(3)v=(1,−1)[3333][1−1]=(1,−1)⋅(0,0)=0,
even though v=0. So t=3 does not give an inner product.
Answer. (a) Positive definite for t>3; positive semidefinite at t=3 (λ=6,0); indefinite for −3<t<3; negative semidefinite at t=−3 (λ=0,−6); negative definite for t<−3. (b) Valid inner product ⟺t>3; at t=3, v=(1,−1)⊤=0 has ⟨v,v⟩=0.
Watch out
Semidefinite is not "almost good enough": at t=3 the axiom that dies is exactly the strict inequality ⟨v,v⟩>0 for v=0. A geometry in which a nonzero vector has length zero cannot measure distances — so the borderline value is excluded, not included.
Key takeaway
For a symmetric matrix, definiteness = the sign pattern of its eigenvalues, full stop. For the pattern [tcct] the eigenvalues are always t+c and t−c — diagonal plus-or-minus off-diagonal — which makes the whole classification a one-line read-off.
Wait — really?
One dial sweeps all five classes — and the eigenvectors never move. For everyt, A(t)(1,1)⊤=(t+3)(1,1)⊤ and A(t)(1,−1)⊤=(t−3)(1,−1)⊤. Turning t just slides the two eigenvalues t±3 along the number line past zero, while the axes of the quadratic form stay frozen at 45∘.
Problem 6Hard
(Positive definiteness over C.) For a real parameter k, consider
A(k)=[k1−i1+i2].
For u,v∈C2, let u∗ denote the conjugate transpose and set ⟨u,v⟩=u∗A(k)v.
(a) Show A(k) is Hermitian for every real k. [1 M]
(b) Find all real k for which A(k) is positive definite — equivalently, for which ⟨u,v⟩=u∗A(k)v is a valid inner product on C2. [2 M]
(c) At the borderline value k=1 the matrix is only positive semidefinite. Find a nonzero vector z∈C2 with z∗A(1)z=0, showing the form degenerates there. [2 M] (5 marks)
Show the worked solution — every step
Step 1 · Hermitian check (a). A matrix is Hermitian when A∗=A, i.e. the diagonal entries are real and the two off-diagonal entries are complex conjugates of each other. Here the diagonal is k,2 (real, because k is real) and the off-diagonals satisfy 1+i=1−i. Hence A(k)∗=A(k) for every real k.
Step 2 · Sylvester over C (b). Sylvester's criterion also works for Hermitian matrices: positive definite ⟺ all leading principal minors are positive (they come out real automatically). The minors are
D1=k,D2=detA(k)=2k−(1+i)(1−i).
Step 3 · The crucial complex product. It is a squared modulus:
(1+i)(1−i)=1−i2=2=∣1+i∣2,soD2=2k−2=2(k−1).
Step 4 · Solve the inequalities. Requiring D1>0 and D2>0 gives k>0 and k>1, so
A(k)is positive definite⟺k>1.
Step 5 · The degenerate direction at k=1 (c). At k=1 we have D2=0, so A(1)=[11−i1+i2] is singular (D1=1>0, D2=0: positive semidefinite). Idea: any nonzero null-space vector works, since A(1)z=0⇒z∗A(1)z=z∗0=0. From the first row, z1+(1+i)z2=0; choosing z2=1 gives z1=−(1+i), so
z=[−(1+i)1].
Step 6 · Verify it is a null vector. Using (1−i)(1+i)=2:
A(1)z=[1⋅(−(1+i))+(1+i)⋅1(1−i)⋅(−(1+i))+2⋅1]=[0−2+2]=[00].
Hence z∗A(1)z=0 with z=0: at k=1 the form is not positive definite, so it is not an inner product.
Answer. (a) A(k)∗=A(k) for all real k. (b) A(k) is positive definite ⟺k>1. (c) z=(−(1+i),1)⊤=0 satisfies A(1)z=0, hence z∗A(1)z=0.
Watch out
Over C, transpose is not enough — use the conjugate transpose u∗. And the off-diagonal product is (1+i)(1−i)=∣1+i∣2=2, not(1+i)2=2i. Writing D2=2k−2i (a complex determinant for a Hermitian matrix — impossible) is the classic slip.
Key takeaway
Hermitian + positive definite is the complex analogue of symmetric + positive definite: Sylvester's criterion still runs, the leading minors are automatically real, and only k>1 — both minors strictly positive — buys a genuine inner product on C2.
Wait — really?
At k=1 there exists a nonzero vector of length zero: ⟨z,z⟩=0 although z=0. The geometry has a direction it simply cannot see — which is precisely the disease the positive-definiteness axiom exists to rule out.
Problem 7Medium
For each matrix M below, decide whether ⟨x,y⟩=x⊤My defines a valid inner product on R2. Justify using the three requirements (bilinear, symmetric, positive-definite); when it fails, exhibit a witness. [2 M each]
(a)M=[1221](b)M=[2113](c)M=[1011](6 marks)
Show the worked solution — every step
Step 1 · Bilinearity is free. Every x⊤My is automatically bilinear, so only symmetry and positive-definiteness can fail.
Step 2 · (a) Symmetric but indefinite.M is symmetric, so symmetry holds. Check positive-definiteness by Sylvester: D1=1>0 but D2=detM=1−4=−3<0. Fails. A witness: x=(1,−1)⊤ gives
x⊤Mx=(1,−1)[1221][1−1]=(1,−1)⋅(−1,1)=−2<0.
So ⟨x,x⟩<0 is possible — not an inner product.
Step 3 · (b) All three requirements hold.M is symmetric. Sylvester: D1=2>0 and D2=detM=6−1=5>0, so M is positive definite. All three requirements hold — this is a valid inner product.
Step 4 · (c) Symmetry fails.M is not symmetric, and that breaks the symmetry requirement directly. Test on the basis vectors:
⟨e1,e2⟩=e1⊤Me2=M12=1,⟨e2,e1⟩=e2⊤Me1=M21=0.
Since ⟨e1,e2⟩=⟨e2,e1⟩, symmetry fails — not an inner product (even though the quadratic form x⊤Mx=x12+x1x2+x22 happens to be positive; symmetry alone already rules it out).
Answer. (a) Not an inner product — indefinite; witness x=(1,−1)⊤ with x⊤Mx=−2<0. (b) Valid inner product — symmetric with D1=2>0, D2=5>0. (c) Not an inner product — symmetry fails: ⟨e1,e2⟩=1=0=⟨e2,e1⟩.
Watch out
D1>0 alone proves nothing — in (a) the first minor passes and the matrix is still indefinite; Sylvester needs all leading minors positive. And check symmetry before reaching for Sylvester: the criterion is only meaningful for symmetric matrices.
Key takeaway
The three-point checklist, cheapest first: bilinearity is automatic for x⊤My; then verify symmetry M⊤=M; only then test positive definiteness (Sylvester or eigenvalue signs). Failing any single one ends the game.
Wait — really?
Matrix (c) satisfies x⊤Mx=x12+x1x2+x22=(x1+2x2)2+43x22>0 for every x=0 — genuinely positive "lengths" — and it is still not an inner product. Positivity cannot buy back broken symmetry: with this M, the "angle between x and y" would depend on the order in which you name them.
Problem 8Medium
On R2 use ⟨x,y⟩A=x⊤Ay with A=[3112] (SPD), and let x=(1,1)⊤, y=(1,−1)⊤.
(a) Compute ∥x∥A, ∥y∥A, and ⟨x,y⟩A. [2 M]
(b) Verify the Cauchy–Schwarz inequality ∣⟨x,y⟩A∣≤∥x∥A∥y∥A. [1 M]
(c) Compute the distance d(x,y)=∥x−y∥A and verify the triangle inequality ∥x−y∥A≤∥x∥A+∥y∥A. [2 M] (5 marks)
Show the worked solution — every step
Step 1 · Two matrix–vector products (a). Compute Ax and Ay once:
Ax=A(1,1)⊤=(3+1,1+2)⊤=(4,3)⊤,Ay=A(1,−1)⊤=(3−1,1−2)⊤=(2,−1)⊤.
Step 2 · Norms and inner product.∥x∥A2=x⊤(Ax)=(1,1)⋅(4,3)=7,∥y∥A2=y⊤(Ay)=(1,−1)⋅(2,−1)=2+1=3,⟨x,y⟩A=x⊤(Ay)=(1,1)⋅(2,−1)=1.
So ∥x∥A=7, ∥y∥A=3, ⟨x,y⟩A=1.
Step 4 · Distance and triangle inequality (c). Distance uses the same norm on the difference. With x−y=(0,2)⊤ and A(0,2)⊤=(2,4)⊤:
∥x−y∥A2=(0,2)⋅(2,4)=8⟹d(x,y)=8=22≈2.83.
Triangle inequality:
∥x−y∥A=22≈2.83≤∥x∥A+∥y∥A=7+3≈4.38.✓
The distance must be measured with A on the difference: (x−y)⊤A(x−y)=8, so d=22 — not the Euclidean ∥(0,2)⊤∥=2. Every length in this problem, the distance included, is an A-length.
Key takeaway
Cauchy–Schwarz and the triangle inequality are theorems of every inner-product space: if A is genuinely SPD they cannot fail. So "verifying" them is really a sanity check on your arithmetic — if such a check ever fails, either the computation or the claimed positive-definiteness is wrong.
Wait — really?
In the plain dot product these two vectors are orthogonal — x⊤y=1−1=0 — yet under A their inner product is 1, giving cosθA=1/21≈0.218: an angle of about 77.4∘. The matrix A literally bends the right angle.
With lengths and angles in hand, Unit 4 goes looking for a matrix's fingerprints: the determinant as a volume dial, the directions a matrix cannot turn, and the theorem that lets a symmetric matrix be rebuilt as turn · stretch · turn back.