One product, $\mathbf{u}\cdot\mathbf{v}=u_1v_1+\dots+u_nv_n$, measures length, distance and angle — and tells you how much of one vector points along another.
In Section 4.1 we could add and scale vectors, but we could not yet ask the most basic geometric questions: How long is this vector? How far apart are two points? Are these two directions perpendicular? A surveyor checking that a wall is square, a physicist computing the work done by a force pulling at an angle, and a search engine deciding which web page best matches your query are all asking these questions — the last one in a space with tens of thousands of dimensions.
Remarkably, a single number answers all of them: the dot product. It is computed by multiplying matching components and adding. From it we get the length of a vector, the distance between points, the angle between directions, a test for perpendicularity, and the projection of one vector onto another — the shadow that one vector casts along the other.
The Dot Product and Length
📘 Definition 4.4 — Dot product
The dot product (or scalar product) of $\mathbf{u}=(u_1,\dots,u_n)$ and $\mathbf{v}=(v_1,\dots,v_n)$ in $\mathbb{R}^n$ is the scalar
$$\mathbf{u}\cdot\mathbf{v}=u_1v_1+u_2v_2+\dots+u_nv_n .$$
The answer is a number, not a vector. For instance $(1,-2,3)\cdot(4,0,-1)=4+0-3=1$. The dot product obeys rules that look just like the rules for multiplying numbers — each follows by writing out the components.
📐 Theorem 4.3 — Properties of the dot product
For all $\mathbf{u},\mathbf{v},\mathbf{w}$ in $\mathbb{R}^n$ and every scalar $c$:
(d) positive$\mathbf{u}\cdot\mathbf{u}\ge0$, and $\mathbf{u}\cdot\mathbf{u}=0$ only when $\mathbf{u}=\mathbf{0}$
Property (d) holds because $\mathbf{u}\cdot\mathbf{u}=u_1^2+\dots+u_n^2$ is a sum of squares. In $\mathbb{R}^2$ and $\mathbb{R}^3$, Pythagoras says that this sum is the square of the length of the arrow — so we use it to define length in every $\mathbb{R}^n$.
📘 Definition 4.5 — Norm, unit vector and distance
The norm (length) of $\mathbf{v}$ in $\mathbb{R}^n$ is $$\|\mathbf{v}\|=\sqrt{\mathbf{v}\cdot\mathbf{v}}=\sqrt{v_1^2+v_2^2+\dots+v_n^2}.$$
A unit vector is a vector of norm $1$. If $\mathbf{v}\ne\mathbf{0}$, the vector $\dfrac{1}{\|\mathbf{v}\|}\mathbf{v}$ is the unit vector in the direction of $\mathbf{v}$; finding it is called normalising $\mathbf{v}$.
The distance between $\mathbf{u}$ and $\mathbf{v}$ (or between the points they locate) is $d(\mathbf{u},\mathbf{v})=\|\mathbf{u}-\mathbf{v}\|$.
📐 Theorem 4.4 — Scaling a vector scales its length
For every $\mathbf{v}$ in $\mathbb{R}^n$ and every scalar $c$, $\ \|c\mathbf{v}\|=|c|\,\|\mathbf{v}\|$.
Proof. $\|c\mathbf{v}\|^2=(c\mathbf{v})\cdot(c\mathbf{v})=c^2(\mathbf{v}\cdot\mathbf{v})=c^2\|\mathbf{v}\|^2$; take square roots, remembering $\sqrt{c^2}=|c|$. In particular $\left\|\tfrac{1}{\|\mathbf{v}\|}\mathbf{v}\right\|=\tfrac{1}{\|\mathbf{v}\|}\|\mathbf{v}\|=1$, so normalising really gives a unit vector. $\blacksquare$
✏️ Example 1 — Dot product, norm, unit vector and distance
Let $\mathbf{u}=\begin{bmatrix}1\\-2\\3\end{bmatrix}$ and $\mathbf{v}=\begin{bmatrix}4\\0\\-1\end{bmatrix}$. Find $\mathbf{u}\cdot\mathbf{v}$, $\|\mathbf{u}\|$, $\|\mathbf{v}\|$, the unit vector in the direction of $\mathbf{v}$, and the distance $d(\mathbf{u},\mathbf{v})$.
Distance $\mathbf{u}-\mathbf{v}=(-3,-2,4)$, so $d(\mathbf{u},\mathbf{v})=\sqrt{9+4+16}=\sqrt{29}\approx5.385$.
Angles, Orthogonality and Two Inequalities
Draw $\mathbf{u}$ and $\mathbf{v}$ from the same point in $\mathbb{R}^2$ or $\mathbb{R}^3$ and let $\theta$ ($0\le\theta\le\pi$) be the angle between them. The third side of the triangle is $\mathbf{u}-\mathbf{v}$, and the law of cosines says
$$\|\mathbf{u}-\mathbf{v}\|^2=\|\mathbf{u}\|^2+\|\mathbf{v}\|^2-2\|\mathbf{u}\|\|\mathbf{v}\|\cos\theta .$$
Expanding the left side with Theorem 4.3 instead gives
$$\|\mathbf{u}-\mathbf{v}\|^2=(\mathbf{u}-\mathbf{v})\cdot(\mathbf{u}-\mathbf{v})=\|\mathbf{u}\|^2-2\,\mathbf{u}\cdot\mathbf{v}+\|\mathbf{v}\|^2 .$$
Comparing the two expressions:
📐 Theorem 4.5 — The geometric form of the dot product
If $\mathbf{u}$ and $\mathbf{v}$ are nonzero vectors in $\mathbb{R}^2$ or $\mathbb{R}^3$ and $\theta$ ($0\le\theta\le\pi$) is the angle between them, then
$$\mathbf{u}\cdot\mathbf{v}=\|\mathbf{u}\|\,\|\mathbf{v}\|\cos\theta .$$
So the sign of $\mathbf{u}\cdot\mathbf{v}$ tells the type of angle: positive $\iff$ acute, zero $\iff$ right angle, negative $\iff$ obtuse.
In $\mathbb{R}^n$ with $n\ge4$ there is no picture, so we turn the formula around and define $\cos\theta=\dfrac{\mathbf{u}\cdot\mathbf{v}}{\|\mathbf{u}\|\|\mathbf{v}\|}$. For this to make sense the fraction must lie between $-1$ and $1$. That is guaranteed by one of the most useful inequalities in mathematics.
📐 Theorem 4.6 — The Cauchy–Schwarz inequality
For all $\mathbf{u},\mathbf{v}$ in $\mathbb{R}^n$, $$|\mathbf{u}\cdot\mathbf{v}|\le\|\mathbf{u}\|\,\|\mathbf{v}\|,$$ with equality if and only if one of the vectors is a scalar multiple of the other.
Proof. If $\mathbf{u}=\mathbf{0}$ both sides are $0$. Otherwise, for every real $t$, $$0\le\|t\mathbf{u}+\mathbf{v}\|^2=\|\mathbf{u}\|^2t^2+2(\mathbf{u}\cdot\mathbf{v})t+\|\mathbf{v}\|^2 .$$ A quadratic in $t$ that is never negative has at most one real root, so its discriminant is $\le0$: $4(\mathbf{u}\cdot\mathbf{v})^2-4\|\mathbf{u}\|^2\|\mathbf{v}\|^2\le0$. Rearranging and taking square roots gives the inequality. Equality means the quadratic has a root $t_0$, i.e. $t_0\mathbf{u}+\mathbf{v}=\mathbf{0}$. $\blacksquare$
📘 Definition 4.6 — Angle and orthogonality in $\mathbb{R}^n$
For nonzero $\mathbf{u},\mathbf{v}$ in $\mathbb{R}^n$, the angle between them is the unique $\theta$ in $[0,\pi]$ with $$\cos\theta=\frac{\mathbf{u}\cdot\mathbf{v}}{\|\mathbf{u}\|\,\|\mathbf{v}\|}.$$ Two vectors $\mathbf{u},\mathbf{v}$ in $\mathbb{R}^n$ are orthogonal (perpendicular) if $\mathbf{u}\cdot\mathbf{v}=0$. (So $\mathbf{0}$ is orthogonal to every vector.)
📐 Theorem 4.7 — Triangle inequality and Pythagoras in $\mathbb{R}^n$
For all $\mathbf{u},\mathbf{v}$ in $\mathbb{R}^n$:
(b) Pythagoras. $\|\mathbf{u}+\mathbf{v}\|^2=\|\mathbf{u}\|^2+\|\mathbf{v}\|^2$ if and only if $\mathbf{u}$ and $\mathbf{v}$ are orthogonal.
Proof. $\|\mathbf{u}+\mathbf{v}\|^2=\|\mathbf{u}\|^2+2\,\mathbf{u}\cdot\mathbf{v}+\|\mathbf{v}\|^2$. For (b), the middle term vanishes exactly when $\mathbf{u}\cdot\mathbf{v}=0$. For (a), Cauchy–Schwarz gives $\mathbf{u}\cdot\mathbf{v}\le\|\mathbf{u}\|\|\mathbf{v}\|$, so $\|\mathbf{u}+\mathbf{v}\|^2\le\left(\|\mathbf{u}\|+\|\mathbf{v}\|\right)^2$. $\blacksquare$
The triangle inequality says that a detour is never shorter: going along $\mathbf{u}$ and then $\mathbf{v}$ is at least as long as going straight along $\mathbf{u}+\mathbf{v}$.
✏️ Example 2 — Finding angles
(a) Find the angle between $\mathbf{u}=(1,1,0)$ and $\mathbf{v}=(1,0,1)$. (b) Find the angle between a main diagonal of a cube and one of its edges.
💡 Show solution▶
(a) $\mathbf{u}\cdot\mathbf{v}=1+0+0=1$ and $\|\mathbf{u}\|=\|\mathbf{v}\|=\sqrt2$, so $\cos\theta=\dfrac{1}{\sqrt2\sqrt2}=\dfrac12$ and $\theta=\dfrac{\pi}{3}=60^\circ$. (These are two face diagonals of a unit cube; with the third face diagonal $(0,1,1)$ they form an equilateral triangle.)
(b) Set up Put the cube with side $1$ at the origin. The diagonal from $(0,0,0)$ to $(1,1,1)$ is $\mathbf{d}=(1,1,1)$ and an edge from the same corner is $\mathbf{e}_1=(1,0,0)$.
(b) Angle $\cos\theta=\dfrac{\mathbf{d}\cdot\mathbf{e}_1}{\|\mathbf{d}\|\|\mathbf{e}_1\|}=\dfrac{1}{\sqrt3\cdot1}$, so $\theta=\cos^{-1}\dfrac{1}{\sqrt3}\approx54.74^\circ$. The answer does not depend on the size of the cube — scaling both vectors does not change the angle.
✏️ Example 3 — Making two vectors orthogonal
Find the value of $k$ for which $\mathbf{u}=(k,2,-1)$ and $\mathbf{v}=(3,k,4)$ are orthogonal, and check Pythagoras for that $k$.
💡 Show solution▶
Set up $\mathbf{u}\cdot\mathbf{v}=3k+2k-4=5k-4$. Orthogonal means $5k-4=0$, so $k=\dfrac45$.
Check With $k=\tfrac45$: $\mathbf{u}=\left(\tfrac45,2,-1\right)$, $\mathbf{v}=\left(3,\tfrac45,4\right)$, $\mathbf{u}\cdot\mathbf{v}=\tfrac{12}{5}+\tfrac85-4=0$. ✓
Pythagoras $\|\mathbf{u}\|^2=\tfrac{16}{25}+4+1=\tfrac{141}{25}$, $\|\mathbf{v}\|^2=9+\tfrac{16}{25}+16=\tfrac{641}{25}$, and $\mathbf{u}+\mathbf{v}=\left(\tfrac{19}{5},\tfrac{14}{5},3\right)$ has $\|\mathbf{u}+\mathbf{v}\|^2=\tfrac{361+196+225}{25}=\tfrac{782}{25}=\tfrac{141+641}{25}$. ✓
Interactive 1 — Dot Product, Angle and Projection
Drag the tips of u and v. The green arrow is the projection — the shadow of one vector on the line of the other, cast by light falling at right angles. Play swings $\mathbf{v}$ round in a circle: watch $\mathbf{u}\cdot\mathbf{v}$ shrink to $0$ exactly when the angle is $90^\circ$, and turn negative (the shadow points backwards) when the angle is obtuse.
$\mathbf{u}$, $\mathbf{v}$—
$\mathbf{u}\cdot\mathbf{v}$—
$\|\mathbf{u}\|$, $\|\mathbf{v}\|$—
angle $\theta$—
projection—
component—
Projections
Very often we want to split a vector into a part along a given direction and a part perpendicular to it: the part of the wind that pushes a sailing boat forward, the part of gravity that pulls a box down a ramp, the part of a data point explained by a trend line. Suppose $\mathbf{u}\ne\mathbf{0}$ and we want to write $\mathbf{v}=c\mathbf{u}+\mathbf{w}$ with $\mathbf{w}$ orthogonal to $\mathbf{u}$. Dotting both sides with $\mathbf{u}$ gives $\mathbf{v}\cdot\mathbf{u}=c\,(\mathbf{u}\cdot\mathbf{u})+0$, so the only possible choice is $c=\dfrac{\mathbf{v}\cdot\mathbf{u}}{\mathbf{u}\cdot\mathbf{u}}$.
📘 Definition 4.7 — Projection and component
Let $\mathbf{u}\ne\mathbf{0}$ and $\mathbf{v}$ be vectors in $\mathbb{R}^n$. The orthogonal projection of $\mathbf{v}$ onto $\mathbf{u}$ is
$$\operatorname{proj}_{\mathbf{u}}\mathbf{v}=\left(\frac{\mathbf{v}\cdot\mathbf{u}}{\mathbf{u}\cdot\mathbf{u}}\right)\mathbf{u},$$
and the component of $\mathbf{v}$ along $\mathbf{u}$ is the scalar $\operatorname{comp}_{\mathbf{u}}\mathbf{v}=\dfrac{\mathbf{v}\cdot\mathbf{u}}{\|\mathbf{u}\|}$ (which equals $\|\mathbf{v}\|\cos\theta$ when $\mathbf{v}\ne\mathbf{0}$). The vector $\mathbf{v}-\operatorname{proj}_{\mathbf{u}}\mathbf{v}$ is orthogonal to $\mathbf{u}$, so
$$\mathbf{v}=\underbrace{\operatorname{proj}_{\mathbf{u}}\mathbf{v}}_{\text{parallel to }\mathbf{u}}+\underbrace{\left(\mathbf{v}-\operatorname{proj}_{\mathbf{u}}\mathbf{v}\right)}_{\text{orthogonal to }\mathbf{u}} .$$
The component is a signed length: $\operatorname{proj}_{\mathbf{u}}\mathbf{v}=\left(\operatorname{comp}_{\mathbf{u}}\mathbf{v}\right)\dfrac{\mathbf{u}}{\|\mathbf{u}\|}$, so it is positive when the shadow points the same way as $\mathbf{u}$ and negative when it points backwards. Note the order: $\operatorname{proj}_{\mathbf{u}}\mathbf{v}$ lies along $\mathbf{u}$, and in general $\operatorname{proj}_{\mathbf{u}}\mathbf{v}\ne\operatorname{proj}_{\mathbf{v}}\mathbf{u}$ — compare the two settings in Interactive 1.
✏️ Example 4 — Splitting a vector into two perpendicular parts
Let $\mathbf{u}=(2,1)$ and $\mathbf{v}=(3,4)$. Find $\operatorname{proj}_{\mathbf{u}}\mathbf{v}$ and $\operatorname{comp}_{\mathbf{u}}\mathbf{v}$, and write $\mathbf{v}$ as a vector parallel to $\mathbf{u}$ plus a vector orthogonal to $\mathbf{u}$.
💡 Show solution▶
Dot products $\mathbf{v}\cdot\mathbf{u}=6+4=10$ and $\mathbf{u}\cdot\mathbf{u}=4+1=5$.
Projection $\operatorname{proj}_{\mathbf{u}}\mathbf{v}=\dfrac{10}{5}(2,1)=(4,2)$, and $\operatorname{comp}_{\mathbf{u}}\mathbf{v}=\dfrac{10}{\sqrt5}=2\sqrt5\approx4.472$ (which is $\|(4,2)\|$, as it should be).
Split $\mathbf{w}=\mathbf{v}-\operatorname{proj}_{\mathbf{u}}\mathbf{v}=(3,4)-(4,2)=(-1,2)$, so $$\mathbf{v}=\begin{bmatrix}3\\4\end{bmatrix}=\begin{bmatrix}4\\2\end{bmatrix}+\begin{bmatrix}-1\\2\end{bmatrix}.$$
Check $\mathbf{w}\cdot\mathbf{u}=-2+2=0$ ✓, and Pythagoras: $\|\mathbf{v}\|^2=25=20+5=\|(4,2)\|^2+\|(-1,2)\|^2$. ✓ The distance from the point $(3,4)$ to the line through the origin in the direction $\mathbf{u}$ is $\|\mathbf{w}\|=\sqrt5$.
⚠️ Common mistakes
1. The dot product is a number. $(1,2)\cdot(3,4)=11$, not $(3,8)$. There is no "dot product of three vectors" $\mathbf{u}\cdot\mathbf{v}\cdot\mathbf{w}$: $(\mathbf{u}\cdot\mathbf{v})\mathbf{w}$ is a vector and $\mathbf{u}(\mathbf{v}\cdot\mathbf{w})$ is a different one.
2. Norms do not add. $\|\mathbf{u}+\mathbf{v}\|$ is usually less than $\|\mathbf{u}\|+\|\mathbf{v}\|$, and $\|(3,4)\|=5$, not $3+4$.
3. Dividing by the wrong thing. The projection divides by $\mathbf{u}\cdot\mathbf{u}=\|\mathbf{u}\|^2$; the component divides by $\|\mathbf{u}\|$. Mixing them up gives an answer that is $\|\mathbf{u}\|$ times too big or too small.
4. Degrees or radians? $\cos^{-1}$ on a calculator in degree mode gives degrees. Both are fine; say which you use.
Applications: Work and Cosine Similarity
Work. When a constant force $\mathbf{F}$ moves an object through a straight displacement $\mathbf{d}$, only the part of the force along the motion does work. That part is $\operatorname{comp}_{\mathbf{d}}\mathbf{F}=\|\mathbf{F}\|\cos\theta$, so the work done is
$$W=\left(\|\mathbf{F}\|\cos\theta\right)\|\mathbf{d}\|=\mathbf{F}\cdot\mathbf{d}.$$
With $\mathbf{F}$ in newtons and $\mathbf{d}$ in metres, $W$ is in joules (J).
✏️ Example 5 — Work done by a force at an angle
(a) A box is dragged $8$ m across a level floor by a rope that pulls with a force of $50$ N at $30^\circ$ above the horizontal. How much work does the rope do? (b) A force $\mathbf{F}=(20,15,-5)$ N moves an object along the displacement $\mathbf{d}=(3,4,0)$ m. Find the work done.
💡 Show solution▶
(a) $W=\|\mathbf{F}\|\|\mathbf{d}\|\cos\theta=(50)(8)\cos30^\circ=400\cdot\dfrac{\sqrt3}{2}=200\sqrt3\approx346.4$ J. (In components: $\mathbf{F}=(25\sqrt3,25)$, $\mathbf{d}=(8,0)$, $\mathbf{F}\cdot\mathbf{d}=200\sqrt3$. ✓) The upward part of the pull, $25$ N, does no work because it is perpendicular to the motion.
(b) $W=\mathbf{F}\cdot\mathbf{d}=(20)(3)+(15)(4)+(-5)(0)=60+60+0=120$ J.
Cosine similarity. In data science a document is often turned into a vector by counting how many times each word of a fixed vocabulary appears. Two documents about the same topic use words in similar proportions, even if one is much longer. So we compare directions, not lengths: the cosine similarity of two nonzero data vectors is
$$\cos\theta=\frac{\mathbf{u}\cdot\mathbf{v}}{\|\mathbf{u}\|\,\|\mathbf{v}\|}.$$
For count data all entries are $\ge0$, so the value lies between $0$ (no words in common) and $1$ (exactly the same proportions). Recommendation systems, plagiarism checkers and search engines all use it.
✏️ Example 6 — Which documents are alike?
Over the vocabulary (matrix, vector, goal, match), three short articles have word counts $\mathbf{d}_1=(4,3,0,1)$, $\mathbf{d}_2=(2,2,0,0)$ and $\mathbf{d}_3=(0,1,5,3)$. Which of $\mathbf{d}_2$, $\mathbf{d}_3$ is more similar to $\mathbf{d}_1$?
$\mathbf{d}_1$ vs $\mathbf{d}_2$ $\mathbf{d}_1\cdot\mathbf{d}_2=8+6=14$, so $\cos\theta=\dfrac{14}{\sqrt{26}\cdot2\sqrt2}=\dfrac{7}{2\sqrt{13}}\approx0.971$ (angle $\approx13.9^\circ$).
$\mathbf{d}_1$ vs $\mathbf{d}_3$ $\mathbf{d}_1\cdot\mathbf{d}_3=0+3+0+3=6$, so $\cos\theta=\dfrac{6}{\sqrt{26}\sqrt{35}}=\dfrac{6}{\sqrt{910}}\approx0.199$ (angle $\approx78.5^\circ$).
Conclusion $\mathbf{d}_2$ is far more similar to $\mathbf{d}_1$: both are about linear algebra, while $\mathbf{d}_3$ is about football. Notice that the distance tells a different story: $\|\mathbf{d}_1-\mathbf{d}_2\|=\sqrt{4+1+0+1}=\sqrt6\approx2.45$ is small only because both are short. Cosine similarity ignores length, which is what we want when comparing topics.
Interactive 2 — Cosine Similarity versus Distance
Each document is a vector of word counts for two words, "goal" (across) and "matrix" (up). Choose a pair, then stretch document B with the slider — $k=2$ means the same text pasted twice. Play stretches B back and forth: the distance between the tips changes a lot, but the angle and the cosine similarity do not move at all.
1
$\mathbf{A}$, $\mathbf{B}$—
$\mathbf{A}\cdot\mathbf{B}$—
cosine similarity—
angle—
distance $\|\mathbf{A}-\mathbf{B}\|$—
Exercises
I
Dot products, norms and distances. Let $\mathbf{u}=(3,-1,2)$, $\mathbf{v}=(1,4,-2)$ and $\mathbf{w}=(-2,0,5)$.
1 $\mathbf{u}\cdot\mathbf{v}$
2 $\|\mathbf{u}\|$
3 $\|\mathbf{w}\|$ and the unit vector in the direction of $\mathbf{w}$
4 $(\mathbf{u}+\mathbf{v})\cdot\mathbf{w}$
5 $\mathbf{u}\cdot(2\mathbf{v}-\mathbf{w})$
6 The distance $d(\mathbf{u},\mathbf{v})$
7 $\|(1,-2,2,0,4)\|$ in $\mathbb{R}^5$, and the unit vector in its direction
8 The unit vector pointing in the direction opposite to $(6,-8)$
9 The vector of length $6$ in the direction of $(2,-1,2)$
3 $\|\mathbf{w}\|=\sqrt{4+0+25}=\sqrt{29}$; unit vector $\tfrac{1}{\sqrt{29}}(-2,0,5)\approx(-0.371,0,0.928)$.
4 $\mathbf{u}+\mathbf{v}=(4,3,0)$, so $(\mathbf{u}+\mathbf{v})\cdot\mathbf{w}=-8+0+0=-8$. (Also $\mathbf{u}\cdot\mathbf{w}+\mathbf{v}\cdot\mathbf{w}=4+(-12)=-8$. ✓)
5 $2\mathbf{v}-\mathbf{w}=(4,8,-9)$, so $\mathbf{u}\cdot(2\mathbf{v}-\mathbf{w})=12-8-18=-14$. (Also $2(-5)-4=-14$. ✓)
6 $\mathbf{u}-\mathbf{v}=(2,-5,4)$, so $d=\sqrt{4+25+16}=\sqrt{45}=3\sqrt5\approx6.708$.
7 $\sqrt{1+4+4+0+16}=\sqrt{25}=5$; unit vector $\left(\tfrac15,-\tfrac25,\tfrac25,0,\tfrac45\right)$.
8 $\|(6,-8)\|=10$, so the answer is $-\tfrac{1}{10}(6,-8)=\left(-\tfrac35,\tfrac45\right)$.
9 $\|(2,-1,2)\|=3$, so $\tfrac63(2,-1,2)=(4,-2,4)$. Check: $\sqrt{16+4+16}=6$. ✓
II
Angles and orthogonality.
1 Find the angle between $(1,1)$ and $\left(-1,\sqrt3\right)$.
2 Find the angle between $(2,-1,1)$ and $(1,1,2)$.
3 Find the angle between $(1,2,-3)$ and $(-2,-4,6)$.
4 Find the angle between $(3,0,4)$ and $(1,2,2)$, to two decimal places in degrees.
5 Are $(2,-3,1)$ and $(4,2,-2)$ orthogonal?
6 Find $k$ so that $(k,3,-1)$ and $(2,k,5)$ are orthogonal.
7 Find both unit vectors in $\mathbb{R}^2$ orthogonal to $(3,4)$.
8 Show that the triangle with vertices $A(1,0,2)$, $B(2,2,3)$, $C(2,-1,3)$ has a right angle, and find its area.
9 Verify the Cauchy–Schwarz and triangle inequalities for $\mathbf{u}=(1,2,2)$ and $\mathbf{v}=(3,0,-4)$.
Check: dot product, angle and projection calculator in $\mathbb{R}^3$
$\mathbf{u}\cdot\mathbf{v}$—
$\|\mathbf{u}\|$, $\|\mathbf{v}\|$—
angle $\theta$—
$\operatorname{proj}_{\mathbf{u}}\mathbf{v}$—
Type three numbers separated by commas; fractions such as 4/5 and square roots such as sqrt(3) are accepted.
💡 Show solutions▶
1 Dot product $-1+\sqrt3$; norms $\sqrt2$ and $2$. $\cos\theta=\dfrac{\sqrt3-1}{2\sqrt2}=\dfrac{\sqrt6-\sqrt2}{4}=\cos75^\circ$, so $\theta=75^\circ=\tfrac{5\pi}{12}$. (Directions $45^\circ$ and $120^\circ$ from the positive $x$-axis differ by $75^\circ$. ✓)
2 Dot product $2-1+2=3$; both norms $\sqrt6$. $\cos\theta=\tfrac36=\tfrac12$, so $\theta=60^\circ$.
3 $(-2,-4,6)=-2(1,2,-3)$: the vectors point in opposite directions, so $\theta=180^\circ$. (Check: $\cos\theta=\dfrac{-28}{\sqrt{14}\sqrt{56}}=\dfrac{-28}{28}=-1$.)
4 Dot product $3+0+8=11$; norms $5$ and $3$. $\cos\theta=\tfrac{11}{15}$, so $\theta\approx42.83^\circ$.
8 $\overrightarrow{AB}=(1,2,1)$, $\overrightarrow{AC}=(1,-1,1)$, $\overrightarrow{AB}\cdot\overrightarrow{AC}=1-2+1=0$: right angle at $A$. Area $=\tfrac12\|\overrightarrow{AB}\|\|\overrightarrow{AC}\|=\tfrac12\sqrt6\sqrt3=\tfrac{3\sqrt2}{2}\approx2.121$. (Check with Pythagoras: $\|\overrightarrow{BC}\|^2=\|(0,-3,0)\|^2=9=6+3$. ✓)
1 Find $\operatorname{proj}_{\mathbf{u}}\mathbf{v}$ for $\mathbf{v}=(1,2,3)$, $\mathbf{u}=(1,1,1)$, and the part of $\mathbf{v}$ orthogonal to $\mathbf{u}$.
2 Find $\operatorname{proj}_{\mathbf{u}}\mathbf{v}$ and $\operatorname{comp}_{\mathbf{u}}\mathbf{v}$ for $\mathbf{v}=(4,-1)$, $\mathbf{u}=(3,4)$.
3 Find $\operatorname{comp}_{\mathbf{u}}\mathbf{v}$ and $\operatorname{proj}_{\mathbf{u}}\mathbf{v}$ for $\mathbf{v}=(2,-1,3)$, $\mathbf{u}=(1,2,2)$.
4 Write $\mathbf{v}=(5,1)$ as the sum of a vector parallel to $\mathbf{u}=(2,-1)$ and a vector orthogonal to $\mathbf{u}$.
5 Use a projection to find the distance from the point $(3,4)$ to the line $y=x$.
💡 Show solutions▶
1 $\mathbf{v}\cdot\mathbf{u}=6$, $\mathbf{u}\cdot\mathbf{u}=3$: $\operatorname{proj}_{\mathbf{u}}\mathbf{v}=2(1,1,1)=(2,2,2)$; orthogonal part $(1,2,3)-(2,2,2)=(-1,0,1)$, and $(-1,0,1)\cdot(1,1,1)=0$ ✓.
2 $\mathbf{v}\cdot\mathbf{u}=12-4=8$, $\mathbf{u}\cdot\mathbf{u}=25$: $\operatorname{proj}_{\mathbf{u}}\mathbf{v}=\tfrac{8}{25}(3,4)=\left(\tfrac{24}{25},\tfrac{32}{25}\right)$ and $\operatorname{comp}_{\mathbf{u}}\mathbf{v}=\tfrac85$.
3 $\mathbf{v}\cdot\mathbf{u}=2-2+6=6$, $\|\mathbf{u}\|=3$: $\operatorname{comp}_{\mathbf{u}}\mathbf{v}=2$ and $\operatorname{proj}_{\mathbf{u}}\mathbf{v}=\tfrac69(1,2,2)=\left(\tfrac23,\tfrac43,\tfrac43\right)$.
4 $\mathbf{v}\cdot\mathbf{u}=10-1=9$, $\mathbf{u}\cdot\mathbf{u}=5$: parallel part $\tfrac95(2,-1)=\left(\tfrac{18}5,-\tfrac95\right)$; orthogonal part $\left(5-\tfrac{18}5,\,1+\tfrac95\right)=\left(\tfrac75,\tfrac{14}5\right)$. Check: $\tfrac{14}{5}-\tfrac{14}{5}=0$. ✓
5 The line $y=x$ passes through the origin with direction $\mathbf{u}=(1,1)$. $\operatorname{proj}_{\mathbf{u}}(3,4)=\tfrac72(1,1)$, so the orthogonal part is $(3,4)-\left(\tfrac72,\tfrac72\right)=\left(-\tfrac12,\tfrac12\right)$, of length $\tfrac{\sqrt2}{2}\approx0.707$. That is the distance.
IV
Applications and proofs.
1Physics. A constant force $\mathbf{F}=(30,40)$ N moves an object in a straight line from $(0,0)$ to $(5,2)$ (metres). Find the work done.
2Physics. A child pulls a sled $25$ m along level snow with a force of $60$ N directed $35^\circ$ above the horizontal. Find the work done.
3Data. Two customers' purchases in five product categories are $\mathbf{a}=(2,0,1,3,0)$ and $\mathbf{b}=(1,0,0,2,1)$. Find their cosine similarity.
4Grades. Coursework, lab, midterm and final have weights $\mathbf{w}=(0.1,0.2,0.3,0.4)$, and a student's scores are $\mathbf{s}=(80,70,65,90)$. Show that the final grade is a dot product and compute it.
5 Prove that for $c\gt0$ the cosine similarity of $c\mathbf{u}$ and $\mathbf{v}$ equals that of $\mathbf{u}$ and $\mathbf{v}$. What happens when $c\lt0$?
6 Prove the parallelogram identity $\|\mathbf{u}+\mathbf{v}\|^2+\|\mathbf{u}-\mathbf{v}\|^2=2\|\mathbf{u}\|^2+2\|\mathbf{v}\|^2$ and interpret it geometrically.
7 Prove that $\mathbf{u}\cdot\mathbf{v}=\tfrac14\|\mathbf{u}+\mathbf{v}\|^2-\tfrac14\|\mathbf{u}-\mathbf{v}\|^2$, and deduce that $\mathbf{u}+\mathbf{v}$ and $\mathbf{u}-\mathbf{v}$ have equal length exactly when $\mathbf{u}\perp\mathbf{v}$.
💡 Show solutions▶
1 $\mathbf{d}=(5,2)$ m, so $W=\mathbf{F}\cdot\mathbf{d}=150+80=230$ J.
2 $W=\|\mathbf{F}\|\|\mathbf{d}\|\cos\theta=(60)(25)\cos35^\circ=1500\cos35^\circ\approx1228.7$ J.
3 $\mathbf{a}\cdot\mathbf{b}=2+0+0+6+0=8$, $\|\mathbf{a}\|=\sqrt{14}$, $\|\mathbf{b}\|=\sqrt6$: $\cos\theta=\dfrac{8}{\sqrt{84}}=\dfrac{4}{\sqrt{21}}\approx0.873$ — quite similar shoppers.
5 $\dfrac{(c\mathbf{u})\cdot\mathbf{v}}{\|c\mathbf{u}\|\|\mathbf{v}\|}=\dfrac{c(\mathbf{u}\cdot\mathbf{v})}{|c|\|\mathbf{u}\|\|\mathbf{v}\|}$ by Theorems 4.3(c) and 4.4. For $c\gt0$, $\tfrac{c}{|c|}=1$ and nothing changes. For $c\lt0$, $\tfrac{c}{|c|}=-1$: the similarity changes sign (the angle becomes $\pi-\theta$).
6 $\|\mathbf{u}\pm\mathbf{v}\|^2=\|\mathbf{u}\|^2\pm2\,\mathbf{u}\cdot\mathbf{v}+\|\mathbf{v}\|^2$; adding, the $\pm2\,\mathbf{u}\cdot\mathbf{v}$ terms cancel. Geometrically: in any parallelogram, the sum of the squares of the two diagonals equals the sum of the squares of the four sides.
7 Subtracting the two expansions in part 6 gives $\|\mathbf{u}+\mathbf{v}\|^2-\|\mathbf{u}-\mathbf{v}\|^2=4\,\mathbf{u}\cdot\mathbf{v}$; divide by $4$. Hence $\|\mathbf{u}+\mathbf{v}\|=\|\mathbf{u}-\mathbf{v}\|\iff\mathbf{u}\cdot\mathbf{v}=0$: a parallelogram has equal diagonals exactly when it is a rectangle.
🔬 Research–Teaching NexusResearch-tutored · optional, about 30 minutes
Research question. How can a search engine rank documents by how well they match a query, using nothing but dot products?
Why it matters. Library catalogues, legal-document search, news recommendation and modern AI "embeddings" all represent texts as vectors and rank them by cosine similarity. The idea is the angle formula of this section, used in spaces with thousands of dimensions.
What to do.
Sample case: the vocabulary is (solar, energy, storage, battery, football). The query "solar energy storage" is $\mathbf{q}=(1,1,1,0,0)$. Three documents have counts $\mathbf{D}_1=(3,2,0,0,0)$, $\mathbf{D}_2=(0,2,3,4,0)$ and $\mathbf{D}_3=(0,1,0,0,5)$.
Compute the cosine similarity of $\mathbf{q}$ with each document and rank them.
Now rank them by Euclidean distance $\|\mathbf{q}-\mathbf{D}_i\|$ instead. Do the two rankings agree? Which one is more sensible, and why?
A common word such as "energy" tells us little. Re-weight each word by how rare it is (for example, divide the "energy" column by $3$ because it appears in all three documents) and recompute the ranking.
Tools: Spreadsheet (the SUMPRODUCT and SQRT functions), or a few lines of Python.
Hand in: A table of similarities and distances, your two rankings, and a short paragraph explaining when cosine similarity and distance disagree.
Going further. Read about "tf–idf" weighting and about word embeddings, where each word is a vector in $\mathbb{R}^{300}$ and similar meanings have small angles. Try your method on three news headlines in two languages you know.
Instructor note: cosines $\tfrac{5}{\sqrt{39}}\approx0.801$, $\tfrac{5}{\sqrt{87}}\approx0.536$, $\tfrac{1}{\sqrt{78}}\approx0.113$, so the ranking is $\mathbf{D}_1,\mathbf{D}_2,\mathbf{D}_3$. Distances: $\|\mathbf{q}-\mathbf{D}_1\|=\sqrt6\approx2.449$, $\|\mathbf{q}-\mathbf{D}_2\|=\sqrt{22}\approx4.690$, $\|\mathbf{q}-\mathbf{D}_3\|=\sqrt{27}\approx5.196$ — the same order here, but distance penalises long documents, which students can show by doubling $\mathbf{D}_1$ (distance rises to $\sqrt{35}\approx5.92$ while the cosine stays $0.801$).
🧪 Self-check quiz
0/5 correct
Q1. $(1,2,-1)\cdot(3,-1,2)=$
Q2. $\|(2,-3,6)\|=$
Q3. Nonzero vectors with $\mathbf{u}\cdot\mathbf{v}\lt0$ make an angle that is
Q4. $\operatorname{proj}_{\mathbf{u}}\mathbf{v}$ for $\mathbf{v}=(4,3)$ and $\mathbf{u}=(2,0)$ is
Q5. The cosine similarity of $(1,1,0)$ and $(3,3,0)$ is