The dot product and the closest point on a line
Which point of a line through 0 is closest to a given point \(b\), and how can you find it without measuring?
Stage 1 asks you to place that point by eye before the page computes anything. The tool that finds it exactly is the dot product \(u \cdot v = u_1v_1 + u_2v_2\), a single number made from two vectors. Stage 3 proves where the closest point is and why there is only one.
Before you start · 3 quick checks on vector arithmetic, length and lines through 0, about 2 min
As on the matrix-as-map page, a vector \(x = (x_1, x_2)\) in \(\mathbb{R}^2\) is a point of the plane, or the arrow from 0 to that point.
The dot product of \(u = (u_1, u_2)\) and \(v = (v_1, v_2)\) is the number \(u \cdot v = u_1v_1 + u_2v_2\). The length of \(v\) is \(|v| = \sqrt{v_1^2 + v_2^2} = \sqrt{v \cdot v}\), so \(|v|^2 = v \cdot v\), and the distance between two points \(x\) and \(y\) is \(|x - y|\).
For all vectors \(u, v, w\) and every real number \(c\): \(u \cdot v = v \cdot u\), \((u + w) \cdot v = u \cdot v + w \cdot v\), \((cu) \cdot v = c\,(u \cdot v)\), and \(v \cdot v \ge 0\), with \(v \cdot v = 0\) only for \(v = 0\).
Two vectors \(u\) and \(v\) are orthogonal when \(u \cdot v = 0\). For a vector \(a \ne 0\), the line through 0 along \(a\) is \(L = \{ta : t \text{ a real number}\}\), the set of all multiples of \(a\).
Why a dot product of 0 means a right angle
Take nonzero vectors \(u\) and \(v\). By the rules above,
\[ \begin{aligned} |u - v|^2 &= (u - v) \cdot (u - v) \\ &= |u|^2 - 2\,u \cdot v + |v|^2. \end{aligned} \]The triangle with corners 0, \(u\) and \(v\) has sides \(|u|\), \(|v|\) and \(|u - v|\). Pythagoras and its converse say that the angle at 0 is a right angle exactly when \(|u - v|^2 = |u|^2 + |v|^2\), that is, exactly when \(u \cdot v = 0\). (If \(u\) and \(v\) lie on one line through 0, the angle is \(0^\circ\) or \(180^\circ\), and \(u \cdot v = \pm|u|\,|v| \ne 0\).) The zero vector is orthogonal to every vector, by the definition.
Find the point of the line closest to b
Each goal gives a line \(L\) through 0 and a point \(b\) off the line. Move your mark along \(L\) to where you think \(L\) comes closest to \(b\): drag the dot, focus it and use the arrow keys, or type \(t\). Then press Place mark. Only then does the page draw the closest point and give the distances.
How the mark moves and how it is scored
What the closest point depends on
Two questions first. The explorer below opens when you have answered both.
The explorer opens when you have answered the two questions above.
Stage 3 proves the formula behind this explorer: the closest point of the line through 0 along \(a \ne 0\) to \(b\) is \(p = \hat t a\) with \(\hat t = \dfrac{a \cdot b}{a \cdot a}\). Choose \(a\) and \(b\), each entry a whole number from −4 to 4. The tiles give \(\hat t\), \(p\), the error \(b - p\) and two checks, all as exact fractions.
Why the closest point is p = t̂a
Let \(a \ne 0\) and \(b\) be vectors, and let \(L\) be the line through 0 along \(a\). Put
\[ \hat t = \frac{a \cdot b}{a \cdot a}, \qquad p = \hat t a. \]Then \((b - p) \cdot a = 0\), and for every real number \(t\),
\[ |b - ta|^2 = |b - p|^2 + (\hat t - t)^2|a|^2. \]So \(p\) is the only point of \(L\) closest to \(b\). The vector \(b\) may be anything, including 0, a point of \(L\) or a vector orthogonal to \(a\).
Build the proof one line at a time; each line has one correct choice. A wrong choice is a statement that is false for these \(a\) and \(b\), or a claimed general rule that fails for some vectors.
What follows
The point \(p = \dfrac{a \cdot b}{a \cdot a}\,a\) is called the orthogonal projection of \(b\) onto \(L\). It splits \(b = p + (b - p)\) into a part along \(L\) and a part orthogonal to \(L\). If \(|a| = 1\), then \(a \cdot a = 1\) and the formula is simply \(p = (a \cdot b)\,a\).
Take \(t = 0\) in the theorem:
\[ \begin{aligned} |b|^2 &= |b - p|^2 + \hat t^2|a|^2 \\ &= |b - p|^2 + |p|^2. \end{aligned} \]So \(|p| \le |b|\), with equality exactly when \(b - p = 0\), that is, when \(b\) lies on \(L\).
Let \(a\) and \(b\) be nonzero, and let \(\theta\), between \(0^\circ\) and \(180^\circ\), be the angle between them. Then
\[ a \cdot b = |a|\,|b|\cos\theta. \]The right triangle with corners 0, \(p\) and \(b\) has its right angle at \(p\) and its long side \(|b|\), so \(|p| = |b|\,|\cos\theta|\); and \(p\) is on the side of \(a\) exactly when \(\theta \lt 90^\circ\). Since \(p = \hat t a\), this says \(\hat t\,|a| = |b|\cos\theta\), and multiplying by \(|a|\) gives the formula. (The triangle is flat when \(b\) lies on \(L\), and \(p = 0\) when \(\theta = 90^\circ\); the formula holds in both cases.) As \(|\cos\theta| \le 1\), it also gives \(|a \cdot b| \le |a|\,|b|\), the Cauchy–Schwarz inequality.
The map \(b \mapsto \dfrac{a \cdot b}{a \cdot a}\,a\) is linear, by the rules for sums and multiples, so it is a 2×2 matrix, as on the matrix-as-map page. It sends \(a\) to \(a\) and every vector orthogonal to \(a\) to 0. So \(a\) and every nonzero vector orthogonal to \(a\) are eigenvectors, with the eigenvalues 1 and 0, and the matrix can be diagonalized with them. Projecting twice changes nothing: the projection of \(p\) is \(p\) itself.
For vectors with \(n\) entries, \(u \cdot v = u_1v_1 + u_2v_2 + \cdots + u_nv_n\) and \(|v| = \sqrt{v \cdot v}\). The rules of the setup still hold, and \(a \cdot a = a_1^2 + \cdots + a_n^2 \gt 0\) for \(a \ne 0\). The proof above uses nothing else, so the theorem holds with the same proof.
Problems
Each problem has hints and a full solution. Exact answers are graded exactly: type whole numbers, exact decimals such as 0.5 or fractions such as 1/2, without thousands separators, and separate the numbers with commas where a problem asks for several. A value that is only close to an exact answer is not accepted. Where an answer is rounded (P5), the accepted error is stated.
Related: Eigenvectors: the directions a matrix only stretches and Diagonalization: what happens when you apply A again and again.
Further reading
- G. Strang, Introduction to Linear Algebra, 5th ed. (Wellesley-Cambridge Press, 2016), section 1.2 (Lengths and Dot Products) and section 4.2 (Projections).
- D. C. Lay, S. R. Lay and J. J. McDonald, Linear Algebra and Its Applications, 5th ed. (Pearson, 2016), section 6.1 (Inner Product, Length, and Orthogonality) and section 6.2 (Orthogonal Sets).
- S. Axler, Linear Algebra Done Right, 4th ed. (Springer, 2024), chapter 6 (Inner Product Spaces), sections 6A and 6C.