An important vector operation in linear algebra is the dot product. A dot product takes two equal dimension vectors and returns a single scalar value by summing the products of the vectors’ corresponding components. This can be written out formulaically as:

ab=i=1naibia \cdot b = \sum\limits_{i=1}^{n} a_{i}b_{i}

The dot product operation is both commutative (a · b = b · a) and distributive (a · (b+c) = a · b + a · c).

The resulting scalar value represents how much one vector “goes into” the other vector. If two vectors are perpendicular (or orthogonal), their dot product is equal to 0, as neither vector “goes into the other.”

Let’s take a look at an example dot product. Consider the following two vectors:

a=[323],b=[036]a = \begin{bmatrix} 3 \\ 2 \\ -3 \end{bmatrix}, b = \begin{bmatrix} 0 \\ -3 \\ -6 \end{bmatrix}

To find the dot product between these two vectors, we do the following:

ab=30+23+36=12a \cdot b = 3*0 + 2*-3 + -3*-6 = 12

The dot product can also be used to find the magnitude of a vector and the angle between two vectors. To find the magnitude, we can reference Exercise 2 and see that the magnitude of a vector is simply the square root of a vector’s dot product with itself.

a=aa||a|| = \sqrt{a \cdot a}

To find the angle between two vectors, we rely on the dot product between the two vectors and use the following equation.

θ=arccosabab\theta = \arccos{ \frac{a \cdot b}{||a|| ||b||}}

Let’s look at the same two vectors from above:

a=[323]b=[036]a = \begin{bmatrix} 3 \\ 2 \\ -3 \end{bmatrix} b = \begin{bmatrix} 0 \\ -3 \\ -6 \end{bmatrix}

To find the angle between these two vectors, we do the following:

θ=arccos30+23+36(3)2+(2)2+(3)2(0)2+(3)2+(6)2\theta = \arccos{ \frac{3*0 + 2*-3 + -3*-6 }{\sqrt{(3)^2+(2)^2+(-3)^2}*\sqrt{(0)^2+(-3)^2+(-6)^2}}}

Solving this, we end up with:

θ=67.58°\theta = 67.58 \degree


We have another exciting vector applet for you! This time this one shows the dot product and angle between two vectors. Play around with it to get a sense of how it works.

Using the applet, attempt to do the following:

  • Find two vectors that are orthogonal (perpendicular to each other).
  • Figure out when the dot product between two vectors is highest. (Hint: when does a vector “go into” another vector the most?)

Now let’s use it to help with the following practice problem.

Find the dot product and angle between the following sets of vectors:

a=[1722],b=[032]a = \begin{bmatrix} -17 \\ 22 \end{bmatrix}, b = \begin{bmatrix} 0 \\ 32 \end{bmatrix}

Does your answer correspond to what you find in the applet? (Note: it may be tough to get to the exact values, but you can use approximate values to check your answer!)

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?