Chapter 4. The dot product

The dot product is the first surprising result you’ll see in this class, because it has two definitions that look nothing alike, one algebraic and one geometric. Because of that, we’ll be able to get a ton of mileage out of it.

This will be a general theme across the course: almost every new concept we define will have some sort of “algebraic” side (like the coordinates for vector addition) and some “geometric” side (the parallelogram in Figure 2). This is the bar a concept has to pass for us to study it in this class: in order for us to deem a concept worthy of our attention in 18.02, it must have both an interpretation with algebra and an interpretation in geometry.

§4.1 [TEXT] Two different definitions of the dot product

I promised you two definitions right? So here they are.

Definition

Suppose 𝐯=(𝑎1⋮𝑎𝑛) and 𝐰=(𝑏1⋮𝑏𝑛) are two vectors in ℝ𝑛.

The algebraic definition is to take the sum of the component-wise products:

(𝑎1⋮𝑎𝑛)⋅(𝑏1⋮𝑏𝑛)≔𝑎1𝑏1+…+𝑎𝑛𝑏𝑛.

The geometric definition is that if 𝜃 is the angle between the two vectors when we draw them as arrows with a common starting point, then

𝐯⋅𝐰≔|𝐯||𝐰|cos𝜃.

That is, the dot product equals the product of the lengths times the cosine of the included angle.

It’s totally not obvious that these two definitions are the same! I know two reasonable proofs, both of which I’ve typed in the appendix:

I won’t dwell on this proof too much in the interest of moving these notes forward.

Type signature

Remember, the dot product takes two vectors of equal dimensions as inputs and outputs a scalar (i.e. a real number). It does not output a vector! This is the mistake every calculus or linear algebra instructor dreads for the first few weeks of class.

Repeat: dot product output type is number! Not a vector!

Warning: There are a lot of dots, aren’t there?

Confusingly, the multiplication ⋅ is also used for normal multiplication (as we saw in Exercise 2.1). This is why you need to always look at the types of objects so you know which ⋅ is happening. To spell this out:

  • If 𝑎 and 𝑏 are two numbers, 𝑎⋅𝑏=𝑎𝑏 is grade-school multiplication, e.g. 3⋅5=15.
  • If 𝑎 is a number and 𝐯 is a vector, 𝑎⋅𝐯 is scalar multiplication, e.g. 3⋅(57)=(1521).
  • If 𝐯 and 𝐰 are vectors, then 𝐯⋅𝐰 is dot product, e.g. (57)⋅(911)=5(9)+7(11)=122.
Example

Let’s compute the dot product of 𝐯=(−553) and 𝐰=(73−7), both ways.

  • The algebraic definition is easy:

    𝐯⋅𝐰=−5⋅73+53⋅(−7)=−703.
  • The geometric definition is a bit more work, see Figure 4. In this picture, you can see there are two 30° angles between the axes, and the lengths of the vectors are 10 and 14. Hence, the angle 𝜃 between them is 𝜃=90°+(30°+30°)=150°. So the geometric definition gives that

    𝐯⋅𝐰=|𝐯||𝐰|cos𝜃=10⋅14⋅cos(150°)=140⋅−32=−703.

Figure 4: The dot product of 𝐯=(−553) and 𝐰=(73−7) is −703.
Tip

You can see from this example that computing the dot product of two given vectors with coordinates is way easier to do with the algebraic definition. This will be true in general throughout this class:

  • Use the algebraic definition when you need to do practical calculation.
  • Use the geometric definition to interpret the result in some way.
Example

Let’s compute the dot product of 𝐯=(12) and 𝐰=(−63) both ways. See Figure 5.

  • The algebraic definition is easy:

    𝐯⋅𝐰=1⋅(−6)+2⋅(3)=0.
  • In this case the two vectors 𝐯 and 𝐰 form a 90° angle between them. You should know this from high school, since the two blue rays in Figure 5 have slopes 2 and −12 respectively. So the cosine of the angle is 0, and the whole dot product is 0. (The lengths are |𝐯|=5 and |𝐰|=35, but there’s no need to actually calculate these.)

Figure 5: Two perpendicular dot products

This example shows something new:

Memorize
Two nonzero vectors have perpendicular directions if and only if their dot product is 0.

This might seem stupid in two dimensions, because it’s doing something you already knew how to do with slope. But in ℝ3 there isn’t a concept of slope, so if you want to see whether two vectors are perpendicular in ℝ3, you’ll want to use the dot product.

Sample Question
Compute the real number 𝑡 such that (123) and (45𝑡) are perpendicular.
Solution. We need 1⋅4+2⋅5+3⋅𝑡=0, so 𝑡=−143.□
Example: 𝐯⋅𝐯=|𝐯|2

If one takes the dot product of a vector 𝐯=(𝑥1⋮𝑥𝑛) with itself, one gets the squared length.

  • To see this from the algebraic definition, note that 𝐯⋅𝐯=𝑥12+…+𝑥𝑛2=|𝐯|2.
  • To see this from the geometric definition, note that 𝐯⋅𝐯=|𝐯||𝐯|cos(0)=|𝐯|2.

§4.2 [TEXT] Properties of the dot product

If you look at the algebraic definition, you should be able to see easily that:

I point this out briefly so it’s on the record, but you’ll probably also internalize it automatically as you get more practice with actually computing the dot product.

§4.3 [TEXT] Projection

Suppose 𝐯 and 𝐰 are two nonzero vectors in ℝ𝑛. Let 𝜃 denote the angle between them. Imagine projecting the vector 𝐯 onto the line through 𝐰, to get the purple vector shown in Figure 6. This purple vector is typically written proj𝐰(𝐯).

Type signature
The vector projection proj𝐰(𝐯) is a vector that points in either the same or opposite direction as 𝐰.

Let’s do an example to see how the dot product lets us compute this.

Sample Question
Suppose 𝐯=(23) and 𝐰=(41), as in Figure 6. Find the vector proj𝐰(𝐯).

See the purple vector in Figure 6.

Figure 6: The projection of 𝐯=(23) along 𝐰=(41).

Solution. First, let’s figure out the length of the purple vector. For trigonometry reasons, we know the length of the purple vector is

length of purple vector=|𝐯|cos𝜃.

However, we don’t really want to go to the work of figuring out what 𝜃 is.

This is where the dot product comes in. It’s easy to compute the dot product:

11=2⋅4+3⋅1=𝐯⋅𝐰=|𝐯||𝐰|cos𝜃.

This is almost what we want, except there’s an unneeded |𝐰| we want to strip out. We know |𝐰|=42+12=17, and hence we get

length of purple vector=𝐯⋅𝐰|𝐰|=1117.

Now how do we get the purple vector itself? Well, the direction along 𝐰 is the unit vector

𝐰|𝐰|=(417117)

and so multiplying by the length gives the desired result:

proj𝐰(𝐯)=(length of purple vector)𝐰|𝐰|=1117(417117)=(44171117).

□

Remark
The projection only depends on the direction of 𝐰. So if one had re-done the problem above with 𝐰=(200300) instead of (23), the answer would be the same.

§4.4 [RECIPE] Projection

This procedure last section works in general for any vectors, in any number of dimensions. The only catch is that we have to pay a bit of attention to 𝜃<90° and 𝜃>90° behaving slightly differently. An example of a situation of that shape is shown in Figure 7.

Figure 7: The projection of 𝐯=(−33) along 𝐰=(41).

Here, the purple vector points away opposite 𝐰.

In the previous example, we used the word “length” and it was fine. In the new figure Figure 7, we would end up taking negative length instead. That works fine, but it’s annoying; and so we introduce a new word that works in both cases 𝜃<90° and 𝜃>90°:

Definition of scalar component

The scalar component of 𝐯 in the direction of 𝐰 is the number defined by

comp𝐰(𝐯)≔|𝐯|cos𝜃=𝐯⋅𝐰|𝐰|.

This is the analog of purple length from before, but now we allow it to be positive, negative, or zero according to 𝜃<90°, 𝜃>90°, and 𝜃=90°, respectively. But the point is that the cosine can take care of this automatically, and because the cosine is baked into the dot product, life is great: we just don’t have to think about the sign issue at all. That is, the formula with the new notation

proj𝐰(𝐯)=comp𝐰(𝐯)𝐰|𝐰|

is just always true.

Type signature
The scalar component is a number, and can be either positive, negative, or zero.
Recipe for projecting one vector along another

Suppose 𝐯 and 𝐰 are given vectors in ℝ𝑛.

  1. To compute the scalar component, use the formula

    comp𝐰(𝐯)=𝐯⋅𝐰|𝐰|.
  2. To compute the vector projection, use the formula

    proj𝐰(𝐯)=comp𝐰(𝐯)𝐰|𝐰|.
Type signature

Pay attention to type safety when carrying out the recipe to avoid shooting yourself in the foot:

  • In the formula 𝐯⋅𝐰|𝐰|, the numerator is a number (it’s a dot product), the denominator is a number (it’s a length), and we’re dividing two numbers.
  • The formula 𝐯⋅𝐰|𝐰|2𝐰 is more complicated. Focus on just the fraction in front first: the numerator is a number (it’s a dot product), and the denominator is a number (it’s a squared length), so the entire fraction is a number. This fraction then gets multiplied onto a vector 𝐰, so the output type is a vector (actually a multiple of 𝐰).
Warning

It’s possible to write the projection formula written in other equivalent ways, e.g.

proj𝐰(𝐯)=comp𝐰(𝐯)𝐰|𝐰|=(𝐯⋅𝐰|𝐰|)𝐰|𝐰|=𝐯⋅𝐰|𝐰|2𝐰=𝐯⋅𝐰𝐰⋅𝐰𝐰.

I don’t like the last few as much because I think they make it harder to see where the formula comes from, but if you know what you’re doing, feel free to use them.

To show you the recipe isn’t doing anything you haven’t seen before, we redo the earlier example using the new notation. You should notice we get the same numbers as before.

Sample Question
Suppose 𝐯=(23) and 𝐰=(41), as in Figure 6. Calculate proj𝐰(𝐯).

Solution. First, compute

comp𝐰(𝐯)=𝐯⋅𝐰|𝐰|=2⋅4+3⋅142+12=1117.

Then,

proj𝐰(𝐯)=comp𝐰(𝐯)𝐰|𝐰|=1117(417117)=(44171117).

□

Let’s also do the example in Figure 7.

Sample Question
Suppose 𝐯=(−33) and 𝐰=(41), as in Figure 6. Calculate proj𝐰(𝐯).

Solution. First, compute

comp𝐰(𝐯)=𝐯⋅𝐰|𝐰|=−3⋅4+3⋅142+12=−917.

Then,

proj𝐰(𝐯)=comp𝐰(𝐯)𝐰|𝐰|=−917(417117)=(−3617−917).

□

§4.5 [EXER] Exercises

Exercise 4.1. In four-dimensional space ℝ4, the vectors ⟨1,2,3,4⟩ and ⟨5,6,7,𝑡⟩ are perpendicular. Compute 𝑡.

Exercise 4.2.

Exercise 4.3. Let 𝐰=⟨3,4⟩. Compute all unit vectors 𝐯 in ℝ2 for which 𝐯⋅𝐰=3.
Exercise 4.4 (*). Determine all possible values of 𝑎𝑥+𝑏𝑦+𝑐𝑧 over real numbers 𝑎, 𝑏, 𝑐, 𝑥, 𝑦, 𝑧 satisfying 𝑎2+𝑏2+𝑐2=2 and 𝑥2+𝑦2+𝑧2=5.