An inner product gives any vector space lengths, angles and perpendicularity. With it, orthogonal bases make coordinates easy, Gram–Schmidt builds them, and projection onto a subspace gives the closest point.
Taught in 375/376Apostol, not taughtBeyond the courseApostol 1.11 to 1.17Spagnolie, Lectures 4 to 6MATH 375 HW3 and HW4
So far a vector space can add and scale, but it has no length, no angle and no idea of “perpendicular”. In JEE you learned the dot product as a⋅b=∣a∣∣b∣cosθ, which starts from the angle. This chapter goes the other way. We write down a few properties of the dot product as axioms (an inner product), and then we define length and angle from it. That works in any vector space, including spaces of functions, and it leads to the most useful idea in applied mathematics: the closest point to a vector, inside a subspace, is its shadow.
Before you start
You need bases and coordinates (2.2), matrix multiplication and the transpose (2.5), and one fact from 2.8 near the end. Some integration is used for function spaces. Three quick checks:
Quick checkIs {(1,0),(1,1)} a basis of R2?
The two vectors are independent (neither is a multiple of the other), and two independent vectors in a 2-dimensional space are a basis.Review: basis
Quick checkWhat are the coordinates of (3,5) in the basis {(1,0),(1,1)}?
We need a(1,0)+b(1,1)=(3,5). The second entry gives b=5, then the first gives a+5=3, so a=−2. The ordinary coordinates (3,5) are the coordinates in the standard basis, which is a different basis.Review: coordinates
Quick checkFor column vectors x=(1,2) and y=(3,4), what is the 1×1 matrix product xTy?
xT is a row, so xTy=1⋅3+2⋅4=11. The 2×2 matrix is xyT, with the factors the other way round.Review: matrix multiplication
The picture
Drag the blue vector v and the grey direction u. The green arrow p is the shadow of v on the line through u. The red dashed arrow e is what is left over. It meets the line at a right angle, and the little square marks that. Now use the slider under the picture to move the orange point along the line. It is never closer to v than the shadow is. This one picture is the backbone of the chapter: Cauchy–Schwarz, Gram–Schmidt, best approximation, Fourier series and least squares are all this triangle in different spaces.
Where this came from· Cauchy, Bunyakovsky, Schwarz
The inequality that makes angles possible grew in steps, each for a bigger setting. Cauchy published it in 1821 for finite sums of numbers. Bunyakovsky (1859) proved the matching inequality for integrals, which is the version for functions that you use in this chapter. Schwarz (1888) gave the modern proof of the integral version. Some books, especially Russian ones, use all three names. The three versions are one theorem, because the proof below uses only the inner-product axioms and never what the vectors are. That is the point of defining an inner product by axioms: one proof then covers sums, integrals and every other case.
The idea, in words
The dot product x⋅y=x1y1+⋯+xnyn does three jobs. It measures length (x⋅x), it detects perpendicular vectors (x⋅y=0), and it measures how much x points along y. All three come from four properties of the dot product. So we take those four properties as the rules, call anything that obeys them an inner product, and everything else follows by algebra. The payoff is that functions can be “perpendicular” too, and we can ask for the nearest function in a family.
Why· How much does x point along y?
Look at the picture. The shadow of v on the line of u is p=cu with c=u⋅uv⋅u. That is the whole idea of projection: the number c is the dot product, divided by the length of u squared so that u‘s own size does not matter. When v is perpendicular to u, the shadow is zero. When v is a multiple of u, the shadow is v itself. Every formula later in the chapter is this one repeated.
Definitions and theorems
Inner products
Definition T
Inner product
Let V be a real vector space. An inner product assigns to every pair x,y in V a real number (x,y) such that, for all x,y,z in V and every real c:
(x,y)=(y,x) (symmetry);
(x+z,y)=(x,y)+(z,y) (additivity);
(cx,y)=c(x,y) (homogeneity);
(x,x)>0 whenever x=O (positivity).
A real vector space with an inner product is a Euclidean space (Apostol and Spagnolie). Many books write ⟨x,y⟩.
In one lineA rule (x,y) giving a real number for every pair of vectors, symmetric, linear, and positive on non-zero vectors. The dot product is the model.
Why it existsIt lets any vector space have length, angle and perpendicularity, and these are what make 'closest point' mean something.
By symmetry, additivity and homogeneity also hold in the second slot, so (x,y) is linear in each entry separately. Taking c=0 in rule 3 gives (O,y)=0, so (x,x)=0 exactly when x=O. Axiom 4 is the one that fails most often.
Examples.
The dot product on Rn:(x,y)=x1y1+⋯+xnyn=xTy. Symmetry is clear, additivity and homogeneity are arithmetic, and (x,x)=x12+⋯+xn2>0 unless every xi=0.
Functions: on C[a,b], the continuous functions on [a,b], put (f,g)=∫abf(t)g(t)dt. Rules 1 to 3 hold because integrals are symmetric and linear. For rule 4, if f=0 then f(t0)=0 for some t0, so by continuity f(t)2>c>0 on a small interval around t0, and the integral of f2 is positive. Here continuity matters: a function that is 1 at a single point and 0 elsewhere has ∫f2=0 but is not the zero function.
A weighted inner product:(f,g)w=∫abw(t)f(t)g(t)dt for any positive function w. Spagnolie stressed “there is no unique inner product” on a space.
Another one on R2:(x,y)=x1y1+2x2y2. Positivity holds since x12+2x22>0 for x=O.
Worked example Apostol 1.13 #1(c), MATH 375 HW3
Is (x, y) = (x1 + x2 + x3)(y1 + y2 + y3) an inner product on R³?
Solution.
Check symmetry. Swapping x and y gives the same product of two sums. Multiplication of numbers is commutative.
Check additivity and homogeneity.(x+z,y)=(∑(xi+zi))(∑yi)=(x,y)+(z,y) and (cx,y)=c(x,y). The sum of coordinates is linear in x, and multiplying by the fixed number ∑yi keeps that.
Check positivity. Here (x,x)=(x1+x2+x3)2≥0, but it equals 0 whenever the coordinates add to zero. Take x=(1,0,−1): (x,x)=0⋅0=0 although x=O. Axiom 4 demands (x,x)>0 for every non-zero x. One counterexample is enough to break it.
Answer. No. It fails axiom 4. (Spagnolie’s remark: positivity is the usual failure, and one counterexample vector shows it.)
Quick checkIs (x,y)=x1y1−x2y2 an inner product on R2?
It is symmetric and linear, but (x,x)=x12−x22, and for x=(0,1) this is −1, which is not positive. Positivity is the axiom that most often breaks.
Your answerOn R2 use the inner product (x,y)=x1y1+2x2y2. What is the norm ∥(2,1)∥?
The norm is (x,x), and (x,x) uses this inner product, not the dot product.
(x,x)=2⋅2+2⋅1⋅1=6, so ∥x∥=6≈2.449. With the ordinary dot product the length would be 5. The norm depends on the inner product.
Length and angle
Definition T
Norm
In a Euclidean space the norm of x is ∥x∥=(x,x), which makes sense because (x,x)≥0. The distance between x and y is ∥x−y∥. In Rn with the dot product this is the usual length x12+⋯+xn2. In C[a,b] it is (∫abf2)1/2.
In one lineThe length of a vector, ∥x∥=(x,x), defined from the inner product.
Why it existsDistance and size are needed to say that one vector is closer to a target than another.
Now we want an angle. In JEE, cosθ=∣x∣∣y∣x⋅y was a consequence of the picture. Here we want to use that formula as the definition of the angle between non-zero vectors. There is a problem: cosθ must lie in [−1,1], or the inverse cosine does not exist. Why would ∥x∥∥y∥(x,y) always be in that range, for functions, say? That is exactly what the next theorem proves.
Theorem TApostol Thm 1.8; Spagnolie Lecture 4
Cauchy–Schwarz inequality
In any Euclidean space, for all x and y,
∣(x,y)∣≤∥x∥∥y∥,
and equality holds if and only if x and y are linearly dependent.
In one line∣(x,y)∣≤∥x∥∥y∥, with equality exactly when x and y are linearly dependent.
Why it is trueThe squared length ∥x+ty∥2 is a parabola in t that never goes below zero. Evaluating it at its lowest point gives the inequality, and that lowest point is the projection of x onto y.
Why· The picture behind the proof
In the picture above, the point of the line closest to v is the shadow. The proof walks along the line x+ty and looks at its smallest distance from the origin. That smallest length cannot be negative, and writing it out gives the inequality. The special value t0=−(x,y)/(y,y) that makes x+t0y shortest is exactly the leftover vector e in the picture (with the roles v=x, u=y): it is the part of x that does not point along y.
ProofSpagnolie Lecture 4 (the quadratic p(t)); Apostol 1.8
The idea: Look at the squared length of x + ty as a function of t. It is a quadratic that is never negative. Plug in the value of t where it is smallest. What is left is the inequality.
Assume y=O, so (y,y)>0.
If y=O then (x,y)=0 and ∥y∥=0, so both sides are 0 and x,O are dependent.
For every real t: 0≤(x+ty,x+ty).
Axiom 4 and (O,O)=0: an inner product of a vector with itself is never negative. We apply it to the vector x+ty, for each real t.
(x+ty,x+ty)=(x,x)+2t(x,y)+t2(y,y).
Additivity and homogeneity in both slots, plus symmetry (y,x)=(x,y).
Choose t0=−(y,y)(x,y).
This is the value of t at the bottom of the parabola: the derivative 2(x,y)+2t(y,y) is zero there. It is also the projection coefficient from the picture. We are free to choose any t because the inequality holds for all of them.
0≤(x,x)−(y,y)(x,y)2.
Substitute t0 into step 3 and simplify: −2(x,y)2/(y,y)+(x,y)2/(y,y)=−(x,y)2/(y,y).
(x,y)2≤∥x∥2∥y∥2, so ∣(x,y)∣≤∥x∥∥y∥.
Multiply both sides by (y,y)>0, then take square roots (both sides are non-negative).
Equality implies x=−t0y, so x,y are dependent.
If equality holds, the right side of step 5 is exactly 0, so (x+t0y,x+t0y)=0. Axiom 4 then forces x+t0y=O.
Conversely, dependent vectors give equality.
If x=cy, then ∣(cy,y)∣=∣c∣(y,y) by homogeneity. And ∥cy∥=(cy,cy)=c2(y,y)=∣c∣∥y∥, so ∥cy∥∥y∥=∣c∣(y,y) too. (With y=O, dependent means x=cy.)
Proof workshopRebuild the Cauchy–Schwarz proof
Tap the lines in the order a proof would write them. Each line can only use what is already above it.
We divide by (y,y) later, so it must be non-zero. The case y=O is trivial: both sides are 0.
Axiom 4: an inner product of a vector with itself is never negative. We apply it to the vector x+ty for every t.
A proof starts by settling the cases. Fix y=O first, then test vectors.
Additivity and homogeneity in both slots, plus symmetry. This is a quadratic in t that never goes below 0.
You can only expand the expression once you have written it down.
This is the bottom of the parabola, and also the projection coefficient from the picture. Any t is allowed, so we may pick the best one.
To pick the bottom of the parabola you need the quadratic first.
Substitute t0 into the expansion: −2(x,y)2/(y,y)+(x,y)2/(y,y)=−(x,y)2/(y,y).
You need the value of t0 to substitute.
Multiply by (y,y)>0, which keeps the inequality, then take square roots of two non-negative numbers.
This clears the fraction, so the inequality with the fraction must come first.
So the angle is well defined.
Definition T
Orthogonal
For non-zero x,y in a Euclidean space, the angle between them is θ=arccos∥x∥∥y∥(x,y)∈[0,π]. The vectors x,y are orthogonal (written x⊥y) if (x,y)=0. This agrees with θ=π/2, and it also allows x=O, which is orthogonal to everything. A set S is orthogonal if (x,y)=0 for all different x,y in S.
In one lineTwo vectors are orthogonal when their inner product is 0; a set is orthogonal when every two different members are.
Why it existsIt is the abstract version of 'at right angles', and it is the property that makes coordinates and projections easy to compute.
Definition T
Orthonormal
A set is orthonormal if it is orthogonal and ∥x∥=1 for each member. Dividing any non-zero vector by its norm makes it have length 1: ∥x/∥x∥∥=1.
In one lineAn orthogonal set in which every vector has length 1.
Why it existsUnit lengths remove the division in every formula, so the coefficient of a vector is an inner product, with no division.
Why the old and the new angle agree. In R2 or R3, the cosine rule from the geometry you did in JEE says ∣x−y∣2=∣x∣2+∣y∣2−2∣x∣∣y∣cosθ. Expanding the left side with the dot product gives ∣x∣2+∣y∣2−2x⋅y. Comparing the two, x⋅y=∣x∣∣y∣cosθ. So the JEE formula is a theorem about the dot product, and in higher dimensions and in function spaces we turn it around into a definition.
Worked example
Find the angle between (1, 1, 0) and (0, 1, 1) in R³.
Solution.
Compute the inner product.(x,y)=1⋅0+1⋅1+0⋅1=1. The dot product is the inner product on R3.
Compute the norms.∥x∥=1+1+0=2 and ∥y∥=0+1+1=2. The norm is (x,x).
Form the cosine.cosθ=2⋅21=21. This is the definition of the angle. Cauchy–Schwarz guarantees this number lies in [−1,1].
Invert.θ=arccos21=60°. The inverse cosine of 21 is π/3.
Answer.θ=60°.
Your answerFind cosθ for the angle between (1,2,2) and (3,0,4).
Divide the dot product by the product of the two lengths.
(x,y)=3+0+8=11, ∥x∥=1+4+4=3, ∥y∥=9+0+16=5. So cosθ=3⋅511=1511.
Quick checkWhen does equality ∣(x,y)∣=∥x∥∥y∥ hold in the Cauchy–Schwarz inequality?
Equality means the angle has cosine ±1: the vectors lie on one line, which is dependence. Perpendicular vectors give the opposite extreme, (x,y)=0. Equal lengths say nothing about the angle.
Theorem TApostol Thm 1.9; Spagnolie Lecture 4
Properties of the norm
In a Euclidean space: (a) ∥x∥≥0, and ∥x∥=0 iff x=O. (b) ∥cx∥=∣c∣∥x∥ for every real c. (c) ∥x+y∥≤∥x∥+∥y∥.
In one line∥x∥≥0 with equality only for O; ∥cx∥=∣c∣∥x∥; and the triangle inequality ∥x+y∥≤∥x∥+∥y∥.
Why it is trueExpand ∥x+y∥2 and bound the cross term with Cauchy–Schwarz.
ProofSpagnolie Lecture 4; Apostol 1.9
The idea: (a) and (b) follow directly from the axioms. For (c), square both sides so that no square roots remain, expand, and use Cauchy–Schwarz on the one cross term.
(a) ∥x∥=(x,x)≥0, with 0 only for x=O.
Axiom 4: (x,x)>0 for x=O, and (O,O)=0.
(b) ∥cx∥=c2(x,x)=∣c∣∥x∥.
Homogeneity in each slot gives (cx,cx)=c2(x,x), and c2=∣c∣, not c.
(c) ∥x+y∥2=(x,x)+2(x,y)+(y,y)=∥x∥2+2(x,y)+∥y∥2.
Expand by additivity and symmetry, as in the Cauchy–Schwarz proof.
≤∥x∥2+2∥x∥∥y∥+∥y∥2=(∥x∥+∥y∥)2.
Cauchy–Schwarz: (x,y)≤∣(x,y)∣≤∥x∥∥y∥.
∥x+y∥≤∥x∥+∥y∥.
Both sides are non-negative, so taking square roots keeps the inequality.
Worked example Apostol 1.13 #3; MATH 375 HW3
Prove that (x, y) = 0 if and only if the norm of x + y equals the norm of x − y. Then deduce the parallelogram law and the polarization identity.
Solution.
Expand the sum.∥x+y∥2=(x+y,x+y)=∥x∥2+2(x,y)+∥y∥2. Additivity in both slots gives four terms, and symmetry makes the two cross terms equal.
Expand the difference.∥x−y∥2=∥x∥2−2(x,y)+∥y∥2. Same computation with −y in place of y. Homogeneity with c=−1 flips the sign of the cross term.
Subtract.∥x+y∥2−∥x−y∥2=4(x,y). The terms ∥x∥2 and ∥y∥2 cancel, and the cross terms add.
Both directions. If (x,y)=0 the two squares are equal, so the norms are equal (norms are non-negative). If the norms are equal, the left side of step 3 is 0, so (x,y)=0. Squaring and taking square roots are reversible for non-negative numbers.
Add instead of subtracting.∥x+y∥2+∥x−y∥2=2∥x∥2+2∥y∥2, the parallelogram law. Now the cross terms cancel. The picture: the two diagonals of a parallelogram have squared lengths adding to twice the sum of the squared sides.
Divide step 3 by 4.(x,y)=41(∥x+y∥2−∥x−y∥2), the polarization identity. The inner product can be recovered from the norm alone.
Answer.(x,y)=0 exactly when the two diagonals x+y and x−y have equal length, which for a parallelogram says it is a rectangle. The parallelogram law and polarization both follow from the same two expansions.
Beyond the course: for understanding· Norms without inner products
A norm in general is any function with properties (a), (b), (c), whether or not it comes from an inner product. Spagnolie lists ∥x∥1=∑∣xi∣, the p-norms (∑∣xi∣p)1/p, and ∥x∥∞=max∣xi∣. In the plane their unit “balls” (∥x∥=1) are a diamond, a circle and a square. Only the circle comes from an inner product; the others have no angle. Spagnolie’s non-example: ∥F∥=∫01F′(x)2dx on differentiable functions is not a norm. It is 0 for F=32, it scales like c2 instead of ∣c∣, and F(x)=g(x)=x gives ∥F+g∥=4>2=∥F∥+∥g∥, which breaks the triangle inequality. In machine learning the 1-norm gives sparse solutions (lasso), and the 2-norm used in this chapter gives least squares.
Worked example Apostol 1.13 #8, MATH 375 HW3
With weight log x on [1, e], find the norm of f(x) = √x, and a linear polynomial g = a + bx orthogonal to the constant 1.
Solution. The inner product is (f,g)=∫1e(logx)f(x)g(x)dx.
Squared norm of f.∥f∥2=∫1exlogxdx. f2=x, and the norm is the square root of (f,f).
Integrate by parts.∫1exlogxdx=[2x2logx]1e−∫1e2xdx=2e2−4e2−1=4e2+1. Take u=logx, dv=xdx.
Take the square root.∥f∥=21e2+1≈1.448.
Orthogonality to 1.(1,a+bx)=a∫1elogxdx+b∫1exlogxdx=a⋅1+b⋅4e2+1. ∫1elogxdx=[xlogx−x]1e=1, and the second integral is from step 2.
Set it to zero.a=−b4e2+1. Taking b=1: g(x)=x−4e2+1. One linear equation in two unknowns, so there is a whole line of answers; any multiple works.
Answer.∥x∥=21e2+1, and g(x)=x−4e2+1 (or any multiple) is orthogonal to 1.
Orthogonal sets and coordinates
Theorem TApostol Thm 1.10; Spagnolie Lecture 5
Orthogonal sets are independent
If x1,…,xk are non-zero and (xi,xj)=0 for i=j, then x1,…,xk are linearly independent.
In one lineAn orthogonal set of non-zero vectors is linearly independent.
Why it is trueTake the inner product of a supposed dependence with one member. Every cross term vanishes and one coefficient is isolated.
ProofSpagnolie Lecture 5; Apostol 1.12
The idea: Suppose a combination is O. Take the inner product with x₁: all terms except the first vanish, leaving c₁‖x₁‖² = 0. Repeat for each vector.
Suppose c1x1+⋯+ckxk=O.
The definition of dependence, to be refuted.
(x1,c1x1+⋯+ckxk)=0.
Take the inner product of both sides with x1. The inner product with O is 0.
c1(x1,x1)+c2(x1,x2)+⋯=c1∥x1∥2=0.
Additivity and homogeneity expand the left side. Orthogonality kills every (x1,xj) with j=1.
c1=0.
x1=O so ∥x1∥2>0. Divide by it.
Likewise every cj=0, so the set is independent.
Repeat with x2,…,xk in place of x1.
Quick checkTrue or false: every linearly independent set of non-zero vectors is orthogonal.
The theorem goes only one way. (1,0) and (1,1) are independent, but their dot product is 1, not 0. Independent means no waste; orthogonal means at right angles, which is much stronger.
Here is why orthogonal bases are worth the trouble. Suppose e1,…,en is an orthogonal basis and x=c1e1+⋯+cnen. The same trick isolates each coefficient.
Theorem TApostol Thm 1.11; Spagnolie Lecture 5
Coordinates in an orthogonal basis
Let e1,…,en be an orthogonal basis of V with all ei=O. Then for every x,
Take the inner product with ei. Additivity, homogeneity, and (ei,ej)=0 for j=i.
ci=(x,ei)/(ei,ei).
(ei,ei)>0 since ei=O.
∥x∥2=∑ci(x,ei)=∑(ei,ei)(x,ei)2.
(x,x)=(x,∑ciei)=∑ci(x,ei), and substitute ci from step 3.
Spagnolie warns about an easy mistake. The denominator is (ei,ei), which is ∥ei∥2 and not ∥ei∥. His unit check: x and ei have the same units (say metres), so the coefficient ci must have no units. (x,ei)/∥ei∥2 is metre-squared over metre-squared, which is fine. (x,ei)/∥ei∥ would be metre-squared over metre, which has units of length, so it cannot be right.
Worked example Spagnolie Lecture 5 (these vectors are built in the Gram–Schmidt example below)
Write z = (1, 2, 3) as a combination of the orthogonal vectors y1 = (1, 0, 1), y2 = (1/2, 1, -1/2), y3 = (-1/3, 1/3, 1/3).
Solution.
Check they are orthogonal.(y1,y2)=21+0−21=0, (y1,y3)=−31+0+31=0, (y2,y3)=−61+31−61=0. The coordinate formula needs an orthogonal basis. Three non-zero orthogonal vectors in R3 are independent, hence a basis.
Compute the denominators.(y1,y1)=2, (y2,y2)=23, (y3,y3)=31.
Compute the numerators.(z,y1)=1+3=4, (z,y2)=21+2−23=1, (z,y3)=−31+32+1=34.
Divide.c1=24=2, c2=3/21=32, c3=1/34/3=4. Coefficient = (inner product with yi) divided by (yi,yi). No equation system is solved.
Check.2(1,0,1)+32(21,1,−21)+4(−31,31,31)=(2+31−34,32+34,2−31+34)=(1,2,3). Adding the pieces back must give z.
Answer.z=2y1+32y2+4y3. For comparison, Spagnolie’s non-orthogonal basis x1=(1,0,0), x2=(1,1,0), x3=(1,1,1) and z=(0,1,1): taking inner products with each xi leaves a 3×3 system with matrix 111122123, whose solution is z=−x1+x3. That is the “annoying” computation that an orthogonal basis avoids.
Your answerIn an orthonormal basis q1,q2,q3 of R3 a vector x has (x,q1)=2, (x,q2)=−6, (x,q3)=3. What is ∥x∥?
Square the three coordinates, add, take the square root.
In an orthonormal basis ∥x∥2=∑(x,qi)2=4+36+9=49, so ∥x∥=7. No coordinates in the standard basis are needed.
Gram–Schmidt: making an orthogonal basis
Not every basis is orthogonal. The Gram–Schmidt process turns any basis into an orthogonal one with the same spans. Its idea is the picture at the top of the chapter, used repeatedly: to make a vector perpendicular to earlier ones, subtract its shadows on them.
Definition T
Gram–Schmidt process
Given independent x1,…,xk, the Gram–Schmidt process defines
Dividing each ym by its norm then gives an orthonormal list.
In one lineFrom independent vectors x1,x2,… build orthogonal vectors y1,y2,… by subtracting from each xk its projections on the earlier yj.
Why it existsIt turns any basis into an orthogonal (then orthonormal) one without changing what each initial segment spans.
Theorem TApostol Thm 1.13; Spagnolie Lecture 5
Gram–Schmidt theorem
If x1,…,xk are linearly independent, the vectors y1,…,yk above are non-zero, pairwise orthogonal, and L(y1,…,ym)=L(x1,…,xm) for each m. (Here L(⋅) is the span, Apostol’s notation.) Consequently every finite-dimensional Euclidean space has an orthonormal basis (Apostol Thm 1.14).
In one lineThe ym are non-zero and orthogonal, and y1,…,ym span the same space as x1,…,xm for every m.
Why it is trueEach step subtracts exactly the part of xm along the earlier yj, so what is left is perpendicular to them, and the subtraction does not change the span.
ProofSpagnolie Lecture 5; Apostol 1.13
The idea: Induction on m. Assume y₁,…,y_{m−1} are orthogonal and span the same as x₁,…,x_{m−1}. Then y_m is x_m minus a combination of earlier y's, so it is in the same span as x₁…x_m, it is not zero because x_m is outside the earlier span, and it is perpendicular to each earlier y_i by a one-line computation.
Base case m=1.
For m=1: y1=x1=O (independent vectors are non-zero), and the spans are equal.
Assume y1,…,ym−1 are non-zero, orthogonal, and L(y1,…,ym−1)=L(x1,…,xm−1).
The induction hypothesis: the claim holds for m−1.
L(y1,…,ym)=L(x1,…,xm).
By the formula, ym is xm minus a combination of y1,…,ym−1, which lie in L(x1,…,xm−1). Conversely xm=ym+ (a combination of yj), so xm∈L(y1,…,ym).
ym=O.
If ym=O, then xm would be a combination of y1,…,ym−1, hence of x1,…,xm−1, contradicting independence of the x's. (When Gram–Schmidt is applied to dependent vectors, a zero y appears, and that is how it reveals dependence: Apostol 1.17 #2(b).)
(yi,ym)=(yi,xm)−(yi,yi)(yi,xm)(yi,yi).
Take the inner product of the defining formula with yi for some i<m. By the induction hypothesis (yi,yj)=0 for j=i, so only the j=i term of the sum survives.
(yi,ym)=0 for every i<m. The claim holds for m, so by induction for all m.
The two terms are equal.
An orthonormal basis exists.
Start with any basis of the space, apply the process, divide each y by its norm.
Quick checkIn Gram–Schmidt, when we compute y3, which vectors do we subtract projections onto?
The formula only works when the vectors we project on are perpendicular to each other, so that the projections do not interfere. The yj are, but the xj usually are not. Projecting on x1 and x2 would remove some components twice.
Worked example Spagnolie Lecture 5 (with its arithmetic corrected)
Apply Gram–Schmidt to x1 = (1, 0, 1), x2 = (1, 1, 0), x3 = (0, 0, 1) in R³, then normalize.
Solution.
Keep the first vector.y1=x1=(1,0,1), with (y1,y1)=2. There is nothing earlier to be perpendicular to.
Remove the shadow of x2 on y1.(y1,x2)=1, so y2=x2−21y1=(21,1,−21), and (y2,y2)=23. This is the red dashed leftover of the picture at the top of the chapter.
Check.(y1,y2)=21+0−21=0. Checking each new vector against the earlier ones catches arithmetic slips immediately.
Remove both shadows from x3.(y1,x3)=1 and (y2,x3)=−21, so the coefficients are 21 and 3/2−1/2=−31. Then y3=x3−21y1+31y2=(−31,31,31). We project on the y‘s, not on x1,x2, because the y‘s are perpendicular, so the shadows do not interfere. The minus before −31 turns into a plus.
Check again.(y1,y3)=−31+31=0 and (y2,y3)=−61+31−61=0. Both are 0, so y1,y2,y3 are an orthogonal basis.
Normalize. Divide each y by its length 2, 3/2, 1/3 to get φ1,φ2,φ3. Unit lengths make the coefficient of each vector a plain inner product.
The step-through below shows the same computation with every product written out.
Answer.y1=(1,0,1), y2=(21,1,−21), y3=(−31,31,31) are orthogonal, and φ1,φ2,φ3 above are orthonormal. In the orthonormal basis the coordinates of z=(0,0,1) are (z,φi)=21,−61,31, and the squares add up to 21+61+31=1=∥z∥2, as the coordinate theorem says.
Your answerGram–Schmidt on x1=(3,4) and x2=(1,0) gives y1=x1 and y2=x2−(y1,y1)(y1,x2)y1. What is the length ∥y2∥?
Compute the coefficient first, then the vector, then its length. Divide by (y1,y1)=25, not by ∥y1∥=5.
(y1,x2)=3 and (y1,y1)=25, so y2=(1,0)−253(3,4)=(2516,−2512). Then ∥y2∥2=625256+144=2516 and ∥y2∥=54. Check: (y1,y2)=2548−48=0.
Worked example Apostol 1.17 #2(b), new numbers
Apply Gram–Schmidt to x1 = (1, 1, 0), x2 = (0, 1, 1), x3 = (1, 2, 1) in R³. What does the result say about the three vectors?
Solution.
First vector.y1=x1=(1,1,0), and (y1,y1)=2. The first vector is kept.
Second vector.(y1,x2)=1, so y2=x2−21y1=(−21,21,1), and (y2,y2)=23. Subtract the shadow of x2 on y1. Check: (y1,y2)=−21+21=0.
Third vector, the two coefficients.(y1,x3)=3 gives 23, and (y2,x3)=−21+1+1=23 gives 3/23/2=1. Divide by (yj,yj) in each case, as in the formula.
Subtract.y3=(1,2,1)−23(1,1,0)−1⋅(−21,21,1)=(1−23+21,2−23−21,1−0−1)=(0,0,0). The shadows on y1 and y2 account for all of x3.
Read the zero.y3=O means x3 lies in the span of x1,x2. If y3 were non-zero, the Gram–Schmidt theorem says it would be a new direction. A zero output is how the process reports dependence.
Check the dependence directly.x3=x1+x2, since (1,1,0)+(0,1,1)=(1,2,1). The conclusion agrees with a direct look at the vectors.
Answer.y3=O, so the three vectors are linearly dependent. The span is a plane with orthogonal basis y1,y2. Discard y3 and carry on with the next vector, if any.
Gram–Schmidt works in any Euclidean space, including a space of functions. Take polynomials on [−1,1] with (f,g)=∫−11f(t)g(t)dt. The monomials 1,t,t2,… are a basis but not orthogonal: (1,t2)=32=0.
Worked example Spagnolie Lecture 5 (Legendre polynomials)
Apply Gram–Schmidt to 1, t, t², t³ on [-1, 1] with (f, g) = ∫ f g dt.
Solution.
Start with the constant.y0=1, and (y0,y0)=∫−111dt=2. The first vector is kept.
Second vector.(y0,t)=∫−11tdt=0, so nothing is subtracted and y1=t, with (y1,y1)=32. t is odd and 1 is even; an odd function integrates to 0 over a symmetric interval.
Third vector.(y0,t2)=32 and (y1,t2)=∫t3=0. So y2=t2−22/3⋅1−0=t2−31. Coefficient of y0 is (y0,t2)/(y0,y0)=31. By the parity argument the y1 coefficient is 0.
Check.(y0,y2)=32−31⋅2=0 and (y1,y2)=∫(t3−t/3)dt=0. Always check orthogonality; it catches slips.
Fourth vector.(y1,t3)=∫t4=52, so the coefficient of y1 is 2/32/5=53. The coefficients of y0 and y2 are 0 by parity (odd times even). So y3=t3−53t. Same formula; t3 is odd, so it is orthogonal to the even y0 and y2 already.
Answer.1,t,t2−31,t3−53t, the Legendre polynomials. They are usually scaled so that the value at t=1 is 1: P2=21(3t2−1) and P3=21(5t3−3t).
Orthogonal complement and projection
Definition T
Orthogonal complement
For a subspace S of a Euclidean space V, the orthogonal complement is
S⊥={v∈V:(v,s)=0 for every s∈S}.
In one lineAll vectors orthogonal to every vector of a subspace S; written S⊥ ('S perp').
Why it existsIt collects exactly the leftover parts that projection throws away.
Theorem TApostol 1.15
The orthogonal complement is a subspace meeting S only at O
For a subspace S of V, S⊥ is a subspace of V, and S∩S⊥={O}. If S has a basis e1,…,ek, then v∈S⊥ if and only if (v,ei)=0 for each i.
In one lineS⊥ is a subspace, and the only vector in both S and S⊥ is O.
Why it is trueInner products are linear, so orthogonality passes through sums and multiples. A vector orthogonal to itself has zero length.
ProofApostol 1.15
The idea: Use the subspace test for the first part, then expand in the basis for the 'if and only if', and use positivity for the intersection.
O∈S⊥.
(O,s)=0 for every s.
If v,w∈S⊥ then v+w and cv are in S⊥. So S⊥ is a subspace.
Additivity and homogeneity in the first slot: (v+w,s)=(v,s)+(w,s)=0 and (cv,s)=c(v,s)=0.
So if (v,ei)=0 for all i, then (v,s)=0 for all s∈S. The converse is immediate.
Every s∈S is ∑aiei, and (v,∑aiei)=∑ai(v,ei).
S∩S⊥={O}.
If v∈S∩S⊥ then v can be used as the s: (v,v)=0, and axiom 4 gives v=O.
In R3, if S is a plane through the origin then S⊥ is the line through the origin perpendicular to it. Spagnolie’s picture: a plane S, a vector x above it, and a dotted perpendicular down to its foot in the plane.
Theorem TApostol Thm 1.15; Spagnolie Lecture 6
Orthogonal decomposition theorem
Let S be a subspace of a Euclidean space V with a finite basis. Then every x∈V can be written in exactly one way as x=s+s⊥, where s∈S and s⊥∈S⊥. Moreover ∥x∥2=∥s∥2+∥s⊥∥2 (Pythagoras).
In one lineIf S is a finite-dimensional subspace, every x splits uniquely as x=s+s⊥ with s∈S and s⊥∈S⊥, and ∥x∥2=∥s∥2+∥s⊥∥2.
Why it is trueTake s to be the sum of the shadows of x on an orthonormal basis of S. What is left over is perpendicular to every basis vector.
ProofSpagnolie Lecture 6; Apostol 1.15
The idea: Choose an orthonormal basis of S by Gram–Schmidt. Define s by the shadow formula and s⊥ = x − s. Check that s⊥ is orthogonal to each basis vector. Uniqueness comes from S ∩ S⊥ = {O}, and Pythagoras from s ⟂ s⊥.
Let q1,…,qk be an orthonormal basis of S.
Gram–Schmidt applied to a basis of S, then normalizing.
Define s=∑i(x,qi)qi and s⊥=x−s.
s is a combination of the qi, so it is in S. And s+s⊥=x by definition of s⊥.
(s⊥,qj)=(x,qj)−(s,qj)=(x,qj)−(x,qj)=0 for each j.
Expand (s,qj): only the i=j term survives because (qi,qj)=0 for i=j and (qj,qj)=1.
So s⊥∈S⊥. This proves existence.
Orthogonal to a basis of S means orthogonal to all of S (the previous theorem).
s−s′ lies in S∩S⊥.
Suppose x=s+s⊥=s′+s′⊥ are two splits. Subtracting, s−s′=s′⊥−s⊥. The left side is in S (a subspace) and the right side is in S⊥ (a subspace).
s=s′ and s⊥=s′⊥. This proves uniqueness (and shows the projection does not depend on the chosen basis).
S∩S⊥={O} from the previous theorem.
∥x∥2=∥s∥2+∥s⊥∥2.
(s,s⊥)=0 because s∈S and s⊥∈S⊥. Expanding (s+s⊥,s+s⊥), the cross terms vanish.
The proof shows that the piece s is well defined, so it gets a name.
Definition T
Projection
The vector s in the decomposition is the projection of x onto S, written projSx. If q1,…,qk is an orthonormal basis of S, it is s=∑i=1k(x,qi)qi. If e1,…,ek is an orthogonal basis, it is ∑(ei,ei)(x,ei)ei. For a line spanned by u it is (u,u)(x,u)u, the shadow in the picture.
In one lineThe S-part s of x=s+s⊥: the shadow of x on the subspace S.
Why it existsIt is the point of S that best stands in for x, which the next theorem proves.
Worked example Spagnolie Lecture 5/6, continuing the example above
Project x = (0, 0, 1) onto the plane S spanned by x1 = (1, 0, 1) and x2 = (1, 1, 0), and find its distance from the plane.
Solution.
Get an orthogonal basis of S. From the Gram–Schmidt example, y1=(1,0,1) and y2=(21,1,−21) are orthogonal and span the same plane. The projection formula needs an orthogonal basis; the original x1,x2 are not orthogonal.
Coefficients.(y1,y1)(x,y1)=21 and (y2,y2)(x,y2)=3/2−1/2=−31.
The projection.s=21(1,0,1)−31(21,1,−21)=(31,−31,32).
The leftover.s⊥=x−s=(−31,31,31), which is exactly the y3 of Gram–Schmidt. The last Gram–Schmidt vector is x3 minus its projection on the span of the earlier ones. This is the same computation.
The distance.∥s⊥∥=91+91+91=31≈0.577. The distance from a point to a plane is the length of the perpendicular.
Answer.projSx=(31,−31,32), at distance 1/3 from x. Check with Pythagoras: ∥x∥2=1=∥s∥2+∥s⊥∥2=96+93.
Your answerThe projection of x=(5,5) onto the line through u=(1,2) is cu. Find c.
Use c=(x,u)/(u,u). Divide by (u,u), not by ∥u∥.
c=(u,u)(x,u)=1+45+10=515=3, so the shadow is (3,6). The leftover x−cu=(2,−1) is perpendicular to u: 2−2=0.
Worked example Axler 6C
Let S be a subspace of a finite-dimensional Euclidean space. Prove that the orthogonal complement of S⊥ is S.
Solution.
The easy inclusion. Take s∈S. Every v∈S⊥ has (s,v)=0, so s is orthogonal to all of S⊥, that is, s∈(S⊥)⊥. This is the definition of S⊥ and of (S⊥)⊥, unpacked once each.
The hard inclusion: split a vector. Take x∈(S⊥)⊥ and write x=s+s⊥ with s∈S and s⊥∈S⊥. The orthogonal decomposition theorem gives this split for every vector. It needs S finite-dimensional, which holds here.
Show the leftover is zero.s⊥=x−s. Now x∈(S⊥)⊥ is orthogonal to s⊥∈S⊥, and s∈S is orthogonal to s⊥. So (s⊥,s⊥)=(x,s⊥)−(s,s⊥)=0−0=0. Both inner products are 0 for the reasons stated in this step.
Conclude. Axiom 4 gives s⊥=O, so x=s∈S. A vector with zero squared length is O.
Answer.(S⊥)⊥=S. In R3: the perpendicular line to the perpendicular line of a plane is the plane again.
Worked example MATH 375 Lecture 19, version 1
Let A be a real symmetric matrix and x, y eigenvectors with different eigenvalues λ and μ. Prove that x is perpendicular to y.
Solution.
Move A across the dot product.(Ax)⋅y=(Ax)Ty=xTATy=xTAy=x⋅(Ay). (AB)T=BTAT, and AT=A because A is symmetric. This is the only place symmetry is used.
Evaluate the left side.(Ax)⋅y=λ(x⋅y). Ax=λx, and a scalar comes out of the dot product.
Evaluate the right side.x⋅(Ay)=μ(x⋅y). Ay=μy.
Compare.(λ−μ)(x⋅y)=0. Steps 1 to 3 say λ(x⋅y)=μ(x⋅y).
Use that the eigenvalues differ.λ−μ=0, so x⋅y=0. A product of two numbers is 0 only if one of them is 0.
Answer.x⊥y. Check on S=[5225] from 2.8: the eigenvectors (1,1) for 7 and (1,−1) for 3 have dot product 1−1=0.
Best approximation
Now the payoff. The closest point of a subspace to x is its projection.
Theorem TApostol Thm 1.16; Spagnolie Lecture 6
Best approximation theorem
Let S be a finite-dimensional subspace of a Euclidean space V, let x∈V, and let s=projSx. Then for every t∈S,
∥x−t∥2=∥x−s∥2+∥s−t∥2≥∥x−s∥2,
with equality only when t=s.
In one lineAmong all points of S, the projection s is the unique closest point to x: ∥x−s∥≤∥x−t∥ for every t∈S.
Why it is trueFor any other point t of the subspace, the three points x, s, t form a right triangle with the right angle at s, so the hypotenuse xt is longer than the leg xs.
Go back to the picture and move the slider so the orange point slides along the line. The green arrow p is s, the orange point is t, the red dashed arrow is x−s, and the right-angle mark is the fact (x−s)⊥(s−t) that the proof uses. The “distance to the orange point” in the readout is always larger than the distance to the shadow, and its square exceeds the shadow’s by exactly the squared length from the shadow to the orange point.
ProofSpagnolie Lecture 6; Apostol 1.16
The idea: Write x − t as the sum of two pieces: x − s, which is perpendicular to S, and s − t, which lies in S. The pieces are perpendicular, so Pythagoras applies.
x−t=(x−s)+(s−t).
Add and subtract s. In the picture: the hypotenuse from x to the orange point t is the sum of the red leg x−s and the leg along the line, s−t.This is the red dashed arrow plus the segment from the shadow to the orange point.
So (x−s,s−t)=0.
x−s=s⊥∈S⊥ by the decomposition theorem. And s−t∈S, since both s and t are in the subspace S.
∥x−t∥2=∥x−s∥2+∥s−t∥2.
Expand (x−t,x−t) using the two pieces. The cross terms are 2(x−s,s−t)=0.This is Pythagoras on the right angle marked in the picture.
∥x−t∥2≥∥x−s∥2, so ∥x−t∥≥∥x−s∥.
A square is never negative.
Equality holds only for t=s.
Equality needs ∥s−t∥=0, and axiom 4 gives s−t=O.
Proof workshopGive the reason for each line: the projection is the closest point
Each line of the proof is shown in order. Choose the reason that justifies it, then press Check.
x−t=(x−s)+(s−t)
(x−s,s−t)=0
∥x−t∥2=∥x−s∥2+∥s−t∥2
∥x−t∥≥∥x−s∥
t=s if the two distances are equal
The squared error has a neat formula too. Since x−s=s⊥, Pythagoras from the decomposition theorem gives ∥x−s∥2=∥x∥2−∥s∥2. With an orthonormal basis qi of S, that is ∥x∥2−∑(x,qi)2. In particular ∑i(x,qi)2≤∥x∥2 (Bessel’s inequality), since the error cannot be negative.
Your answerq1,q2 are orthonormal vectors and x has ∥x∥2=30, (x,q1)=3, (x,q2)=4. What is the squared distance from x to the plane spanned by q1 and q2?
Squared error = ∥x∥2 minus the sum of the squared coefficients.
The projection onto the plane is s=3q1+4q2, with ∥s∥2=9+16=25. The squared distance is ∥x∥2−∥s∥2=30−25=5.
Worked example Apostol 1.17 #8, MATH 375 HW4
Find the linear polynomial g nearest to f(t) = e^t on [-1, 1], with (f, g) = ∫ f g dt, and the squared error.
Solution. The family of linear polynomials S={a+bt} is a 2-dimensional subspace of C[−1,1].
Orthonormal basis of S. From the Legendre example, y0=1 and y1=t are orthogonal, with (y0,y0)=2 and (y1,y1)=32. So φ0=21 and φ1=23t. The projection formula in this simple form needs an orthonormal basis.
Two integrals.I0=∫−11etdt=e−e−1 and I1=∫−11tetdt=[tet−et]−11=2e−1. Integration by parts. These are the inner products of f with 1 and with t.
Projection.g=(f,φ0)φ0+(f,φ1)φ1=2I0+23I1t=2e−e−1+e3t≈1.1752+1.1036t. (f,φ0)φ0=2I0⋅21 and (f,φ1)φ1=23I1t.
Squared error.∥f−g∥2=∥f∥2−∥g∥2=2e2−e−2−(2I02+23I12)=1−7e−2≈0.0527. The error formula above. Here 2I02=2e2−2+e−2 and 23I12=6e−2.
Check numerically.∥f∥2=3.6269, ∥g∥2=2.7622+0.8120=3.5742, difference 0.0527. A second route to the same number.
Answer.g(t)=21(e−e−1)+3e−1t, with squared error 1−7/e2≈0.0527. (Calculus gives the same by minimizing ∥f−a−bt∥2 over a,b: setting the two partial derivatives to zero gives the same a,b. Those equations are the “normal equations” of chapter 2.10.)
Quick checkIn the best approximation theorem, why is the projection s closer to x than any other point t of S?
The right angle at s is the whole reason: x−s is perpendicular to s−t, so Pythagoras gives ∥x−t∥2=∥x−s∥2+∥s−t∥2. The projection does not in general have the same length as x (it is shorter), and 'largest inner product' is not the criterion.
Fourier series: best approximation by waves
Where this came from· Heat, waves and least squares
Fourier presented his memoir on how heat spreads through a solid body to the Paris Institute in December 1807 (the book Théorie analytique de la chaleur followed in 1822). He wrote the starting temperature as a sum of sine and cosine waves, because the heat equation treats each wave separately (each one fades at its own rate), and added the results. Lagrange, one of the committee that read the memoir, objected to expanding an arbitrary function in a trigonometric series. The inner-product view of this chapter explains the practical side: the coefficients are inner products, and a partial sum is a best approximation. Gram (1883) studied expanding functions in series by least squares and gave the orthogonalization process there. Erhard Schmidt (1907) used the process for integral equations, and acknowledged Gram’s earlier work. The process now carries both names, although Laplace was already familiar with the idea.
Take V=C[0,2π] with (f,g)=∫02πf(x)g(x)dx. The functions
are orthonormal. (The check uses the product-to-sum identities. The next example does the cosine case on [0,π], and on [0,2π] the computation is the same.) Let Sn be the span of the first 2n+1 of them. By the best approximation theorem, the closest function in Sn to f is the projection, whose coefficients are inner products:
sn=j=0∑2n(f,φj)φj,(f,φj)=∫02πf(x)φj(x)dx.
This is the partial Fourier series of f. “Closest” means smallest ∫02π(f−s)2, the root-mean-square error. The infinite sum is a different matter (the φj are an orthonormal “basis” only in a limiting sense, which analysis in MATH 521 makes precise), and we use only partial sums and their errors.
Worked example Apostol 1.17 #3, MATH 375 HW3
Show that cos(mt) and cos(nt) are orthogonal on [0, π] for m ≠ n, and find the norm of cos(nt).
Solution.
Use the product-to-sum identity.cosmtcosnt=21[cos(m+n)t+cos(m−n)t]. Turns a product into a sum of two cosines, each easy to integrate.
Integrate for m=n.∫0πcosmtcosntdt=21[m+nsin(m+n)t+m−nsin(m−n)t]0π=0. sin of an integer multiple of π is 0, and both denominators are non-zero.
Integrate for m=n≥1.∫0πcos2ntdt=21∫0π(cos2nt+1)dt=2π. Now m−n=0, so the second cosine is the constant 1.
For n=0:∫0π1dt=π.
Normalize.y0=π1 and yn=π2cosnt are orthonormal. Divide each function by its norm, π and π/2.
Answer. The cosines are orthogonal, with ∥1∥2=π and ∥cosnt∥2=π/2.
Worked example Spagnolie Lecture 6 (the Mathematica example), numbers computed here
Approximate the triangle wave f(x) = x on [0, π], 2π − x on [π, 2π] by constants, then by a constant plus a cosine, and measure the error.
Solution.
The squared length of f.∥f∥2=2∫0πx2dx=32π3≈20.671. The two halves are mirror images.
Best constant. The coefficient on φ0 is (f,φ0)=2π1∫02πf=2ππ2, so the best constant is 2ππ2⋅2π1=2π, the average height of the wave. Its squared “energy” is (f,φ0)2=2π3≈15.503. The area under the triangle is π2. The projection onto the constants is the average value.
Error of the best constant.∥f−2π∥2=32π3−2π3=6π3≈5.168. Error =∥f∥2−∥s∥2, from the best approximation theorem.
The cosine term.(f,φ1)=π1∫02πf(x)cosxdx=−π4≈−2.257. (The sine coefficient is 0 because f is symmetric about x=π.) Integration by parts on each half; the answer matches a numerical integration.
Add it.s=2π−π4cosx. The squared energy added is (f,φ1)2=π16≈5.093, so the new error is 6π3−π16≈0.0748. Each new orthonormal function removes exactly its coefficient squared from the error.
Read the result. Two terms already remove 98.6% of the error left by the constant. Adding cos3x (energy 81π16) brings the error to 0.0119, and cos5x to 0.0037. The coefficients fall off like 1/k2 for this wave because it has corners but no jumps. This is the shape of the three Mathematica plots in Spagnolie’s Lecture 6.
Answer.f≈2π−π4(cosx+9cos3x+25cos5x+⋯). At x=0 the two-term version gives 2π−π4=0.30 where the true value is 0.
Where it is used
Used inside maths· Inside maths: a sum of 1/k⁴ from Pythagoras
For the triangle wave, the squared length of f is the sum of the squares of its coefficients (Parseval’s equality, which holds because the trigonometric system is complete; Bessel’s inequality above gives only "≤", and completeness, which is MATH 521 material, gives "="). The nonzero coefficients are the constant and the cosines of odd frequency k, and the square of the coefficient of coskx is πk416. So
A numerical check: π4/96=1.014678…, and the first terms 1+0.012346+0.0016+0.00042+⋯ add to the same. An infinite sum, found by applying Pythagoras in a function space.
Used in the real world· Signal processing: a Fourier coefficient is an inner product
An audio signal on one second of time, x(t)=3cos(2π⋅5t)+sin(2π⋅12t), is a mix of a 5 Hz cosine and a 12 Hz sine. To find how much of the 5 Hz cosine is present, take the inner product on [0,1]: (x,cos2π5t)=23 and (cos2π5t,cos2π5t)=21, so the amount is 1/23/2=3, which is right. Likewise (x,sin2π12t)=21 gives amount 1. The inner product with any other frequency (say cos2π12t, sin2π5t or cos2π7t) is 0, because the waves are orthogonal. This is exactly the coordinate theorem for an orthogonal basis. A JPEG file does the same with a cosine basis: each 8×8 block of pixels is treated as a vector with 64 numbers and expanded in 64 orthonormal cosine patterns; the small coefficients are thrown away. By the best approximation theorem, keeping the largest coefficients gives the closest picture that uses that many patterns. MP3 applies a related cosine transform to short frames of audio.
Used in the real world· Search and AI: cosine similarity
A text-embedding model turns each word or sentence into a vector (hundreds or thousands of numbers). Similar meanings should give similar directions, so the similarity is the cosine of the angle, defined above. Toy example with three numbers: king=(0.9,0.8,0.1), queen=(0.85,0.75,0.2), apple=(0.1,0.2,0.95). Then (king,queen)=1.385, with norms 1.208 and 1.151, so cosθ=0.9958 and θ≈5.3°. But (king,apple)=0.345 with norms 1.208 and 0.976 gives cosθ=0.293, θ≈73°. Cauchy–Schwarz is what guarantees every such number lies in [−1,1], whatever the dimension. Multiplying a vector by 10 changes the inner product but not the cosine, so similarity ignores length. A transformer’s attention scores q⋅k are inner products of the same kind.
A preview· Preview: the closest point is least squares (chapter 2.10)
A GPS receiver measures its distance to four or more satellites. Each measurement is one equation in four unknowns (three position coordinates and the receiver’s clock error). With more than four equations and noisy measurements there is usually no exact solution. The fix is to find the vector of unknowns whose predicted measurements are closest to the actual ones. The predicted measurements lie in a subspace (the span of the columns of a matrix), so the closest point is the projection of the data onto that subspace, and the error vector is perpendicular to it. Chapter 2.10 turns this into a formula. Fitting a line to data points works the same way, as in the et example above where the “data” is a whole function.
Beyond the course: for understanding· QR decomposition: Gram–Schmidt written as a matrix factorization
Let A have the columns x1,x2,x3 of the Gram–Schmidt example. Put the orthonormal vectors φ1,φ2,φ3 as the columns of a matrix Q. Since xm is ym plus a combination of earlier y‘s, each xm is a combination of φ1,…,φm with coefficients rim=(φi,xm), and so A=QR with R upper triangular. Here
and one can check QR=A entry by entry (for example the first column is 2φ1=(1,0,1)). This factorization is how numerical software solves least-squares problems, because Q has perpendicular unit columns and so does not magnify errors, and R is solved by back-substitution. In practice the classical process above loses perpendicularity to rounding errors on hard matrices, so libraries use Householder reflections or the “modified” Gram–Schmidt instead.
Beyond the course: for understanding· Orthogonal polynomials
Changing the interval or the weight in the inner product gives other families by the same process. On [−1,1] with weight 1, Gram–Schmidt on 1,t,t2,… gives the Legendre polynomials (electrostatic potentials, Gaussian quadrature). With weight 1/1−t2 you get Chebyshev polynomials (used for stable polynomial approximation). On [0,∞) with weight e−t it gives the Laguerre polynomials: 1,t−1,t2−4t+2,t3−9t2+18t−6 (Apostol 1.17 #5). With weight e−t2 on the whole line you get Hermite polynomials, which describe the quantum harmonic oscillator. All of them are one idea: the inner product decides what “orthogonal” means.
Traps
Watch out· Orthogonal depends on the inner product
With the dot product (1,1) and (1,−1) are orthogonal. With (x,y)=x1y1+2x2y2 their inner product is 1−2=−1, so they are not. In function spaces, whether 1 and t2 are orthogonal depends on the interval and the weight: on [−1,1] with weight 1 they are not (32). Always say which inner product.
Watch out· Orthogonal implies independent, not the reverse; and O is excluded
An orthogonal set of non-zero vectors is independent. An independent set need not be orthogonal ((1,0) and (1,1)). And the zero vector is orthogonal to everything, so including it in a list breaks the theorem: {O,x} is orthogonal but dependent.
Watch out· Gram–Schmidt: project onto the y's, divide by (y, y)
Two slips: projecting x3 onto the original x1,x2 (they are not perpendicular, so you remove some directions twice), and dividing by ∥y∥ instead of (y,y)=∥y∥2. A third: arithmetic. Spagnolie’s own class notes got a=1 and b=+31 for the example above, instead of 21 and −31, and the resulting y3 was not orthogonal to y1. Always check (yi,yj)=0 at the end. A zero vector appearing means the x‘s were dependent.
Watch out· Adding projections works only for an orthogonal basis
Let S=R2 with the basis (1,0),(1,1) and x=(0,1). Projecting x onto each basis vector separately gives (0,0) and (21,21), and their sum (21,21) is not x, though x is in S. The sum-of-shadows formula needs the basis vectors to be perpendicular.
Watch out· The norm scales by |c|, and not every integral is a norm
∥cx∥=∣c∣∥x∥. A student summary sheet wrote c∥x∥, which would give negative lengths for negative c. And ∫F′2 (the example in the beyond-box) fails all three norm rules. Check the rules before calling something a norm.
Watch out· Fourier 'basis' and cosine similarity are used loosely
A Fourier “basis” is infinite, so the expansion of f is a limit, and a statement like ”f equals its Fourier series” needs a notion of convergence (and at jumps it is false pointwise). Cosine similarity ignores length: two vectors pointing the same way are “identical” however different their sizes. Be sure that is what you want.
Problems
check
Is (x,y)=x1y1+2x2y2 an inner product on R2? Are (1,1) and (1,−1) orthogonal for it?
Solution
Symmetry, additivity and homogeneity are clear (it is the dot product with the second coordinate weighted by 2). Positivity: (x,x)=x12+2x22>0 unless x=O. So yes, it is an inner product. ((1,1),(1,−1))=1−2=−1=0, so they are not orthogonal for it, although they are for the dot product.
check
In C[−1,1] with (f,g)=∫−11fgdt, are 1 and t2 orthogonal? Are t and t2−31?
Solution
(1,t2)=∫−11t2dt=32=0: not orthogonal (Spagnolie’s example showing the monomials are not orthogonal). (t,t2−31)=∫−11(t3−3t)dt=0 since the integrand is odd: orthogonal.
check
For x=(3,4) and y=(4,3) in R2, compute (x,y), ∥x∥, ∥y∥ and check Cauchy–Schwarz.
Solution
(x,y)=12+12=24. ∥x∥=∥y∥=5. Then ∣(x,y)∣=24≤25=∥x∥∥y∥. The cosine of the angle is 24/25=0.96 (θ≈16.3°). They are not dependent, so the inequality is strict.
check
An orthonormal basis q1,q2 of R2 is given, and x has (x,q1)=3 and (x,q2)=−4. What is ∥x∥?
Solution
x=3q1−4q2, so ∥x∥2=32+(−4)2=25 and ∥x∥=5.
useApostol 1.17 #2(b), MATH 375 HW3
Apply Gram–Schmidt to x1=(1,1,0,1), x2=(1,0,2,1), x3=(1,2,−2,1) in R4 and find an orthonormal basis of their span.
Solution
y1=x1, (y1,y1)=3. (y1,x2)=2, so y2=x2−32y1=(31,−32,2,31)=31(1,−2,6,1) and (y2,y2)=314. For x3: (y1,x3)=4 and (y2,x3)=31(1−4−12+1)=−314. So y3=x3−34y1+1⋅y2=(1−34+31,2−34−32,−2+2,1−34+31)=(0,0,0,0). A zero vector means x3 was dependent on x1,x2 (x3=34x1−y2). Discard it. The span is 2-dimensional with orthonormal basis 31(1,1,0,1) and 421(1,−2,6,1) (since ∥(1,−2,6,1)∥2=42).
useApostol 1.17 #6, MATH 375 HW4
In C[1,3] with (f,g)=∫13fgdx, find the constant function nearest to f(x)=1/x and the squared error.
Solution
The constants form a 1-dimensional subspace with orthonormal basis φ0=1/2 (since ∫131=2). The nearest constant is (f,φ0)φ0=21∫13x1dx=21log3≈0.549 (the average value of 1/x). The squared error is ∥f∥2−∥g∥2=∫13x−2dx−2⋅(21log3)2=32−21(log3)2≈0.0632, so the distance from f to the nearest constant is 0.0632≈0.251.
use
Project x=(1,2,3) onto the plane S spanned by (1,1,0) and (0,1,1). Find the projection, the perpendicular part, and the distance from x to the plane.
Solution
Make an orthogonal basis: y1=(1,1,0), and y2=(0,1,1)−21(1,1,0)=(−21,21,1) (since (y1,(0,1,1))=1 and (y1,y1)=2). Then (x,y1)=3, so the coefficient is 23; (x,y2)=−21+1+3=27 and (y2,y2)=23, so the coefficient is 37. The projection is 23(1,1,0)+37(−21,21,1)=(31,38,37). The perpendicular part is x−s=(32,−32,32). Check: its inner products with (1,1,0) and (0,1,1) are both 0. The distance is ∥(32,−32,32)∥=32≈1.155.
useApostol 1.17 #5, MATH 375 HW3
On the functions with ∫0∞e−tf2dt<∞, with (f,g)=∫0∞e−tfgdt, apply Gram–Schmidt to 1,t,t2. (Use In=∫0∞e−ttndt=n!.)
Solution
y0=1, (y0,y0)=I0=1. For y1=t−ay0: a=(y0,t)/(y0,y0)=I1=1, so y1=t−1, with (y1,y1)=I2−2I1+I0=2−2+1=1. For y2=t2−ay0−by1: a=I2=2 and b=(y1,t2)/(y1,y1)=(I3−I2)/1=6−2=4. So y2=t2−2−4(t−1)=t2−4t+2. (Check: (y0,y2)=I2−4I1+2I0=2−4+2=0.)
proveApostol 1.13 #3, MATH 375 HW3
Prove that (x,y)=0 if and only if ∥x+y∥=∥x−y∥, in any Euclidean space.
Solution
Expand: ∥x+y∥2=∥x∥2+2(x,y)+∥y∥2 and ∥x−y∥2=∥x∥2−2(x,y)+∥y∥2. Subtracting, ∥x+y∥2−∥x−y∥2=4(x,y). If (x,y)=0 the squares are equal, and norms are non-negative, so ∥x+y∥=∥x−y∥. Conversely, equal norms give 4(x,y)=0. (Geometrically: the two diagonals of a parallelogram have equal length exactly when it is a rectangle.)
proveApostol 1.13 exercises
Prove the parallelogram law ∥x+y∥2+∥x−y∥2=2∥x∥2+2∥y∥2 and the polarization identity (x,y)=41(∥x+y∥2−∥x−y∥2).
Solution
From the two expansions in the previous solution, adding gives 2∥x∥2+2∥y∥2, which is the parallelogram law, and subtracting gives 4(x,y), which is polarization. So the inner product can be recovered from the norm alone.
provefollows Apostol 1.15 and 1.16
Prove Bessel’s inequality: if q1,…,qk are orthonormal, then ∑i=1k(x,qi)2≤∥x∥2 for every x.
Solution
Let S=L(q1,…,qk) and s=projSx=∑(x,qi)qi. The qi are orthonormal, so ∥s∥2=∑(x,qi)2 (the coordinate theorem). By the decomposition theorem, ∥x∥2=∥s∥2+∥s⊥∥2≥∥s∥2. So ∑(x,qi)2≤∥x∥2, with equality exactly when s⊥=O, that is, when x∈S.
proveAxler 6C
Let V be finite-dimensional and S a subspace. Prove (S⊥)⊥=S.
Solution
(⊇) If s∈S and v∈S⊥, then (s,v)=0, so s is orthogonal to every vector of S⊥, that is, s∈(S⊥)⊥. (⊆) Let x∈(S⊥)⊥ and write x=s+s⊥ with s∈S, s⊥∈S⊥ (decomposition theorem). Then s⊥=x−s. Now x∈(S⊥)⊥ is orthogonal to s⊥, and s∈S is also orthogonal to s⊥. So (s⊥,s⊥)=(x−s,s⊥)=(x,s⊥)−(s,s⊥)=0−0=0, and axiom 4 gives s⊥=O. Hence x=s∈S.
Let A be a real symmetric matrix (AT=A) and let x,y be eigenvectors of A with different eigenvalues λ=μ (see 2.8). Prove x⊥y for the dot product.
Solution
Use (Ax)⋅y=(Ax)Ty=xTATy=xTAy=x⋅(Ay), which holds because AT=A. Then (Ax)⋅y=λ(x⋅y) and x⋅(Ay)=μ(x⋅y). So (λ−μ)(x⋅y)=0, and since λ=μ, x⋅y=0. This is why the ellipse 5x2+4xy+5y2=1 of 2.8 had perpendicular axes, and it is half of the spectral theorem (chapter 3.1).
stretch
Let S be a finite-dimensional subspace of V and P(x)=projSx. Prove that P is a linear map with P∘P=P, range S, and null space S⊥. If V is finite-dimensional, deduce dimV=dimS+dimS⊥.
Solution
Linearity: with an orthonormal basis qi of S, P(x)=∑(x,qi)qi, and x↦(x,qi) is linear by additivity and homogeneity. For s∈S, the decomposition of s is s+O, so P(s)=s. Every P(x) is in S, so P(P(x))=P(x), and the range is exactly S. P(x)=O means x=O+s⊥, so x∈S⊥; conversely x∈S⊥ has decomposition O+x, so P(x)=O. Thus N(P)=S⊥. By rank–nullity (2.3): dimV=rankP+nullityP=dimS+dimS⊥.
stretch
Prove that ∥x+y∥=∥x∥+∥y∥ holds if and only if one of x,y is a non-negative multiple of the other.
Solution
Square both sides: ∥x∥2+2(x,y)+∥y∥2=∥x∥2+2∥x∥∥y∥+∥y∥2, so equality holds iff (x,y)=∥x∥∥y∥. If y=O or x=O this is true and one is 0 times the other. Otherwise this is equality in Cauchy–Schwarz (with a plus sign), which requires x=cy for some c. Then (cy,y)=c∥y∥2 and ∥cy∥∥y∥=∣c∣∥y∥2, so c=∣c∣, that is, c≥0. Conversely, if x=cy with c≥0, both sides equal (c+1)∥y∥.
Summary
An inner product(x,y) is symmetric, additive, homogeneous, and positive on non-zero vectors. The dot product is one; ∫fg is another. From it we define the norm∥x∥=(x,x) and the angle cosθ=(x,y)/(∥x∥∥y∥). JEE derived the dot product’s cosine formula; we define the angle by it.
Cauchy–Schwarz∣(x,y)∣≤∥x∥∥y∥ (proof: the parabola ∥x+ty∥2≥0 at its lowest point) is what makes the angle defined. It gives the triangle inequality.
Orthogonal means (x,y)=0. Orthogonal non-zero vectors are independent. In an orthogonal basis the coordinate of x on ei is (x,ei)/(ei,ei), with no equations to solve.
Gram–Schmidt builds an orthogonal basis from any basis: subtract from each vector its projections on the earlier y‘s. A zero output means dependence. The Legendre polynomials come from doing it to 1,t,t2,….
Orthogonal complementS⊥; every x splits uniquely as s+s⊥ (the projection plus a perpendicular leftover) and ∥x∥2=∥s∥2+∥s⊥∥2.
Best approximation: the projection is the unique closest point of S to x. Proof: Pythagoras on the right triangle x,s,t. The error is ∥x∥2−∥s∥2.
Fourier coefficients are inner products with orthonormal waves, and a partial Fourier sum is a projection. Cosine similarity, JPEG, the least squares of chapter 2.10 and QR decomposition are the same picture.
Watch and read
The same ideas explained by someone else. Use these when an explanation here does not land.
MATH 521: Cauchy–Schwarz and the triangle inequality are the first tools of analysis. The same proofs work in the space of square-summable sequences and in function spaces, where the 'basis' is infinite.
MATH 376: Fourier series solve the heat and wave equations. The coefficients are the inner products computed below, and each partial sum is a projection.
CS 532 / AI: Cosine similarity of embeddings is the angle defined here. QR decomposition (Gram–Schmidt on the columns of a matrix) is how least squares is solved on a computer.
MATH 541: Inner products over the complex numbers (Hermitian), and Hilbert spaces, where the closest-point theorem still holds.