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.
Suppose and are two vectors in .
The algebraic definition is to take the sum of the component-wise products:
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
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:
- The standard proof uses the law of cosines; it’s documented in Section 54.1. It’s short but seems somewhat magical.
- I came up with a geometric proof without trigonometry; it’s documented in Section 54.2. It’s longer but easier to come up with.
I won’t dwell on this proof too much in the interest of moving these notes forward.
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!
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. .
- If is a number and is a vector, is scalar multiplication, e.g. .
- If and are vectors, then is dot product, e.g. .
Let’s compute the dot product of and , both ways.
The algebraic definition is easy:
The geometric definition is a bit more work, see Figure 4. In this picture, you can see there are two angles between the axes, and the lengths of the vectors are and . Hence, the angle between them is . So the geometric definition gives that
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.
Let’s compute the dot product of and both ways. See Figure 5.
The algebraic definition is easy:
In this case the two vectors and form a angle between them. You should know this from high school, since the two blue rays in Figure 5 have slopes and respectively. So the cosine of the angle is , and the whole dot product is . (The lengths are and , but there’s no need to actually calculate these.)
This example shows something new:
This might seem stupid in two dimensions, because it’s doing something you already knew how to do with slope. But in there isn’t a concept of slope, so if you want to see whether two vectors are perpendicular in , you’ll want to use the dot product.
If one takes the dot product of a vector with itself, one gets the squared length.
- To see this from the algebraic definition, note that .
- To see this from the geometric definition, note that .
§4.2 [TEXT] Properties of the dot product
If you look at the algebraic definition, you should be able to see easily that:
- , i.e., dot product is commutative.
- , i.e., the dot product is distributive.
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 .
Let’s do an example to see how the dot product lets us compute this.
See the purple vector in Figure 6.
Solution. First, let’s figure out the length of the purple vector. For trigonometry reasons, we know the length of the purple vector is
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:
This is almost what we want, except there’s an unneeded we want to strip out. We know , and hence we get
Now how do we get the purple vector itself? Well, the direction along is the unit vector
and so multiplying by the length gives the desired result:
§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 and behaving slightly differently. An example of a situation of that shape is shown in Figure 7.
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 and :
The scalar component of in the direction of is the number defined by
This is the analog of purple length from before, but now we allow it to be positive, negative, or zero according to , , and , 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
is just always true.
Suppose and are given vectors in .
To compute the scalar component, use the formula
To compute the vector projection, use the formula
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 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 ).
It’s possible to write the projection formula written in other equivalent ways, e.g.
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.
Solution. First, compute
Then,
Let’s also do the example in Figure 7.
Solution. First, compute
Then,
§4.5 [EXER] Exercises
Exercise 4.2.
- Compute the vector projection of in the direction of .
- Compute the scalar component and vector projection of along the direction of .