Unit 6, lesson 27

Dot Products, Length and Angle

How the dot product of real vectors gives Euclidean length, unit vectors, the distance between vectors, a test for orthogonal vectors and the angle between nonzero vectors.

  • Video 27
  • Length, Angle and Inner Products

Draw one arrow from the origin to (1,2)(1, 2) and another to (2,−1)(2, -1). They look perpendicular, but a drawing is only an estimate, and in four or more dimensions there is no drawing to look at. This lesson builds one computation from the coordinates, the dot product, and shows that it settles questions of length, distance, perpendicularity and angle exactly, in any number of dimensions. Throughout the page a tuple such as (1,2)(1, 2) stands for a column vector.

Key terms

Dot product

Definition For vectors x=(x1,…,xn)\mathbf{x} = (x_1, \dots, x_n) and y=(y1,…,yn)\mathbf{y} = (y_1, \dots, y_n) in Rn\mathbb{R}^n, the dot product is the real number

x⋅y=x1y1+⋯+xnyn=x⊤y.\begin{aligned} \mathbf{x} \cdot \mathbf{y} &= x_1 y_1 + \cdots + x_n y_n \\[0.4em] &= \mathbf{x}^{\top}\mathbf{y}. \end{aligned}

The row x⊤\mathbf{x}^{\top} times the column y\mathbf{y} is a 1×11 \times 1 matrix, identified with that number. The dot product is defined only when both vectors have the same number of entries. For all x,y,z\mathbf{x}, \mathbf{y}, \mathbf{z} in Rn\mathbb{R}^n and every real cc it satisfies

x⋅y=y⋅x,x⋅(y+z)=x⋅y+x⋅z,(cx)⋅y=c (x⋅y),\begin{aligned} \mathbf{x} \cdot \mathbf{y} &= \mathbf{y} \cdot \mathbf{x}, \\[0.4em] \mathbf{x} \cdot (\mathbf{y} + \mathbf{z}) &= \mathbf{x} \cdot \mathbf{y} + \mathbf{x} \cdot \mathbf{z}, \\[0.4em] (c\mathbf{x}) \cdot \mathbf{y} &= c\,(\mathbf{x} \cdot \mathbf{y}), \end{aligned}

and x⋅x=x12+⋯+xn2≥0\mathbf{x} \cdot \mathbf{x} = x_1^2 + \cdots + x_n^2 \ge 0, with equality only for x=0\mathbf{x} = \mathbf{0}.

In plain words Multiply matching entries and add. The answer is a single number, not a vector. It is linear in each input while the other input stays fixed.

Example For u=(1,2)\mathbf{u} = (1, 2) and v=(2,−1)\mathbf{v} = (2, -1) the products are 22 and −2-2, so u⋅v=0\mathbf{u} \cdot \mathbf{v} = 0. For w=(2,1)\mathbf{w} = (2, 1) we get u⋅w=2+2=4\mathbf{u} \cdot \mathbf{w} = 2 + 2 = 4. Doubling only u\mathbf{u} doubles this to 88, while doubling both vectors gives (2,4)⋅(4,2)=16(2, 4) \cdot (4, 2) = 16, four times the original. The dot product is linear in each input separately, not in the pair at once.

Euclidean length

Definition The Euclidean length, or norm, of x=(x1,…,xn)\mathbf{x} = (x_1, \dots, x_n) in Rn\mathbb{R}^n is

∥x∥=x⋅x=x12+x22+⋯+xn2.\begin{aligned} \lVert \mathbf{x} \rVert &= \sqrt{\mathbf{x} \cdot \mathbf{x}} \\[0.4em] &= \sqrt{x_1^2 + x_2^2 + \cdots + x_n^2}. \end{aligned}

It satisfies ∥x∥≥0\lVert \mathbf{x} \rVert \ge 0, with ∥x∥=0\lVert \mathbf{x} \rVert = 0 only for x=0\mathbf{x} = \mathbf{0}, and ∥cx∥=∣c∣ ∥x∥\lVert c\mathbf{x} \rVert = \lvert c \rvert \, \lVert \mathbf{x} \rVert for every real cc. In R2\mathbb{R}^2 and R3\mathbb{R}^3 it is the length given by the Pythagorean theorem, applied once in the plane and once more for the third coordinate.

In plain words Square every entry, add, and take the square root. Squaring removes signs, so an entry of −3-3 contributes as much as an entry of 33.

Example The vector (1,2)(1, 2) has length 1+4=5\sqrt{1 + 4} = \sqrt{5}, and (1,−1,2)(1, -1, 2) has length 1+1+4=6\sqrt{1 + 1 + 4} = \sqrt{6}. Scaling (1,2)(1, 2) by −3-3 gives (−3,−6)(-3, -6), whose length is 45=35\sqrt{45} = 3\sqrt{5}. The scalar reverses the direction, but its absolute value 33 is what multiplies the length.

Unit vector

Definition A unit vector is a vector of length 11. For a nonzero vector x\mathbf{x}, the vector

x∥x∥\frac{\mathbf{x}}{\lVert \mathbf{x} \rVert}

is the unit vector in the direction of x\mathbf{x}. Producing it is called normalizing x\mathbf{x}. The zero vector cannot be normalized, since its length is 00 and it has no direction.

In plain words Normalizing keeps the direction and resets the length to one, by dividing every entry by the length.

Example The vector (1,2)(1, 2) has length 5\sqrt{5}, so its unit vector is

(15,25),\left( \frac{1}{\sqrt{5}}, \frac{2}{\sqrt{5}} \right),

and the squares of its entries add to 15+45=1\frac{1}{5} + \frac{4}{5} = 1. Likewise (3,−4)(3, -4) has length 55 and normalizes to (35,−45)(\frac{3}{5}, -\frac{4}{5}). The unit vector pointing the opposite way is (−35,45)(-\frac{3}{5}, \frac{4}{5}).

Distance between vectors

Definition The distance between vectors x\mathbf{x} and y\mathbf{y} in Rn\mathbb{R}^n is ∥x−y∥\lVert \mathbf{x} - \mathbf{y} \rVert, the length of their difference. It equals ∥y−x∥\lVert \mathbf{y} - \mathbf{x} \rVert. Expanding the squares entry by entry gives

∥x−y∥2=∥x∥2+∥y∥2−2 x⋅y,\begin{aligned} \lVert \mathbf{x} - \mathbf{y} \rVert^2 &= \lVert \mathbf{x} \rVert^2 + \lVert \mathbf{y} \rVert^2 \\[0.4em] &\quad - 2\,\mathbf{x} \cdot \mathbf{y}, \end{aligned}

because each entry contributes (xi−yi)2=xi2−2xiyi+yi2(x_i - y_i)^2 = x_i^2 - 2x_i y_i + y_i^2.

In plain words Subtract first, then measure. The distance is the length of the arrow that runs from the tip of one vector to the tip of the other.

Example For x=(1,2)\mathbf{x} = (1, 2) and y=(4,6)\mathbf{y} = (4, 6) the difference y−x=(3,4)\mathbf{y} - \mathbf{x} = (3, 4) has length 9+16=5\sqrt{9 + 16} = 5. The expansion agrees, since ∥x∥2=5\lVert \mathbf{x} \rVert^2 = 5, ∥y∥2=52\lVert \mathbf{y} \rVert^2 = 52 and x⋅y=16\mathbf{x} \cdot \mathbf{y} = 16 give 5+52−32=255 + 52 - 32 = 25.

Orthogonal vectors

Definition Vectors x\mathbf{x} and y\mathbf{y} in Rn\mathbb{R}^n are orthogonal if x⋅y=0\mathbf{x} \cdot \mathbf{y} = 0. By the expansion of the squared distance, this happens exactly when

∥x−y∥2=∥x∥2+∥y∥2,\lVert \mathbf{x} - \mathbf{y} \rVert^2 = \lVert \mathbf{x} \rVert^2 + \lVert \mathbf{y} \rVert^2,

which for nonzero vectors in R2\mathbb{R}^2 or R3\mathbb{R}^3 is the Pythagorean condition for a right angle between them. So for nonzero vectors in the plane or in space, orthogonal means perpendicular. In higher dimensions the dot product condition is the definition. The zero vector is orthogonal to every vector.

In plain words For nonzero vectors, zero dot product is the coordinate test for a right angle. It works in every dimension, even where no picture is available to check.

Example The opening pair passes the test, since (1,2)⋅(2,−1)=2−2=0(1, 2) \cdot (2, -1) = 2 - 2 = 0. In R4\mathbb{R}^4 take x=(1,1,1,1)\mathbf{x} = (1, 1, 1, 1) and y=(1,−1,2,−2)\mathbf{y} = (1, -1, 2, -2). The products 1,−1,2,−21, -1, 2, -2 cancel, so the vectors are orthogonal although no single product is zero. As a check, ∥x∥2=4\lVert \mathbf{x} \rVert^2 = 4, ∥y∥2=10\lVert \mathbf{y} \rVert^2 = 10, and the difference x−y=(0,2,−1,3)\mathbf{x} - \mathbf{y} = (0, 2, -1, 3) has squared length 14=4+1014 = 4 + 10, as the identity above requires.

Angle between nonzero vectors

Definition For nonzero vectors x\mathbf{x} and y\mathbf{y} in Rn\mathbb{R}^n, the angle between them is the unique θ\theta with 0≤θ≤π0 \le \theta \le \pi such that

cos⁡θ=x⋅y∥x∥ ∥y∥.\cos \theta = \frac{\mathbf{x} \cdot \mathbf{y}}{\lVert \mathbf{x} \rVert \, \lVert \mathbf{y} \rVert}.

In R2\mathbb{R}^2 and R3\mathbb{R}^3 this agrees with the geometric angle. The law of cosines for the triangle with corners 0\mathbf{0}, x\mathbf{x} and y\mathbf{y} gives

∥x−y∥2=∥x∥2+∥y∥2−2∥x∥ ∥y∥cos⁡θ,\begin{aligned} \lVert \mathbf{x} - \mathbf{y} \rVert^2 &= \lVert \mathbf{x} \rVert^2 + \lVert \mathbf{y} \rVert^2 \\[0.4em] &\quad - 2\lVert \mathbf{x} \rVert \, \lVert \mathbf{y} \rVert \cos \theta, \end{aligned}

and comparing with the expansion of the squared distance leaves x⋅y=∥x∥ ∥y∥cos⁡θ\mathbf{x} \cdot \mathbf{y} = \lVert \mathbf{x} \rVert \, \lVert \mathbf{y} \rVert \cos \theta. In higher dimensions the formula is the definition. It makes sense because the quotient always lies between −1-1 and 11, a fact called the Cauchy-Schwarz inequality and proved in the next lesson. The angle is not defined when either vector is zero.

In plain words Dividing by both lengths leaves a number that compares directions only. For nonzero vectors, a positive dot product means an acute angle or the angle 00, zero means a right angle, and a negative dot product means an obtuse angle or the straight angle π\pi.

Example For x=(1,0,1)\mathbf{x} = (1, 0, 1) and y=(0,1,1)\mathbf{y} = (0, 1, 1), the dot product is 11 and both lengths are 2\sqrt{2}, so cos⁡θ=12\cos \theta = \frac{1}{2} and θ=π3\theta = \frac{\pi}{3}. For (1,2)(1, 2) and (−2,−4)(-2, -4) the dot product is −10-10 and the product of the lengths is 5⋅20=10\sqrt{5} \cdot \sqrt{20} = 10, so cos⁡θ=−1\cos \theta = -1 and θ=π\theta = \pi. The second vector is a negative multiple of the first and points the opposite way.

Check yourself

  1. Find the length of x=(2,−1,2)\mathbf{x} = (2, -1, 2) and the unit vector in its direction.
Show the answer

The squared length is 4+1+4=94 + 1 + 4 = 9, so ∥x∥=3\lVert \mathbf{x} \rVert = 3. Dividing each entry by 33 gives the unit vector (23,−13,23)(\frac{2}{3}, -\frac{1}{3}, \frac{2}{3}), and indeed 49+19+49=1\frac{4}{9} + \frac{1}{9} + \frac{4}{9} = 1.

  1. Let a=(2,1,−1)\mathbf{a} = (2, 1, -1) and b=(1,1,3)\mathbf{b} = (1, 1, 3). Decide whether the angle between them is acute, right or obtuse, and find their lengths and the distance between them.
Show the answer

The dot product is 2+1−3=02 + 1 - 3 = 0, and both vectors are nonzero, so the angle is a right angle. The lengths are ∥a∥=4+1+1=6\lVert \mathbf{a} \rVert = \sqrt{4 + 1 + 1} = \sqrt{6} and ∥b∥=1+1+9=11\lVert \mathbf{b} \rVert = \sqrt{1 + 1 + 9} = \sqrt{11}. The difference b−a=(−1,0,4)\mathbf{b} - \mathbf{a} = (-1, 0, 4) has squared length 1+0+16=171 + 0 + 16 = 17, so the distance is 17\sqrt{17}. The expansion confirms it, since 6+11−2⋅0=176 + 11 - 2 \cdot 0 = 17.

  1. One classmate says the distance between (3,0)(3, 0) and (0,4)(0, 4) is 4−3=14 - 3 = 1, the difference of their lengths. Another says the zero vector makes a right angle with (3,4)(3, 4), because their dot product is 00. Correct both claims.
Show the answer

The distance is the length of the difference, not the difference of the lengths. Here (3,0)−(0,4)=(3,−4)(3, 0) - (0, 4) = (3, -4), whose length is 9+16=5\sqrt{9 + 16} = 5.

The zero vector is orthogonal to (3,4)(3, 4), since the dot product is 00. But it has no direction, so there is no angle between it and anything. The angle formula would divide by ∥0∥=0\lVert \mathbf{0} \rVert = 0. Orthogonality extends to the zero vector, while angles and right angles need two nonzero vectors.

How this lesson connects

It also uses the Pythagorean theorem and square roots.