Dot Products

Earlier you learned that two vectors are added by summing up their individual components:

$$ \begin{bmatrix} u_0 \\ u_1 \\ u_2 \end{bmatrix} + \begin{bmatrix} v_0 \\ v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} u_0 + v_0 \\ u_1 + v_1 \\ u_2 + v_2 \end{bmatrix} $$

Component-wise subtraction, multiplication, and division are defined similarly.

Vectors also support other operations. One very important operation is the dot product. The dot product of two vectors is computed by multiplying their associated components and summing the products. The dot product can be applied to vectors of any dimension, but the two vectors must have the same number of dimensions.

Consider this dot product of 2-vectors \(\mathbf{u}\) and \(\mathbf{v}\):

$$ \mathbf{u} \cdot \mathbf{v} = \begin{bmatrix} u_0 \\ u_1 \end{bmatrix} \cdot \begin{bmatrix} v_0 \\ v_1 \end{bmatrix} = u_0 \times v_0 + u_1 \times v_1 $$

Consider this dot product of 3-vectors \(\mathbf{u}\) and \(\mathbf{v}\):

$$ \mathbf{u} \cdot \mathbf{v} = \begin{bmatrix} u_0 \\ u_1 \\ u_2 \end{bmatrix} \cdot \begin{bmatrix} v_0 \\ v_1 \\ v_2 \end{bmatrix} = u_0 \times v_0 + u_1 \times v_1 + u_2 \times v_2 $$

Try your hand at computing a few dot products:

The semantic meaning of the dot product is probably not obvious. To help build your intuition, draw these three 2-vectors on a grid:

$$ \begin{bmatrix} 3 \\ 2 \end{bmatrix} \qquad \begin{bmatrix} 4 \\ 3 \end{bmatrix} \qquad \begin{bmatrix} -4 \\ -3 \end{bmatrix} $$

In this case, drawing a vector means plotting a line segment from the origin to the vector's coordinates.

Compute these two dot products:

$$ \begin{bmatrix} 3 \\ 2 \end{bmatrix} \cdot \begin{bmatrix} 4 \\ 3 \end{bmatrix} \qquad \begin{bmatrix} 3 \\ 2 \end{bmatrix} \cdot \begin{bmatrix} -4 \\ -3 \end{bmatrix} \qquad $$

Observe that the first and second vectors point in roughly the same direction. The first and third vectors point in roughly opposite directions.

What happens when two vectors are perpendicular to each other? Add this vector to your drawing:

$$ \begin{bmatrix} 2 \\ -3 \end{bmatrix} $$

It is perpendicular to the first. Compute the dot product between them:

$$ \begin{bmatrix} 3 \\ 2 \end{bmatrix} \cdot \begin{bmatrix} 2 \\ -3 \end{bmatrix} $$

Your answers should suggest what the dot product means. Verify your hypothesis interactively by dragging these vector endpoints around:

When the two vectors point in the same general direction, the dot product is positive. When the two vectors point in opposite directions, the dot product is negative. When the two vectors are perpendicular, the dot product is 0. Thus, the sign of the dot product describes the alignment of two vectors.

Measuring alignment between vectors is important—but not yet. For now, you are more interested in the dot product as a machine for multiplying and summing.