Linear Algebra, Interactive EditionXYZ Homework Edition

⇩ Download ▾

0.6 The Dot Product and the Angle Between Vectors

Adding vectors and scaling them never leave the vectors' own world: the answer is another vector. The dot product is different. It takes two vectors of ℝn\mathbb{R}^n and returns a number, by multiplying matching components and adding the results:

𝐮 · 𝐯 = u 1 v 1 + u 2 v 2 + ⋯ + u n v n \mathbf{u} \cdot \mathbf{v} = u_1 v_1 + u_2 v_2 + \cdots + u_n v_n

For 𝐮=(1,2,2)\mathbf{u} = (1, 2, 2) and 𝐯=(2,−1,2)\mathbf{v} = (2, -1, 2) that is 2−2+4=42 - 2 + 4 = 4. The recipe is symmetric, so 𝐮·𝐯=𝐯·𝐮\mathbf{u} \cdot \mathbf{v} = \mathbf{v} \cdot \mathbf{u}; it is built from products and sums, so it distributes, 𝐮·(𝐯+𝐰)=𝐮·𝐯+𝐮·𝐰\mathbf{u} \cdot (\mathbf{v} + \mathbf{w}) = \mathbf{u} \cdot \mathbf{v} + \mathbf{u} \cdot \mathbf{w}, and scalars pull out, (k𝐮)·𝐯=k(𝐮·𝐯)(k\mathbf{u}) \cdot \mathbf{v} = k(\mathbf{u} \cdot \mathbf{v}). And a vector dotted with itself is the sum of its squared components, which you have met already:

𝐯 · 𝐯 = v 1 2 + v 2 2 + ⋯ + v n 2 = | 𝐯 | 2 \mathbf{v} \cdot \mathbf{v} = v_1^2 + v_2^2 + \cdots + v_n^2 = |\mathbf{v}|^2

So 𝐯·𝐯\mathbf{v} \cdot \mathbf{v} is never negative, and it is zero only for the zero vector. Length is a dot product in disguise, and that is the first hint that this number knows geometry.

What it knows is the angle. The figure fixes 𝐮=(2,1,0)\mathbf{u} = (2, 1, 0), puts 𝐯=(a,b,c)\mathbf{v} = (a, b, c) on three sliders, and fills the angle between them with a sector lying in the plane the two vectors span.

Two thick shaded arrows leaving the origin: a fixed light gray one, the vector u, ending at (2, 1, 0) on the floor, and a movable one, the vector v, ending at (a, b, c), whose components are set by three sliders that start at 1, 3 and 0. A faint translucent sheet, dark blue while it lies in the floor and outlined by a thin light gray line, is the plane the two arrows span, a thin gray segment joins their tips as the third side of a triangle, and a small filled sector, a pie slice with its point at the origin, fills the angle between the two arrows and lies in the plane they span. At the starting values that angle is exactly 45 degrees. Raising c lifts the movable arrow off the floor, and the sheet, the gray side and the sector all tilt with it, the angle opening to about 53 degrees at c = 2. Setting a to 1 and b to -2 makes the sector a quarter circle for every value of c, since every vector of the form (1, -2, c) is perpendicular to u. Setting v to (-2, -1, 0), the opposite of u, puts the two arrows on one line: they span no plane, so the sheet collapses to a line and the sector disappears, even though the angle between them is 180 degrees; raising c to 0.1 brings the sector back as an almost-half disk standing upright. Setting v to (2, 1, 0) makes the two arrows coincide, the sheet collapse to a line, and the sector vanish at 0 degrees.Explore in 3D (opens in a new tab)

Two thick shaded arrows leaving the origin: a fixed light gray one, the vector u, ending at (2, 1, 0) on the floor, and a movable one, the vector v, ending at (a, b, c), whose components are set by three sliders that start at 1, 3 and 0. A faint translucent sheet, dark blue while it lies in the floor and outlined by a thin light gray line, is the plane the two arrows span, a thin gray segment joins their tips as the third side of a triangle, and a small filled sector, a pie slice with its point at the origin, fills the angle between the two arrows and lies in the plane they span. At the starting values that angle is exactly 45 degrees. Raising c lifts the movable arrow off the floor, and the sheet, the gray side and the sector all tilt with it, the angle opening to about 53 degrees at c = 2. Setting a to 1 and b to -2 makes the sector a quarter circle for every value of c, since every vector of the form (1, -2, c) is perpendicular to u. Setting v to (-2, -1, 0), the opposite of u, puts the two arrows on one line: they span no plane, so the sheet collapses to a line and the sector disappears, even though the angle between them is 180 degrees; raising c to 0.1 brings the sector back as an almost-half disk standing upright. Setting v to (2, 1, 0) makes the two arrows coincide, the sheet collapse to a line, and the sector vanish at 0 degrees.

The fixed vector 𝐮=(2,1,0)\mathbf{u} = (2, 1, 0) and the movable 𝐯=(a,b,c)\mathbf{v} = (a, b, c), with the angle between them drawn as a filled sector inside the plane they span, a faint translucent sheet outlined in light gray. The thin gray side joining their tips is 𝐮−𝐯\mathbf{u} - \mathbf{v}, the third side of the triangle the law of cosines will use.

Explore the figure

  1. At the starting values 𝐯=(1,3,0)\mathbf{v} = (1, 3, 0), both vectors lie in the floor and the sector is an eighth of a turn: the angle is 45∘45^\circ. Compute the number: 𝐮·𝐯=2+3+0=5\mathbf{u} \cdot \mathbf{v} = 2 + 3 + 0 = 5, while |𝐮||𝐯|=510=50|\mathbf{u}| \, |\mathbf{v}| = \sqrt{5} \, \sqrt{10} = \sqrt{50}, and 5/50=1/25/\sqrt{50} = 1/\sqrt{2}, which is cos45∘\cos 45^\circ.
  2. Drag cc to 22. The vector 𝐯\mathbf{v} lifts off the floor, the plane tilts with it, and the sector opens. The dot product is still 55, because 𝐮\mathbf{u} has nothing in the third component to multiply against; but |𝐯||\mathbf{v}| has grown to 14\sqrt{14}, so the cosine has dropped to 5/70≈0.5985/\sqrt{70} \approx 0.598 and the angle is about 53∘53^\circ.
  3. Set a=1a = 1 and b=−2b = -2, with any cc. Now 𝐮·𝐯=2−2+0=0\mathbf{u} \cdot \mathbf{v} = 2 - 2 + 0 = 0, and the sector is a quarter turn — a right angle. Sweep cc through its whole range and watch the sector stay a quarter turn: every vector (1,−2,c)(1, -2, c) is perpendicular to 𝐮\mathbf{u}, a whole plane of them.
  4. Set a=−2a = -2, b=−1b = -1 and c=0c = 0, so that 𝐯=−𝐮\mathbf{v} = -\mathbf{u}. The two arrows now lie along one line and span no plane, so the sheet collapses to a line and the sector, with no plane to lie in, disappears. The angle is still 180∘180^\circ, since cosθ=−5/(55)=−1\cos \theta = -5/(\sqrt{5} \, \sqrt{5}) = -1, and the dot product −4−1=−5-4 - 1 = -5 is the most negative it can be for this length. Nudge cc to 0.10.1 and the sector comes back as an almost-half disk, about 177∘177^\circ, standing in the upright plane through 𝐮\mathbf{u}. Then set a=2a = 2, b=1b = 1 and c=0c = 0: the two vectors coincide, the sector collapses, and the dot product 𝐮·𝐮=5=|𝐮|2\mathbf{u} \cdot \mathbf{u} = 5 = |\mathbf{u}|^2 is the most positive.

The law of cosines, rewritten

Draw 𝐮\mathbf{u} and 𝐯\mathbf{v} from a common tail, with the angle θ\theta between them, 0≤θ≤π0 \le \theta \le \pi. The vector 𝐮−𝐯\mathbf{u} - \mathbf{v} from the tip of 𝐯\mathbf{v} to the tip of 𝐮\mathbf{u} closes a triangle whose sides have lengths |𝐮||\mathbf{u}|, |𝐯||\mathbf{v}| and |𝐮−𝐯||\mathbf{u} - \mathbf{v}|, and the law of cosines from trigonometry says

| 𝐮 − 𝐯 | 2 = | 𝐮 | 2 + | 𝐯 | 2 − 2 | 𝐮 | | 𝐯 | cos θ |\mathbf{u} - \mathbf{v}|^2 = |\mathbf{u}|^2 + |\mathbf{v}|^2 - 2 \, |\mathbf{u}| \, |\mathbf{v}| \cos \theta

Now expand the left side with the dot product's own rules. Since a squared length is a self dot product, |𝐮−𝐯|2=(𝐮−𝐯)·(𝐮−𝐯)|\mathbf{u} - \mathbf{v}|^2 = (\mathbf{u} - \mathbf{v}) \cdot (\mathbf{u} - \mathbf{v}), and distributing gives 𝐮·𝐮−2𝐮·𝐯+𝐯·𝐯=|𝐮|2−2𝐮·𝐯+|𝐯|2\mathbf{u} \cdot \mathbf{u} - 2 \, \mathbf{u} \cdot \mathbf{v} + \mathbf{v} \cdot \mathbf{v} = |\mathbf{u}|^2 - 2 \, \mathbf{u} \cdot \mathbf{v} + |\mathbf{v}|^2. Setting the two expansions equal, the squared lengths cancel and what remains is

𝐮 · 𝐯 = | 𝐮 | | 𝐯 | cos θ \mathbf{u} \cdot \mathbf{v} = |\mathbf{u}| \, |\mathbf{v}| \cos \theta

That is the geometric meaning of the dot product: the product of the two lengths, discounted by the cosine of the angle between them. Read backwards, it computes the angle from components alone, cosθ=𝐮·𝐯/(|𝐮||𝐯|)\cos \theta = \mathbf{u} \cdot \mathbf{v} / (|\mathbf{u}| \, |\mathbf{v}|) — and since nothing in the derivation used a picture beyond the triangle, the same formula defines the angle between two vectors of ℝn\mathbb{R}^n, where no protractor could reach.

Two consequences carry the rest of the book. First, the sign of the dot product is the sign of the cosine: positive means the angle is acute, the vectors lean the same way; negative means obtuse. Second, and most important, the dot product is zero exactly when cosθ=0\cos \theta = 0, that is, when θ=90∘\theta = 90^\circ. Two vectors with 𝐮·𝐯=0\mathbf{u} \cdot \mathbf{v} = 0 are called orthogonal. For nonzero vectors in the plane or in space, orthogonal simply means perpendicular; the word is chosen because the test 𝐮·𝐯=0\mathbf{u} \cdot \mathbf{v} = 0 makes sense in ℝn\mathbb{R}^n, and even for the zero vector, which is orthogonal to everything without having an angle with anything.

55
The dot product at the figure's starting values ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text The dot product at the figure's starting values, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The two vectors of the figure at its default, handed to a computer algebra system: 𝐮·𝐯=5\mathbf{u} \cdot \mathbf{v} = 5.

4545
And the angle they make, exactly ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text And the angle they make, exactly, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The same two vectors, and the number the sector in the figure is drawing: the engine computes arccos(5/(510))\arccos\big(5/(\sqrt{5}\sqrt{10})\big), recognizes the cosine as 2/2\sqrt{2}/2, and returns exactly 45∘45^\circ. Step 1 asks you to read that off the figure; this is the same claim with no eye in the loop. A decimal such as 45.045.0 would be refuted here rather than accepted, which is why the starting components were chosen to land on a closed form.

00
A whole plane of perpendicular vectors ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text A whole plane of perpendicular vectors, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

Step 3 of the exploration claims that (1,−2,c)(1, -2, c) is perpendicular to 𝐮\mathbf{u} for every value of the slider, and a figure can only show you the values you drag to. Here the third component is left as the symbol cc and the dot product still comes back 00 — a statement about the whole slider, and about the values beyond its ends.

44
The worked example's dot product ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text The worked example's dot product, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The dot product of (1,2,2)(1, 2, 2) and (2,−1,2)(2, -1, 2): 44. Over the product of lengths 99, that is the cosine 4/94/9 of the worked example.

arccos(49)\arccos\left(\frac{4}{9}\right)
Its angle, in closed form ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text Its angle, in closed form, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

And the angle itself. arccos(4/9)\arccos(4/9) is not one of the nine angles the engine folds to a closed form, so it ships exactly as written rather than as the 63.6∘63.6^\circ the prose rounds to — the decimal is the approximation, and this is the number.

22
The right-angle condition, solved ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text The right-angle condition, solved, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The orthogonality condition (s,1,2)·(2,s,−3)=0(s, 1, 2) \cdot (2, s, -3) = 0, written out and handed to a computer algebra system: one root, s=2s = 2.

An original work of XYZ Homework, built around interactive XYZ 3D figures. Chapters 1–6 follow the topic sequence of Interactive Linear Algebra (Margalit & Rabinoff, Georgia Tech, GNU FDL). Chapter 0's scope (its topics, their order, and the idea each figure shows) follows the Vectors chapter of Ximera's Linear Algebra: An Interactive Introduction. The prose, worked examples and figures were written for this book, which is not affiliated with or endorsed by the authors of either work. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or any other accessibility standard. Every page is built against an automated accessibility gate, and our target for the published editions is WCAG 2.2 Level AA. If something is unusable, please tell us.