No history yet

Dot Product

What is the Dot Product?

The dot product is a way to multiply two vectors to get a single number, called a scalar. This simple operation tells us something crucial about the relationship between the vectors' directions. It's also known as the scalar product for this reason.

There are two primary ways to define and calculate the dot product. The first is algebraic, using the components of the vectors. If you have two vectors a=a1,a2,,an\vec{a} = \langle a_1, a_2, \dots, a_n \rangle and b=b1,b2,,bn\vec{b} = \langle b_1, b_2, \dots, b_n \rangle, you multiply their corresponding components and add the results.

ab=i=1naibi=a1b1+a2b2++anbn\vec{a} \cdot \vec{b} = \sum_{i=1}^{n} a_i b_i = a_1 b_1 + a_2 b_2 + \dots + a_n b_n

The second definition is geometric. It uses the magnitudes (or lengths) of the vectors and the angle between them.

ab=abcos(θ)\vec{a} \cdot \vec{b} = \|\vec{a}\| \|\vec{b}\| \cos(\theta)

Both formulas give the same result. The one you use depends on the information you have. If you know the components, the algebraic method is easier. If you know the magnitudes and the angle, the geometric method is the way to go.

Geometric Interpretation

The dot product's real power comes from its geometric meaning. It measures how much one vector points in the same direction as another. Think of it as a measure of alignment.

Look at the geometric formula again: abcos(θ)\|\vec{a}\| \|\vec{b}\| \cos(\theta). The term acos(θ)\|\vec{a}\| \cos(\theta) represents the scalar projection of vector a\vec{a} onto vector b\vec{b}. It's the length of the shadow that a\vec{a} casts on the line defined by b\vec{b}. So, the dot product is essentially the length of this projection multiplied by the length of b\vec{b}.

Lesson image

The sign of the dot product, determined by cos(θ)\cos(\theta), tells you about the vectors' relative orientation:

  • Positive dot product: If 0θ<900^{\circ} \le \theta < 90^{\circ}, then cos(θ)>0\cos(\theta) > 0. The vectors point in generally the same direction.
  • Zero dot product: If θ=90\theta = 90^{\circ}, then cos(θ)=0\cos(\theta) = 0. The vectors are perpendicular, or orthogonal. This is a critical property and one of the dot product's most important uses.
  • Negative dot product: If 90<θ18090^{\circ} < \theta \le 180^{\circ}, then cos(θ)<0\cos(\theta) < 0. The vectors point in generally opposite directions.

The dot product is the key tool for calculating vector projections, vector decompositions, and determining orthogonality.

Applications in Action

The dot product isn't just an abstract concept; it's a practical tool used across science and engineering.

Physics: Calculating Work

In physics, the work done on an object is defined as the force applied in the direction of displacement, multiplied by the magnitude of the displacement. If you pull a wagon with a rope, you're likely pulling up at an angle. Not all of your force contributes to moving the wagon forward. Only the component of the force vector that aligns with the displacement vector does any work.

This is a perfect scenario for the dot product. If F\vec{F} is the force vector and d\vec{d} is the displacement vector, the work done (WW) is their dot product.

W=FdW = \vec{F} \cdot \vec{d}

Machine Learning: Cosine Similarity

In machine learning, data is often represented as high-dimensional vectors. For example, a text document can be converted into a vector where each component corresponds to the frequency of a specific word. To compare two documents and see how similar they are, we can't just look at them. But we can measure the "distance" between their vector representations.

One of the most common similarity metrics is cosine similarity, which is derived directly from the dot product. By rearranging the geometric formula, we can find the cosine of the angle between two vectors.

cos(θ)=abab\cos(\theta) = \frac{\vec{a} \cdot \vec{b}}{\|\vec{a}\| \|\vec{b}\|}

The result is a number between -1 and 1:

  • 1: The vectors point in the exact same direction (maximum similarity).
  • 0: The vectors are orthogonal (no similarity).
  • -1: The vectors point in opposite directions (maximum dissimilarity).

This technique is used in recommendation systems to find users with similar tastes and in search engines to rank documents by relevance to a query.

Quiz Questions 1/6

The dot product of two vectors results in what type of quantity?

Quiz Questions 2/6

Given vectors v=3,5\vec{v} = \langle 3, 5 \rangle and w=2,4\vec{w} = \langle -2, 4 \rangle, what is their dot product, vw\vec{v} \cdot \vec{w}?

From physics to computer science, the dot product provides a fundamental way to analyze the relationship between vectors.