9.6  Projection onto a Line and the Cosine of an Angle

Section 9.5 bounded the dot product by lengths, |⟨x,y⟩|≤‖x‖‖y‖. This section asks a new question: given a point x and a line through the origin, which point of the line is nearest to x? The answer splits x into a piece along the line and a piece orthogonal to it. Divided by lengths, the same split gives a number between −1 and 1 that measures how far two directions agree, the cosine of the angle between them.

9.6.1. The nearest point on a line through the origin

Fix y∈Rn with y≠0. The multiples ty, for t∈R, form the line through the origin in the direction of y. Take a point x∈Rn. Among all ty, which one is nearest to x? In the plane a picture answers: drop a perpendicular from x to the line, and its foot is the nearest point. In R5 there is no picture, but the picture suggests a guess to test.

Try a concrete case first. Let x=(3,1) and y=(1,1). The squared distance from x to ty is ‖x−ty‖2=(3−t)2+(1−t)2=2t2−8t+10=2(t−2)2+2. The last form shows the answer at once: the squared distance is at least 2, and it equals 2 only at t=2. So the nearest point is 2y=(2,2), and the distance is 2. Now look at the error: x−2y=(1,−1), and ⟨(1,−1),(1,1)⟩=0. The error is orthogonal to the line, as the picture promised.

Completing the square worked but hid the reason. In any Rn we guess that the error is orthogonal and check the guess with Pythagoras.

Idea (Scratch work). We plan the search with a table.

We know We want
x,y∈Rn, y≠0 find t with ‖x−ty‖≤‖x−sy‖ for every s∈R
guess: the error is perpendicular, ⟨x−ty,y⟩=0 solve ⟨x,y⟩−t‖y‖2=0: t0=⟨x,y⟩/‖y‖2, allowed since ‖y‖2≠0
x−t0y⊥y compare x−sy with x−t0y for an arbitrary s
x−sy=(x−t0y)+(t0−s)y, two orthogonal pieces Pythagoras: ‖x−sy‖2=‖x−t0y‖2+(t0−s)2‖y‖2

The last row closes the gap: the extra term (t0−s)2‖y‖2 is never negative, so no s beats t0. The picture supplied only the guess; Pythagoras supplies the proof.

The number t0=⟨x,y⟩/‖y‖2 and the point t0y come back in this section and in Chapter 10, so they get a name.

Definition 9.6.1 (Projection onto a Line)

Let x,y∈Rn with y≠0. The projection of x onto y is the vector projyx:=⟨x,y⟩‖y‖2y.

The projection is the multiple of y that leaves an error orthogonal to y.

In words: projyx is a vector, a scalar multiple of y. The scalar is the number ⟨x,y⟩ divided by the square of the length of y. Recall that ‖y‖2=⟨y,y⟩ (Proposition 9.4.1 (c)). This number is positive exactly when y≠0 (Proposition 9.3.1 (c)).

Examples.

  • A unit vector. If ‖u‖=1, the denominator is 1, and projux=⟨x,u⟩u.
  • A standard vector. The vector ek is a unit vector (Proposition 9.4.1 (e)). For u=ek this gives projekx=⟨x,ek⟩ek=xkek, by Proposition 9.3.1 (d). Projecting onto the k-th axis keeps the k-th coordinate and sets the others to 0. For x=(3,−1,2) and k=3, it gives (0,0,2).
  • The opening example. For x=(3,1) and y=(1,1), ⟨x,y⟩=4 and ‖y‖2=2, so projyx=2y=(2,2), the point found above.
  • Two extreme cases. If x⊥y, the coefficient is 0, and projyx=0: the nearest point of the line to a point orthogonal to it is the origin. At the other extreme, if x=cy then projyx=(c‖y‖2/‖y‖2)y=x: a point already on the line is its own projection.

When y=0. Keep x=(3,1) and change y=(1,1) to y=(0,0). The formula now divides by ‖y‖2=0, so it defines nothing. The question does not survive either: every ty is 0, so all of them are at the same distance ‖x‖ from x, and “the” nearest point is no longer a single t. This is why the definition requires y≠0.

Why this definition. Dividing by ‖y‖ instead of ‖y‖2 would give 22(1,1)≠(2,2) for y=(1,1) and x=(3,1), and its error is not orthogonal to y. The square makes the answer independent of the length of y, as Exercise B2 (c) shows: the projection depends on the line, not on the vector chosen to name it.

Quick check. Compute proj(1,0)(2,3) and proj(2,0)(2,3). Are they equal?

Solution. For y=(1,0): ⟨(2,3),(1,0)⟩=2 and ‖y‖2=1, so the projection is 2(1,0)=(2,0). For y=(2,0): ⟨(2,3),(2,0)⟩=4 and ‖y‖2=4, so it is 1⋅(2,0)=(2,0). They are equal, because (1,0) and (2,0) name the same line.

The scratch work above is a proof method.

Example (Method: subtract the projection)

How it goes. Given x and y≠0, write x=p+(x−p),p:=projyx. The piece x−p is orthogonal to y, hence to every multiple of y. So Pythagoras (Proposition 9.4.4) splits the length of any vector of the form (x−p)+cy: its square is ‖x−p‖2+c2‖y‖2.

When to use it. Distances from a point to a line through the origin; inequalities between ⟨x,y⟩ and lengths; any problem where a vector should be split into “along y” and “orthogonal to y”.

Common mistakes. It is easy to forget that y≠0 is needed before anything is divided. It is also easy to project onto the wrong vector: projyx and projxy are different in general, as Exercise B2 (e) shows. Finally, dividing by ‖y‖ instead of ‖y‖2 leaves an error that is not orthogonal to y.

The closest-point theorem below is proved this way, and Example (Distance to a line through the origin) uses it on numbers.

The theorem turns the scratch work into a proof, and adds an exact identity for the cost of a wrong choice of t.

Theorem 9.6.1 (The Projection Is the Closest Point)

Let x,y∈Rn with y≠0, let t0:=⟨x,y⟩/‖y‖2, and let p:=t0y=projyx.

  • (a) x−p⊥y, and t0 is the only t∈R with x−ty⊥y.
  • (b) For every t∈R, ‖x−ty‖2=‖x−p‖2+(t−t0)2‖y‖2. Hence ‖x−ty‖≥‖x−p‖, with equality if and only if t=t0.
  • (c) ‖x‖2=‖p‖2+‖x−p‖2, and ‖p‖=|⟨x,y⟩|/‖y‖.

Try it first (ten minutes): for x=(3,1) and y=(1,1) we minimized ‖x−ty‖2 by completing the square in t. Do the same for general x and y≠0: expand ‖x−ty‖2 as a quadratic in t and complete the square.

Idea. The attempt succeeds. Expanding gives ‖y‖2t2−2⟨x,y⟩t+‖x‖2, and completing the square gives (b) with ‖x‖2−⟨x,y⟩2/‖y‖2 as the constant term. What it does not show is why the minimum sits at t0, or what the constant term means. The scratch work answers both, as in Example (Method: subtract the projection): the error at t0 is orthogonal to y, and Pythagoras turns the split x−ty=(x−p)+(t0−t)y into the identity. The constant term is then ‖x−p‖2, the squared distance to the line.

Before reading on: in (a), why is t0 the only such t? Which hypothesis does that use?

Proof. Since y≠0, ‖y‖2=⟨y,y⟩>0. In particular ‖y‖2≠0, so t0 is defined.

  • (a) Let t∈R. By linearity in the first slot, ⟨x−ty,y⟩=⟨x,y⟩−t⟨y,y⟩=⟨x,y⟩−t‖y‖2. This is 0 if and only if t‖y‖2=⟨x,y⟩. Since ‖y‖2≠0, this holds if and only if t=t0. So x−t0y=x−p is orthogonal to y, and no other t has this property.

  • (b) Let t∈R. By the vector space laws, x−ty=(x−p)+(t0−t)y. By (a) and linearity, ⟨x−p,(t0−t)y⟩=(t0−t)⟨x−p,y⟩=0, so the two pieces are orthogonal. Pythagoras (Proposition 9.4.4) and the rule ‖cv‖=|c|‖v‖ give ‖x−ty‖2=‖x−p‖2+|t0−t|2‖y‖2=‖x−p‖2+(t−t0)2‖y‖2, where |t0−t|2=(t0−t)2=(t−t0)2. The last term is a product of two non-negative reals, so it is ≥0. Hence ‖x−ty‖2≥‖x−p‖2. The last term is 0 if and only if (t−t0)2=0, because ‖y‖2≠0 and a field has no zero divisors. That is, it is 0 if and only if t=t0, since a non-zero real has a positive square. Both lengths are non-negative, and for non-negative numbers comparing squares compares the numbers. So ‖x−ty‖≥‖x−p‖, with equality exactly when the squares are equal, that is, when t=t0.

  • (c) Take t=0 in (b): ‖x‖2=‖x−p‖2+t02‖y‖2. Since p=t0y, ‖p‖=|t0|‖y‖, so ‖p‖2=t02‖y‖2, which gives the first claim. For the second, |t0|=|⟨x,y⟩|/‖y‖2, since ‖y‖2>0. Hence ‖p‖=|⟨x,y⟩|‖y‖/‖y‖2=|⟨x,y⟩|/‖y‖. This proves the theorem.

Uses: Proposition 9.4.1 (a)–(c) (rules for lengths); Proposition 9.3.1 (b), (c) (linearity, positivity); Definition 9.3.2, Proposition 9.2.1, Example (Method: expand the square) (comparing squares). Number Systems: From N to R, Proposition 4.1.3 (b) (products, squares); Number Systems: From N to R, Proposition 2.4.3 (b), (e) (sums, non-zero squares); Number Systems: From N to R, Lemma 4.1.1 (d) (no zero divisors).

Why is t0 the only such t? By (a), x−ty⊥y is the linear equation t‖y‖2=⟨x,y⟩, with exactly one solution because ‖y‖2≠0. Without y≠0 the theorem fails: for y=0 every t gives the same distance ‖x‖, so the nearest point is not unique in t.

Part (b) says more than “p is nearest”: it measures exactly what a wrong t costs.

Alternatively. Part (c) says ‖p‖≤‖x‖, that is, ⟨x,y⟩2/‖y‖2≤‖x‖2. Multiplying by ‖y‖2>0 gives ⟨x,y⟩2≤‖x‖2‖y‖2. That is the Cauchy–Schwarz inequality (Theorem 9.5.1 (a)) again, by a second route. More is true: (c) gives ‖x‖2‖y‖2−⟨x,y⟩2=‖y‖2‖x−p‖2, so the gap between the two sides of Cauchy–Schwarz is a squared distance, scaled by ‖y‖2. Equality holds exactly when x=p, that is, when x lies on the line through y. Exercise C1 of Section 9.5 (Exercise (C1: Chapter check: Cauchy–Schwarz)) turns this route into a complete second proof of Cauchy–Schwarz with its equality case.

Example (Distance to a line through the origin)

Find the point of the line {ty:t∈R} nearest to x, and the distance from x to the line:

  • (a) x=(3,1), y=(1,1);
  • (b) x=(1,2,3), y=(1,1,1); also write ‖x−ty‖2 for every t.

Solution. We subtract the projection, as in Example (Method: subtract the projection), and use the theorem just proved.

  • (a) ⟨x,y⟩=3+1=4 and ‖y‖2=2, so t0=2 and p=(2,2). Then x−p=(1,−1), and indeed ⟨(1,−1),(1,1)⟩=0. The distance is ‖x−p‖=1+1=2, as the completed square at the start of the section found.

  • (b) ⟨x,y⟩=1+2+3=6 and ‖y‖2=3, so t0=2 and p=(2,2,2). Then x−p=(−1,0,1); its dot product with (1,1,1) is −1+0+1=0, and ‖x−p‖2=2. By the theorem’s (b), for every t, ‖x−ty‖2=2+3(t−2)2. So the nearest point is (2,2,2) and the distance is 2. As a check, at t=0 the formula gives 2+12=14=1+4+9=‖x‖2.

Lines that do not pass through the origin need one more step, a translation; Chapter 10 takes them up.

Uses:

Warning. projyx is a vector; ⟨x,y⟩/‖y‖ is a number. The two are easily confused, because the number is, up to sign, the length of the vector (1 (c)). They also behave differently when y is rescaled. For x=(3,1): with y=(1,1) the number is 4/2=22, and with y=(−1,−1) it is −22, while the projection is (2,2) both times.

9.6.2. The cosine of an angle

The projection splits x into a piece along y and a piece orthogonal to it. In the plane picture, x, p and the origin are the corners of a right triangle, and school trigonometry would call ‖p‖/‖x‖ the cosine of the angle at the origin, “adjacent over hypotenuse”. With the sign of t0 kept, so that the cosine is negative when p points away from y, that ratio is t0‖y‖‖x‖=⟨x,y⟩‖y‖2⋅‖y‖‖x‖=⟨x,y⟩‖x‖‖y‖. The picture is motivation only. The expression on the right is defined in any Rn as soon as x≠0 and y≠0, and Cauchy–Schwarz already tells us it lies between −1 and 1. Before naming it, compute it on a few cases where the answer is guessable.

Quick check. Let x=(1,1,0). Compute ⟨x,y⟩/(‖x‖‖y‖) for y=x, for y=−x, and for y=(1,−1,0).

Solution. ‖x‖=2. For y=x: ⟨x,x⟩=2, so the ratio is 2/(22)=1. For y=−x: ⟨x,−x⟩=−2 and ‖−x‖=2, so the ratio is −1. For y=(1,−1,0): ⟨x,y⟩=1−1+0=0, so the ratio is 0. Same direction gives 1, opposite directions give −1, and orthogonal vectors give 0, as the school cosine of 0, of a straight angle and of a right angle would.

Definition 9.6.2 (Cosine of the Angle between Two Vectors)

Let x,y∈Rn with x≠0 and y≠0. The cosine of the angle between x and y is the real number cos⁡∠(x,y):=⟨x,y⟩‖x‖‖y‖.

The cosine of the angle is the dot product of the two directions.

In words: divide the dot product by both lengths. The symbol cos⁡∠(x,y) is read as one symbol, a function of the pair (x,y). It is not the function cos applied to a number ∠(x,y): this chapter defines no angle ∠(x,y) at all, and ∠ alone means nothing here.

Well-definedness. Both lengths are positive, because x≠0 and y≠0 (Proposition 9.4.1 (a)), so the quotient exists. Its value lies in [−1,1]. Indeed, Cauchy–Schwarz (Theorem 9.5.1 (a)) gives |⟨x,y⟩|≤‖x‖‖y‖. Dividing by ‖x‖‖y‖>0 gives |cos⁡∠(x,y)|≤1, that is, −1≤cos⁡∠(x,y)≤1, by the rule for absolute values in an ordered field (Number Systems: From N to R, Number Systems: From N to R, Proposition 4.1.3 (d)). Without Cauchy–Schwarz, we would not know that this number lies between −1 and 1, as a cosine should.

The computation before the definition gives the first examples: cos⁡∠(x,x)=1, cos⁡∠(x,−x)=−1, and cos⁡∠(x,y)=0 for orthogonal non-zero x,y.

When one vector is zero. Keep x=(1,1,0) and replace y by 0. The dot product is still 0, but the quotient 0/0 is not defined. The zero vector has no direction, and this is why the definition requires y≠0. In particular, “cos⁡∠(x,y)=0” and “x⊥y” are not the same statement: the second allows a zero vector, the first does not.

Why this definition. Dividing by both lengths makes the number see only directions, as part (b) below shows. Dividing by one length, or by none, would let the size of x or y change the answer.

The properties below are what the name promises.

Proposition 9.6.2 (Properties of the Cosine of an Angle)

Let x,y∈Rn be non-zero.

  • (a) cos⁡∠(x,y)=cos⁡∠(y,x), and cos⁡∠(x,y)=⟨x/‖x‖,y/‖y‖⟩.
  • (b) For all a,b∈R with ab≠0: cos⁡∠(ax,by)=cos⁡∠(x,y) if ab>0, and cos⁡∠(ax,by)=−cos⁡∠(x,y) if ab<0.
  • (c) cos⁡∠(x,y)=1 if and only if y=cx for some c>0; cos⁡∠(x,y)=−1 if and only if y=cx for some c<0; and cos⁡∠(x,y)=0 if and only if x⊥y.
  • (d) (Law of cosines.) ‖x−y‖2=‖x‖2+‖y‖2−2‖x‖‖y‖cos⁡∠(x,y).

Idea. Part (a) is the method of normalizing (Example (Method: normalize)) in reverse: the cosine is the dot product of the unit vectors x/‖x‖ and y/‖y‖. Rescaling x or y by a non-zero factor changes the unit vector at most by a sign, which is (b). Part (c) is the equality case of Cauchy–Schwarz, and (d) is one expansion of a square.

Proof.

  • (a) The first claim is the symmetry of the dot product. By linearity in each slot, ⟨x/‖x‖,y/‖y‖⟩=⟨x,y⟩/(‖x‖‖y‖).

  • (b) Here ax≠0 and by≠0 (Proposition 9.2.1 (j)), so the left side is defined. By linearity and the rule ‖cv‖=|c|‖v‖, cos⁡∠(ax,by)=ab⟨x,y⟩|a|‖x‖|b|‖y‖=ab|ab|cos⁡∠(x,y), using |a||b|=|ab|. If ab>0 then |ab|=ab and the factor is 1. If ab<0 then |ab|=−ab and the factor is −1.

  • (c) Multiplying by ‖x‖‖y‖>0, cos⁡∠(x,y)=1 if and only if ⟨x,y⟩=‖x‖‖y‖. By the equality case of Cauchy–Schwarz (Theorem 9.5.1 (c)), this holds if and only if x=0 or y=cx with c≥0. Since x≠0, it holds if and only if y=cx with c≥0. Also c≠0 because y≠0, so c>0. The case −1 is the same argument with ⟨x,y⟩=−‖x‖‖y‖ and part (c′) of the same theorem, which gives c≤0, hence c<0. Finally cos⁡∠(x,y)=0 if and only if ⟨x,y⟩=0, that is, x⊥y.

  • (d) Expand the square (Example (Method: expand the square)): ‖x−y‖2=‖x‖2−2⟨x,y⟩+‖y‖2, and ⟨x,y⟩=‖x‖‖y‖cos⁡∠(x,y) by the definition.

Uses: Proposition 9.3.1 (a), (b) (symmetry, linearity); Proposition 9.4.1 (b) (length of a multiple); Definition 9.3.2. Number Systems: From N to R, Proposition 4.1.3 (b) (|a||b|=|ab|).

Part (d) is the law of cosines of school trigonometry, now with no triangle and no angle in it: the “angle” is replaced by its cosine, and the cosine by a quotient of dot products. When x⊥y it is Pythagoras again. Part (b) says that the cosine depends only on the two lines through x and y, and on whether each vector points along its line or against it.

Example (Cosines of angles)

Compute:

  • (a) cos⁡∠((1,0),(1,1));
  • (b) cos⁡∠((1,2,2),(2,−1,2));
  • (c) three cosines in the unit cube [0,1]3, with a corner at the origin. First, between the body diagonal (1,1,1) and the edge e1. Second, between the two body diagonals (1,1,1) and (1,1,−1); the second runs from the corner (0,0,1) to the corner (1,1,0). Third, between the body diagonal and the face diagonal (1,1,0).

Solution.

  • (a) The dot product is 1, and the lengths are 1 and 2, so the cosine is 1/2.

  • (b) The dot product is 2−2+4=4, and both lengths are 1+4+4=3, so the cosine is 4/9.

  • (c) ‖(1,1,1)‖=3. Against e1: the dot product is 1 (Proposition 9.3.1 (d)), so the cosine is 1/3. Between the body diagonals: the dot product is 1+1−1=1, and both lengths are 3, so the cosine is 1/3. Against the face diagonal: the dot product is 2 and ‖(1,1,0)‖=2, so the cosine is 2/(32)=2/6=6/3.

Each answer is a cosine and nothing more. We do not convert any of them into an angle, because that needs the function cos itself.

Uses: Lemma 1.5.2 (a) (root of a product).

Quick check. What is cos⁡∠((1,1),(−1,−1))? Answer first with Proposition 9.6.2, then by computing.

Solution. (−1,−1)=c(1,1) with c=−1<0, so the cosine is −1 by (c). Computing: the dot product is −2, and both lengths are 2, so the cosine is −2/2=−1.

Remark (Looking ahead: the angle itself). An angle θ with cos⁡θ=cos⁡∠(x,y) needs the function cos, which this book only borrows through five facts (Axiom 3.5.2). Those facts give such a θ for any n. Let c=cos⁡∠(x,y). Then c2≤1, so the point (c,1−c2) has squared coordinates adding up to 1. Every such point is (cos⁡θ,sin⁡θ) for some θ, (T4). No proof in this chapter uses θ. For n=2 and non-zero z,w∈C, the number z―w/(|z||w|) has modulus 1, so its polar form is cos⁡θ+isin⁡θ (Proposition 3.5.4). Here cos⁡θ=cos⁡∠(z,w), by Proposition 9.4.3. The sign of sin⁡θ records which way one turns from z to w, and cos⁡∠ cannot see it. Next, Chapter 10 uses the projection to find nearest points on lines and on hyperplanes.

9.6.3. Exercises

A. Check your understanding

Exercise (A1)

These questions are about 1 and its proof.

  • (a) Why does the theorem assume y≠0? What goes wrong for y=0?
  • (b) Where in the proof of (b) is x−p⊥y used?
  • (c) Check the identity of (b) for x=(1,2,3), y=(1,1,1), at t=0 and at t=1.
  • (d) Compute proj(1,2,2)(3,0,0), and check that the error is orthogonal to (1,2,2).
  • (e) State the idea of the proof of (b) in two sentences.

Solution.

  • (a) The definition of t0 divides by ‖y‖2, which is 0 exactly when y=0. For y=0 the statement also fails: every ty is 0, so ‖x−ty‖=‖x‖ for every t, and the minimizing t is not unique.

  • (b) In applying Pythagoras to x−ty=(x−p)+(t0−t)y: Pythagoras needs the two pieces orthogonal, and ⟨x−p,(t0−t)y⟩=(t0−t)⟨x−p,y⟩=0 uses (a). In the terms of Example (Method: expand the square), it makes the cross term zero.

  • (c) Here t0=2, p=(2,2,2), ‖x−p‖2=2 and ‖y‖2=3. At t=0: ‖x‖2=1+4+9=14 and 2+(0−2)2⋅3=14. At t=1: ‖x−y‖2=‖(0,1,2)‖2=5 and 2+(1−2)2⋅3=5.

  • (d) ⟨(3,0,0),(1,2,2)⟩=3 and ‖(1,2,2)‖2=9, so the projection is 13(1,2,2)=(1/3,2/3,2/3). The error is (8/3,−2/3,−2/3), and its dot product with (1,2,2) is 8/3−4/3−4/3=0.

  • (e) Choose t0 so that the error x−t0y is orthogonal to y. Then any other x−ty is that error plus a multiple of y, and Pythagoras shows the extra multiple can only add length.

B. Practice

Exercise (B1: The median identity)

Let x,y,z∈Rn and m:=12(x+y). Prove that ‖x−z‖2+‖y−z‖2=12‖x−y‖2+2‖z−m‖2. You are given the first half: x−z=(x−m)+(m−z),y−z=−(x−m)+(m−z), where the second holds because y−m=12(y−x)=−(x−m).

Say which method this is, then complete it.

Solution. The method is expand the square (Example (Method: expand the square)). Write a:=x−m and b:=m−z. Then ‖x−z‖2=‖a+b‖2=‖a‖2+2⟨a,b⟩+‖b‖2,‖y−z‖2=‖−a+b‖2=‖a‖2−2⟨a,b⟩+‖b‖2, using ‖−a‖=‖a‖ (Proposition 9.4.1 (b)) and linearity for ⟨−a,b⟩=−⟨a,b⟩. Adding, the cross terms cancel: the sum is 2‖a‖2+2‖b‖2. Finally a=x−m=12(x−y), so 2‖a‖2=2⋅14‖x−y‖2=12‖x−y‖2 by Proposition 9.4.1 (b), and ‖b‖=‖z−m‖. This proves the identity. It is the parallelogram law (Proposition 9.4.5) applied to a and b, read as a statement about a triangle x,y,z and the midpoint m of one side.

Exercise (B2: Prove or disprove)

Let x,y,z∈Rn with y≠0. Prove or disprove each statement.

  • (a) projy(projyx)=projyx.
  • (b) projy(x+z)=projyx+projyz.
  • (c) projcyx=projyx for every c∈R with c≠0.
  • (d) ‖projyx‖≤‖x‖.
  • (e) projyx=projxy for all non-zero x,y.
  • (f) If x⊥y, then projyx=0.

Solution. Write t0=⟨x,y⟩/‖y‖2.

  • (a) True. projyx=t0y, and projy(t0y)=(⟨t0y,y⟩/‖y‖2)y=(t0‖y‖2/‖y‖2)y=t0y, by linearity. A point on the line is its own projection.

  • (b) True. By linearity, ⟨x+z,y⟩=⟨x,y⟩+⟨z,y⟩; divide by ‖y‖2 and multiply by y, using the distributive law (h) of Proposition 9.2.1.

  • (c) True. cy≠0 because c≠0 and y≠0 (Proposition 9.2.1 (j)). Then ⟨x,cy⟩=c⟨x,y⟩ and ‖cy‖2=c2‖y‖2, so projcyx=c⟨x,y⟩c2‖y‖2cy=c2⟨x,y⟩c2‖y‖2y=projyx.

  • (d) True. By 1 (c), ‖x‖2=‖p‖2+‖x−p‖2≥‖p‖2, and both lengths are non-negative, so ‖p‖≤‖x‖.

  • (e) False. Take x=(1,0) and y=(1,1). Then projyx=12(1,1)=(1/2,1/2), while projxy=1⋅(1,0)=(1,0). The first lies on the line of y, the second on the line of x.

  • (f) True. x⊥y means ⟨x,y⟩=0, so t0=0 and projyx=0y=0 (Proposition 9.2.1 (i)).

Exercise (B3)
  • (a) Find the point of the line {t(2,1,−2):t∈R} nearest to (1,1,1), and the distance from (1,1,1) to the line.
  • (b) Let v,y∈Rn with y≠0. Show that there are at most two real numbers t with ‖v+ty‖=1.

Solution.

  • (a) With x=(1,1,1) and y=(2,1,−2): ⟨x,y⟩=2+1−2=1 and ‖y‖2=4+1+4=9, so t0=1/9, and the nearest point is p=(2/9,1/9,−2/9) (1 (b)). By (c) of the theorem, ‖x−p‖2=‖x‖2−‖p‖2=3−19=269, since ‖p‖2=⟨x,y⟩2/‖y‖2=1/9. The distance is 26/3. As a check, x−p=(7/9,8/9,11/9), with (49+64+121)/81=234/81=26/9, and ⟨x−p,y⟩=(14+8−22)/9=0.

  • (b) Suppose ‖v+ty‖=1. Squaring and expanding (Example (Method: expand the square)), ‖y‖2t2+2⟨v,y⟩t+‖v‖2−1=0. Consider the polynomial f:=‖y‖2x2+2⟨v,y⟩x+(‖v‖2−1) in R[x], with the indeterminate x of Chapters 6 and 7. Its coefficient of x2 is ‖y‖2≠0, since y≠0, so f≠0 and deg⁡f=2 (Definition 6.3.1). By Theorem 6.4.1, the value f(t) is the left side of the display, so every t with ‖v+ty‖=1 is a root of f in R. By Theorem 7.4.1, f has at most 2 distinct roots. Hence there are at most two such t. (Geometrically: a line meets a sphere of radius 1 in at most two points.)

C. Going deeper

Exercise (C1: Chapter check: the projection theorem)

Let x,y∈Rn with y≠0. Prove that exactly one t∈R minimizes ‖x−ty‖, that this t is t0=⟨x,y⟩/‖y‖2, and that x−t0y⊥y. Write the proof from the definitions and the results of Sections 9.2–9.4, without quoting 1.

Solution (Hint 1). Look for the t that makes the error x−ty orthogonal to y.

Solution (Hint 2). For an arbitrary t, compare x−ty with x−t0y: what is their difference?

Solution. Since y≠0, ‖y‖2=⟨y,y⟩>0, so t0 is defined. By linearity, ⟨x−t0y,y⟩=⟨x,y⟩−t0‖y‖2=⟨x,y⟩−⟨x,y⟩=0, so x−t0y⊥y. Let t∈R. Then x−ty=(x−t0y)+(t0−t)y, and ⟨x−t0y,(t0−t)y⟩=(t0−t)⋅0=0. By Pythagoras and the rule ‖cv‖=|c|‖v‖, ‖x−ty‖2=‖x−t0y‖2+(t−t0)2‖y‖2. The last term is ≥0, and it is 0 only if t=t0, because ‖y‖2>0 and a square of a non-zero real is positive. So ‖x−ty‖2≥‖x−t0y‖2 for every t, with equality only at t=t0. Lengths are non-negative, so the same holds for the lengths themselves. Hence t0 minimizes ‖x−ty‖, and every t≠t0 gives a strictly larger value, so the minimizer is unique.

Completing the square in t is an acceptable second route for the identity: ‖x−ty‖2=‖y‖2t2−2⟨x,y⟩t+‖x‖2=‖y‖2(t−t0)2+‖x‖2−⟨x,y⟩2/‖y‖2. It receives the points for the identity, minimality and uniqueness; the orthogonality must still be checked separately.

What a complete answer needs. (10 points)

  • 2: finds t0 from the orthogonality condition (or states it), and justifies dividing by ‖y‖2 through y≠0.
  • 2: verifies x−t0y⊥y.
  • 3: proves the identity ‖x−ty‖2=‖x−t0y‖2+(t−t0)2‖y‖2 for every t (by Pythagoras or by completing the square).
  • 2: deduces minimality and uniqueness, using ‖y‖2>0 for the strict inequality when t≠t0.
  • 1: concludes, passing from squares to lengths with non-negativity.

Slips that lose the step (0 for the step):

  • a division by ‖y‖2 with no mention of y≠0;
  • derivatives, which are not available in this book;
  • “the vertex of a parabola is the minimum” without the identity that proves it.

Uses: Proposition 9.3.1 (b), (c) (linearity, positivity); Proposition 9.2.1; Proposition 9.4.4; Proposition 9.4.1 (b) (length of a multiple). Number Systems: From N to R, Proposition 2.4.3 (e), (g) (non-zero squares, comparing squares).

Exercise (C2: The distance to a line in the plane)

Let x,y∈Rn with y≠0, and p=projyx.

  • (a) Prove that ‖y‖2‖x−p‖2=12∑j=1n∑k=1n(xjyk−xkyj)2.
  • (b) Deduce that for n=2 the distance from x to the line {ty:t∈R} is |x1y2−x2y1|/‖y‖.

Solution (Hint 1). Both sides of (a) are equal to the same third expression, which involves only ‖x‖, ‖y‖ and ⟨x,y⟩.

Solution (Hint 2). For (a), start from ‖x−p‖2=‖x‖2−‖p‖2 and multiply by ‖y‖2. For (b), list the four terms of the double sum when n=2.

Solution.

  • (a) By 1 (c), ‖x−p‖2=‖x‖2−‖p‖2=‖x‖2−⟨x,y⟩2/‖y‖2. Multiplying by ‖y‖2, ‖y‖2‖x−p‖2=‖x‖2‖y‖2−⟨x,y⟩2. By Lagrange’s identity (Exercise (C2: Lagrange’s identity)), the right side is 12∑j∑k(xjyk−xkyj)2, since ‖x‖2=∑kxk2, ‖y‖2=∑kyk2 and ⟨x,y⟩=∑kxkyk.

  • (b) For n=2, the terms with j=k are (xjyj−xjyj)2=0. The terms with (j,k)=(1,2) and (2,1) are (x1y2−x2y1)2 and (x2y1−x1y2)2, which are equal. So the right side of (a) is 12⋅2(x1y2−x2y1)2=(x1y2−x2y1)2. By 1 (b), the distance from x to the line is ‖x−p‖. Taking non-negative square roots gives ‖y‖‖x−p‖=|x1y2−x2y1|, since a2=|a| and the root of a product is the product of the roots. Dividing by ‖y‖>0 gives the claim. For x=(3,1) and y=(1,1) it gives |3−1|/2=2, as in Example (Distance to a line through the origin).

The number |x1y2−x2y1| is the base ‖y‖ times the height ‖x−p‖: in the picture, the area of the parallelogram spanned by x and y. Area is not defined in this book; later volumes meet this number again as a determinant.

Uses: 1 (b); Proposition 3.2.1 (a2=|a|); Lemma 1.5.2 (a) (root of a product).

R. Review

Exercise (R1)

Let x,y∈Rn with y≠0, let t0=⟨x,y⟩/‖y‖2, let p:=t0y, and let g(t):=‖x−ty‖ for t∈R. Prove that g is strictly increasing on [t0,∞).

Solution. Let t0≤s<t. By 1 (b), g(t)2=‖x−p‖2+(t−t0)2‖y‖2, and likewise for s. Factoring out t−s (Example (Method: factor out y − x)) gives g(t)2−g(s)2=((t−t0)2−(s−t0)2)‖y‖2=(t−s)(t+s−2t0)‖y‖2. Here t−s>0 and ‖y‖2>0. Also t+s−2t0=(t−t0)+(s−t0)>0, since t−t0>0 and s−t0≥0. The sum is strict because one summand is. So g(s)2<g(t)2. Both g(s) and g(t) are non-negative, so g(s)<g(t). This is the definition of strictly increasing on [t0,∞) (Definition 8.2.1). By the same factorization, g is strictly decreasing on (−∞,t0].

Uses: Number Systems: From N to R, Proposition 2.4.3 (b), (g) (strict sums, comparing squares).

Exercise (R2)

Fix a∈Rn, and define φ:Rn→R by φ(x):=⟨a,x⟩. Show that φ is a homomorphism from (Rn,+) to (R,+), find its kernel, and decide for which a and n it is injective.

Solution. The brackets here are the dot product of Definition 9.3.1, not a subgroup generated by an element.

(Rn,+) is a group (Definition 5.1.1). Associativity, the identity 0 and the inverse −x are laws (a), (c) and (d) of Proposition 9.2.1, and law (b) makes it abelian. So is (R,+). By linearity of the dot product, φ(x+y)=⟨a,x+y⟩=⟨a,x⟩+⟨a,y⟩=φ(x)+φ(y), so φ is a homomorphism (Definition 5.3.1). Its kernel is {x:⟨a,x⟩=0}={x:x⊥a}.

If a=0, the kernel is all of Rn. Let a≠0. If n=1, φ(x)=ax, and ax=0 forces x=0; the kernel is {0}. If n≥2, the kernel contains a non-zero vector: if a1≠0, take v=a2e1−a1e2, with ⟨a,v⟩=a1a2−a2a1=0 and second coordinate −a1≠0; if a1=0, take e1, with ⟨a,e1⟩=a1=0. By Proposition 5.3.3, φ is injective if and only if n=1 and a≠0.

Uses: Proposition 9.3.1 (b) (linearity).

Exercise (R3)

Let z,w∈C with z≠0. Prove that zw― is a non-negative real number if and only if w=cz for some real c≥0.

Solution. (⇐) If w=cz with c∈R, c≥0, then c―=c, because the imaginary part of c is 0. So by Theorem 3.2.2 (b) and (c), zw―=zc―z―=c|z|2, a non-negative real.

(⇒) Let zw―=r with r∈R, r≥0. By Theorem 3.2.2 (a) and (b), wz―=zw――=r―=r. Since z≠0, |z|2=zz―≠0 (Theorem 3.2.2 (c), (e)), so w=wz―zz―z=r|z|2z. With c:=r/|z|2, a non-negative real, w=cz. The product of the real number c=(c,0) with z in C is the scalar multiple cz in R2, by Proposition 9.4.3 (a).

Chapter 3 found the first condition as the equality case of |z+w|≤|z|+|w| (Exercise (B1: The equality case)). Then Theorem 9.5.3 (a) found the second, “z=0 or w=cz with c≥0”, for n=2. For z≠0 this exercise shows the two conditions agree, and for z=0 both hold. So the two chapters’ equality cases are one statement.

Uses: Definition 3.2.1 (conjugate of a real).

Exercise (R4)

Find all x∈Rn with ∑k=1nxk=n and ∑k=1nxk2=n.

Solution. The only solution is x=(1,1,…,1). It works, since both sums are n. Let w:=(1,1,…,1)∈Rn, so ‖w‖=n. The two conditions say ⟨w,x⟩=n and ‖x‖=n. By Cauchy–Schwarz (Theorem 9.5.1 (a)), n=⟨w,x⟩≤‖w‖‖x‖=nn=n, so equality holds: ⟨w,x⟩=‖w‖‖x‖. By Theorem 9.5.1 (c), w=0 or x=cw with c≥0; since w≠0, x=cw. Then ∑xk=nc=n, so c=1 and x=w.

A second route expands a square (Example (Method: expand the square)): ‖x−w‖2=‖x‖2−2⟨x,w⟩+‖w‖2=n−2n+n=0. So x=w, because only the zero vector has length 0 (Proposition 9.4.1 (a)).

The tool is Cauchy–Schwarz with its equality case, because each condition mixes all the coordinates. The look-alike tool, working coordinatewise (Example (Method: work coordinatewise)), finds nothing to hold on to: neither condition says anything about a single xk.