Notice how subtracting one vector from another produces a vector that connects the two original vectors if the resulting vector is drawn from the end point of one of them. This is perhaps easier to illustrate with another graph.

Plotting v-u in a new location.

That’s all well and good, but how about multiplying them together? Well, as it turns out, there are actually several ways of multiplying vectors. You can multiply the components much like we added and subtracted them above. But we will examine a far more interesting operation here. One that doesn’t produce a vector at all, namely, the dot product.

Calculating the dot product of two vectors actually involves two operations: multiplication and addition. We start by multiplying the vectors’ components element-wise, i.e. [1,3]*[2,2]=[2,6]. We then add the components of the resulting vector together to produce a single number, i.e. 2+6=8. Voila!

So the dot product of v and u is 8. Great! But why would we want to do this? The dot product, in all its simplicity, actually reveals quite a lot of useful information about the relationship between the two vectors being multiplied.

Getting the length of a vector

The dot product can be used to determine the length (also called size or magnitude) of a vector. The length of vector v is denoted by |v|. And we can use the dot product to get our answer.

Remember the Pythagorean theorem which helps us solve for the length of the hypotenuse in a right triangle if we know the lengths of the other sides.

The Pythagorean theorem.

Now, we can actually use this theorem to determine the length of our original vector v=[1,3]. Since v consists of 1 step in the x direction, and 3 steps in the y direction, we can make a right triangle of its components and just plug in the values in the formula. Just imagine v taking the place of c in the graph above, b being 1 and a being 3. So,

which means that the length of v is √10.

Here’s the cool thing: What we did just now was equivalent to taking the dot product of v with itself. We multiplied the components of v with themselves and added them up, which is just what 3² + 1² means. So the length of vector v is simply the square root of the dot product between v and v.

Determining angle

You may not be convinced of the usefulness of the dot product quite yet. Here’s another interesting relationship for you. If two vectors are perpendicular (which in two dimensional space means they form a 90-degree angle but generalises to any n dimensional space) their dot product will always be 0. Let’s dig a little deeper and see why that is.

The Pythagorean theorem is actually just a special case of a more general rule called the law of cosines. The latter applies to any triangle whereas the former only works with right triangles. It involves a third term that takes the angle between a and b into account.

Here, cosθ refers to the cosine of the angle between a and b. Remember that the cosine of an angle is 1 when the angle is 90 degrees. Since the angle θ is always 90° in right triangles (that is the very definition of a right triangle) the whole third term in our equation evaluates to 0 and we are left with the Pythagorean theorem.

Let’s translate the law of cosines into vector notation. We begin by plotting what we’re working with.

So in vector notation, the law of cosines translates to the following (it might look a bit more complicated but just remember that the |x| notation refers to the length of the vectors, similar to the sides of a triangle).

From this version of the law of cosines, we can derive a simpler equation.

Step 1

Multiply out the left hand side of the equation. And keep in mind that a vector dotted with itself is the length of the vector to the power of 2.

Step 2

Cancel terms from the left hand side and the right hand side of the equation.

So it turns out that the dot product of two vectors equals the product of their respective lengths times the cosine of the angle formed between them. And if the angle is 90 degrees, the cosine is 0, so the whole expression evaluates to 0.

Quite nifty!