Chapter 15
18 min read
Section 136 of 353

The Dot Product

Vectors and the Geometry of Space

Learning Objectives

By the end of this section, you will be able to:

  1. Compute the dot product of two vectors using both the algebraic and geometric definitions
  2. Interpret the dot product geometrically as a measure of how much two vectors point in the same direction
  3. Apply the dot product to find angles between vectors
  4. Determine when two vectors are orthogonal (perpendicular) using the dot product
  5. Calculate the projection of one vector onto another
  6. Use the dot product in physics applications, especially work and force
  7. Connect the dot product to cosine similarity in machine learning

The Big Picture: Measuring Alignment

"The dot product answers a fundamental question: How much do two vectors point in the same direction?"

Imagine you're pushing a heavy box across the floor. You push with a certain force, but the box only moves horizontally. How much of your effort actually moves the box? If you push straight down, you do no useful work — your force is perpendicular to the motion. If you push parallel to the floor, all your effort moves the box. For any angle in between, only part of your force contributes.

The dot product (also called the scalar product or inner product) precisely quantifies this relationship. It takes two vectors and produces a single number that measures their "alignment."

Where the Dot Product Appears

Physics

  • Work = Force · Displacement
  • Power = Force · Velocity
  • Projection of fields onto surfaces
  • Angle between velocity vectors

Computer Graphics

  • Lighting calculations (Lambert's cosine law)
  • Surface normals and visibility
  • Collision detection
  • Camera viewing angles

Machine Learning

  • Cosine similarity for text
  • Attention mechanisms in transformers
  • Word embeddings comparison
  • Recommendation systems

Engineering

  • Stress analysis (force components)
  • Structural mechanics
  • Signal processing (correlation)
  • Navigation systems

Historical Context: The Birth of Vector Algebra

The dot product emerged in the 19th century as mathematicians developed the modern concept of vectors. William Rowan Hamilton (1805–1865) invented quaternions in 1843, which contained both a scalar and vector part. When you "multiply" two quaternions, the scalar part of the result is related to what we now call the dot product.

Josiah Willard Gibbs (1839–1903) and Oliver Heaviside (1850–1925) later extracted the dot and cross products as separate operations, creating the vector algebra we use today. Gibbs developed this specifically for his work in physics, where he needed to express work and energy in terms of forces and displacements.

Why "Dot" Product?

The name comes from the notation: we write ab\mathbf{a} \cdot \mathbf{b} with a centered dot. This distinguishes it from the cross product a×b\mathbf{a} \times \mathbf{b}, which we'll study next. The dot product returns a scalar (a number), while the cross product returns a vector.


Algebraic Definition

We begin with the component-by-component definition, which is how we actually compute dot products.

Definition: The Dot Product (Algebraic)

Let a=a1,a2,a3\mathbf{a} = \langle a_1, a_2, a_3 \rangle and b=b1,b2,b3\mathbf{b} = \langle b_1, b_2, b_3 \rangle be vectors in R3\mathbb{R}^3. The dot product of a\mathbf{a} and b\mathbf{b} is:

ab=a1b1+a2b2+a3b3\mathbf{a} \cdot \mathbf{b} = a_1 b_1 + a_2 b_2 + a_3 b_3

In 2D: ab=a1b1+a2b2\mathbf{a} \cdot \mathbf{b} = a_1 b_1 + a_2 b_2

In general n-dimensions: ab=i=1naibi\mathbf{a} \cdot \mathbf{b} = \sum_{i=1}^{n} a_i b_i

Example: Computing a Dot Product

Let a=3,2,5\mathbf{a} = \langle 3, -2, 5 \rangle and b=4,1,2\mathbf{b} = \langle 4, 1, -2 \rangle. Find ab\mathbf{a} \cdot \mathbf{b}.

Solution:

ab=(3)(4)+(2)(1)+(5)(2)\mathbf{a} \cdot \mathbf{b} = (3)(4) + (-2)(1) + (5)(-2)

=12210= 12 - 2 - 10

=0= 0

Interpretation: Since the dot product is zero, these vectors areorthogonal (perpendicular) to each other!

OperationNotationResult Type
Dot Producta · bScalar (number)
Cross Producta × bVector
Scalar Multiplicationc·aVector
Vector Additiona + bVector

Interactive: Exploring the Dot Product

Use this interactive visualizer to develop intuition for the dot product. Drag the vector endpoints or use the sliders to see how the dot product changes with the angle between vectors.

Interactive Dot Product Visualizer

Drag the vector endpoints to explore

Vector a = (3.0, 2.0)

|a| = 3.606

Vector b = (2.0, 4.0)

|b| = 4.472

Dot Product Calculation

a · b = axbx + ayby

= (3.0)(2.0) + (2.0)(4.0)

= 6.00 + 8.00

= 14.000

Angle: 29.7°

cos(θ) = 0.8682

Positive: vectors point in similar directions (acute angle)

What to Explore

  • Make vectors point the same direction — the dot product becomes large and positive
  • Make vectors perpendicular — the dot product becomes zero
  • Make vectors point opposite directions — the dot product becomes negative
  • Keep the angle fixed but change magnitudes — the dot product scales with both magnitudes

Geometric Interpretation

The algebraic definition tells us how to compute the dot product. The geometric definition tells us what it means.

The Dot Product (Geometric Form)

If θ\theta is the angle between vectors a\mathbf{a} and b\mathbf{b}, then:

ab=abcosθ\mathbf{a} \cdot \mathbf{b} = |\mathbf{a}| \, |\mathbf{b}| \cos \theta

where a|\mathbf{a}| and b|\mathbf{b}| are the magnitudes (lengths) of the vectors.

Understanding the Geometric Formula

The formula ab=abcosθ\mathbf{a} \cdot \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \cos\theta reveals the true meaning of the dot product:

  • The dot product measures alignment. When θ=0°\theta = 0° (parallel vectors), cosθ=1\cos\theta = 1, and the dot product is maximized.
  • Perpendicular vectors have zero dot product. When θ=90°\theta = 90°, cosθ=0\cos\theta = 0.
  • Opposite vectors give negative dot products. When θ=180°\theta = 180°, cosθ=1\cos\theta = -1.
  • The result scales with both magnitudes. Longer vectors produce larger (in absolute value) dot products.
Angle θcos θDot Product SignInterpretation
1Positive (maximum)Parallel, same direction
0° < θ < 90°0 < cos θ < 1PositiveAcute angle
90°0ZeroPerpendicular (orthogonal)
90° < θ < 180°-1 < cos θ < 0NegativeObtuse angle
180°-1Negative (minimum)Parallel, opposite directions

Properties of the Dot Product

The dot product satisfies several important algebraic properties that make it useful for calculations.

Properties of the Dot Product

1. Commutativity: ab=ba\mathbf{a} \cdot \mathbf{b} = \mathbf{b} \cdot \mathbf{a}

2. Distributivity: a(b+c)=ab+ac\mathbf{a} \cdot (\mathbf{b} + \mathbf{c}) = \mathbf{a} \cdot \mathbf{b} + \mathbf{a} \cdot \mathbf{c}

3. Scalar Multiplication: (ca)b=c(ab)=a(cb)(c\mathbf{a}) \cdot \mathbf{b} = c(\mathbf{a} \cdot \mathbf{b}) = \mathbf{a} \cdot (c\mathbf{b})

4. Self Dot Product: aa=a2\mathbf{a} \cdot \mathbf{a} = |\mathbf{a}|^2

5. Zero Vector: a0=0\mathbf{a} \cdot \mathbf{0} = 0

The Magnitude Connection

Property 4 is particularly useful: a=aa|\mathbf{a}| = \sqrt{\mathbf{a} \cdot \mathbf{a}}. This means we can find a vector's length by taking the dot product with itself and then the square root!


Finding Angles Between Vectors

One of the most important applications of the dot product is finding the angle between two vectors. Rearranging the geometric formula:

cosθ=abab\cos \theta = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}| \, |\mathbf{b}|}

Therefore: θ=arccos(abab)\theta = \arccos\left(\frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}| \, |\mathbf{b}|}\right)

Example: Finding the Angle

Find the angle between a=2,3\mathbf{a} = \langle 2, 3 \rangle and b=4,1\mathbf{b} = \langle 4, -1 \rangle.

Step 1: Compute the dot product

ab=(2)(4)+(3)(1)=83=5\mathbf{a} \cdot \mathbf{b} = (2)(4) + (3)(-1) = 8 - 3 = 5

Step 2: Find the magnitudes

a=22+32=13|\mathbf{a}| = \sqrt{2^2 + 3^2} = \sqrt{13}

b=42+(1)2=17|\mathbf{b}| = \sqrt{4^2 + (-1)^2} = \sqrt{17}

Step 3: Find cos θ

cosθ=51317=52210.3365\cos\theta = \frac{5}{\sqrt{13} \cdot \sqrt{17}} = \frac{5}{\sqrt{221}} \approx 0.3365

Step 4: Find θ

θ=arccos(0.3365)70.3°\theta = \arccos(0.3365) \approx 70.3°


Orthogonality: Perpendicular Vectors

Two vectors are orthogonal (perpendicular) if and only if their dot product is zero.

ab    ab=0\mathbf{a} \perp \mathbf{b} \iff \mathbf{a} \cdot \mathbf{b} = 0

This is because when θ=90°\theta = 90°, cos90°=0\cos 90° = 0, making the entire product zero.

Example: Testing for Orthogonality

Are u=2,3,1\mathbf{u} = \langle 2, -3, 1 \rangle and v=4,3,1\mathbf{v} = \langle 4, 3, 1 \rangle orthogonal?

uv=(2)(4)+(3)(3)+(1)(1)=89+1=0\mathbf{u} \cdot \mathbf{v} = (2)(4) + (-3)(3) + (1)(1) = 8 - 9 + 1 = 0

Yes! Since the dot product is zero, these vectors are orthogonal.


Vector Projection

The projection of a\mathbf{a} onto b\mathbf{b} answers the question: "How much of a\mathbf{a} lies in the direction of b\mathbf{b}?"

Scalar Projection (Component)

The scalar projection (or component) of a\mathbf{a} onto b\mathbf{b} is the signed length of the projection:

compba=abb\text{comp}_\mathbf{b} \mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|}

Vector Projection

The vector projection of a\mathbf{a} onto b\mathbf{b} is a vector in the direction of b\mathbf{b} with the same length as the scalar projection:

projba=abb2b=abbbb\text{proj}_\mathbf{b} \mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|^2} \mathbf{b} = \frac{\mathbf{a} \cdot \mathbf{b}}{\mathbf{b} \cdot \mathbf{b}} \mathbf{b}

Vector Decomposition

Any vector can be decomposed into components parallel and perpendicular to another vector:

a=projba+perpba\mathbf{a} = \text{proj}_\mathbf{b} \mathbf{a} + \text{perp}_\mathbf{b} \mathbf{a}

where perpba=aprojba\text{perp}_\mathbf{b} \mathbf{a} = \mathbf{a} - \text{proj}_\mathbf{b} \mathbf{a} is the component of a\mathbf{a} perpendicular to b\mathbf{b}.


Interactive: Vector Projection

Explore how the projection of vector a\mathbf{a} onto b\mathbf{b} works. The purple vector shows the projection, and the green dashed line shows the perpendicular component.

Vector Projection Visualizer

Vector a = (4.0, 3.0)

|a| = 5.000

Vector b = (5.0, 0.0)

|b| = 5.000

Projection Formula

projba = (a·b / |b|²) b

= (20.00 / 25.00) b

= 0.8000 × (5.0, 0.0)

= (4.000, 0.000)

Scalar projection: compba = 4.0000

Perpendicular: (0.000, 3.000)

The projection is in the same direction as b (acute angle)

Physics Applications

Work Done by a Force

When a constant force F\mathbf{F} moves an object through a displacement d\mathbf{d}, the work done is:

W=Fd=FdcosθW = \mathbf{F} \cdot \mathbf{d} = |\mathbf{F}| |\mathbf{d}| \cos\theta

This formula explains why:

  • Pushing parallel to motion (θ=0°\theta = 0°): Maximum work (W=FdW = Fd)
  • Pushing perpendicular to motion (θ=90°\theta = 90°): No work done (W=0W = 0)
  • Pushing opposite to motion (θ=180°\theta = 180°): Negative work (W=FdW = -Fd), which slows the object

Example: Work on an Inclined Plane

A force of 50 N is applied at 30° above the horizontal to push a cart 10 m along a flat surface. How much work is done?

Solution:

W=Fdcosθ=(50)(10)cos30°W = |\mathbf{F}||\mathbf{d}|\cos\theta = (50)(10)\cos 30°

=50032433 J= 500 \cdot \frac{\sqrt{3}}{2} \approx 433 \text{ J}

The vertical component of the force (50sin30°=2550 \sin 30° = 25 N) does no work on horizontal motion.


Machine Learning Applications

The dot product is fundamental to modern machine learning, appearing in everything from basic similarity measures to the attention mechanisms that power transformers.

Cosine Similarity

Cosine similarity normalizes the dot product by the vector magnitudes:

cosine_similarity(a,b)=abab=cosθ\text{cosine\_similarity}(\mathbf{a}, \mathbf{b}) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}| |\mathbf{b}|} = \cos\theta

This gives a similarity score between -1 (opposite) and 1 (identical direction), regardless of vector magnitudes. This is crucial in NLP where document length shouldn't affect similarity.

Applications in Modern ML

  • Word Embeddings: Words like "king" and "queen" have similar vectors (high cosine similarity), while "king" and "car" are dissimilar
  • Attention Mechanisms: In transformers, attention scores are computed using dot products between query and key vectors
  • Recommendation Systems: Users with similar preference vectors receive similar recommendations
  • Information Retrieval: Search results are ranked by cosine similarity between query and document vectors
Cosine Similarity in Machine Learning

2D Word Embedding Space

kingqueenmanwomanprinceprincess

Click on words to compare their similarity

[0.85, 0.7]

[0.75, 0.82]

Cosine Similarity Formula

cos(θ) = (a · b) / (|a| |b|)

= (0.85 × 0.75 + 0.7 × 0.82) / ...

Similarity:99.0%

"king" and "queen" have very high similarity (99.0%).

In NLP, this means these words appear in similar contexts and have related meanings.

Information Retrieval

Search engines rank documents by cosine similarity to the query vector.

Recommendation Systems

Find similar items or users by comparing their feature vectors.

Attention Mechanisms

Transformers use dot products to compute attention scores between tokens.

Why Cosine Over Euclidean Distance?

Euclidean distance measures absolute separation, while cosine similarity measures directional alignment. For text, a longer document isn't necessarily more different — it just has more words. Cosine similarity captures semantic similarity regardless of document length.


Python Implementation

Computing Dot Products

Dot Product Computation
🐍dot_product.py
3Algebraic Definition

The dot product is computed by multiplying corresponding components and summing the results. In NumPy, element-wise multiplication followed by np.sum() does this efficiently.

EXAMPLE
For a = (3, 4) and b = (2, -1): 3×2 + 4×(-1) = 6 - 4 = 2
13Geometric Definition

The geometric form uses magnitudes and the cosine of the angle between vectors. This reveals the geometric meaning: the dot product measures how much two vectors point in the same direction.

21Numerical Stability

Due to floating-point arithmetic, cos(θ) might slightly exceed [-1, 1]. We clamp it to avoid arccos errors. This is a common numerical computing practice.

36Finding Angles

Rearranging a · b = |a||b|cos(θ), we get cos(θ) = (a · b)/(|a||b|). Then θ = arccos(...) gives the angle in radians.

44Orthogonality Test

Two non-zero vectors are orthogonal (perpendicular) if and only if their dot product is zero. This is because cos(90°) = 0.

57 lines without explanation
1import numpy as np
2
3def dot_product_algebraic(a, b):
4    """
5    Compute dot product using the algebraic definition:
6    a · b = a₁b₁ + a₂b₂ + ... + aₙbₙ
7
8    This is equivalent to element-wise multiplication
9    followed by summation.
10    """
11    return np.sum(a * b)
12
13def dot_product_geometric(a, b):
14    """
15    Compute dot product using the geometric definition:
16    a · b = |a| |b| cos(θ)
17
18    First find magnitudes, then the angle between them.
19    """
20    mag_a = np.linalg.norm(a)
21    mag_b = np.linalg.norm(b)
22
23    if mag_a == 0 or mag_b == 0:
24        return 0.0
25
26    # Find angle using the algebraic formula
27    cos_theta = np.dot(a, b) / (mag_a * mag_b)
28
29    # Clamp to [-1, 1] to handle numerical errors
30    cos_theta = np.clip(cos_theta, -1, 1)
31
32    return mag_a * mag_b * cos_theta
33
34# Example vectors
35a = np.array([3, 4])
36b = np.array([2, -1])
37
38print("Vector a:", a)
39print("Vector b:", b)
40print()
41
42# Compute dot product both ways
43algebraic = dot_product_algebraic(a, b)
44geometric = dot_product_geometric(a, b)
45
46print(f"Dot product (algebraic): {algebraic}")
47print(f"Dot product (geometric): {geometric:.6f}")
48print()
49
50# Find the angle between vectors
51cos_theta = np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
52theta_rad = np.arccos(np.clip(cos_theta, -1, 1))
53theta_deg = np.degrees(theta_rad)
54
55print(f"Angle between vectors: {theta_deg:.2f}°")
56print(f"cos(θ) = {cos_theta:.4f}")
57print()
58
59# Check orthogonality
60orthogonal_example = np.array([3, 0])
61perpendicular = np.array([0, 4])
62print(f"Orthogonal check: {orthogonal_example} · {perpendicular} = {np.dot(orthogonal_example, perpendicular)}")

Vector Projection

Vector Projection Implementation
🐍vector_projection.py
3Vector Projection Formula

proj_b(a) projects vector a onto b. The result is a vector in the direction of b whose length equals how far a extends in that direction.

EXAMPLE
Like dropping a shadow of a onto the line containing b
10Using Dot Products

We use a · b for the numerator and b · b for the denominator. Note that |b|² = b · b, which is more efficient than computing norm then squaring.

21Scalar Projection

The scalar projection is just the signed length (magnitude) of the vector projection. Positive means same direction as b, negative means opposite.

32Vector Decomposition

Any vector can be written as the sum of a component parallel to b and a component perpendicular to b. This is fundamental in physics and graphics.

43Physical Application

Here we decompose a force into horizontal (along direction) and vertical components. The horizontal component does work on horizontal motion.

62 lines without explanation
1import numpy as np
2
3def vector_projection(a, b):
4    """
5    Compute the vector projection of a onto b.
6
7    Formula: proj_b(a) = (a · b / |b|²) b
8
9    This gives the component of a in the direction of b.
10    """
11    dot_ab = np.dot(a, b)
12    dot_bb = np.dot(b, b)  # |b|² = b · b
13
14    if dot_bb == 0:
15        return np.zeros_like(a)
16
17    scalar_proj = dot_ab / dot_bb
18    return scalar_proj * b
19
20def scalar_projection(a, b):
21    """
22    Compute the scalar projection (component) of a onto b.
23
24    Formula: comp_b(a) = a · b / |b|
25
26    This is the signed length of the projection.
27    """
28    mag_b = np.linalg.norm(b)
29    if mag_b == 0:
30        return 0.0
31    return np.dot(a, b) / mag_b
32
33def decompose_vector(a, b):
34    """
35    Decompose vector a into parallel and perpendicular
36    components relative to b.
37
38    a = proj_b(a) + perp_b(a)
39    """
40    parallel = vector_projection(a, b)
41    perpendicular = a - parallel
42    return parallel, perpendicular
43
44# Example: Decompose force vector
45force = np.array([10, 6])      # Force applied
46direction = np.array([1, 0])   # Horizontal direction
47
48print("Force vector:", force)
49print("Direction:", direction)
50print()
51
52# Compute projections
53proj = vector_projection(force, direction)
54comp = scalar_projection(force, direction)
55parallel, perp = decompose_vector(force, direction)
56
57print(f"Vector projection: {proj}")
58print(f"Scalar projection: {comp}")
59print()
60print(f"Parallel component: {parallel}")
61print(f"Perpendicular component: {perp}")
62print()
63
64# Verify decomposition
65reconstructed = parallel + perp
66print(f"Verification: {parallel} + {perp} = {reconstructed}")
67print(f"Matches original: {np.allclose(reconstructed, force)}")

Cosine Similarity for NLP

Cosine Similarity in Machine Learning
🐍cosine_similarity.py
3Cosine Similarity Definition

Cosine similarity is the dot product of two vectors divided by the product of their magnitudes. It measures the angle between vectors, ignoring their lengths.

EXAMPLE
Two unit vectors pointing the same way have similarity 1.0
11Normalization

By dividing by both magnitudes, we normalize the result to [-1, 1]. This makes similarity independent of vector scale — a key advantage in text processing.

21Word Embeddings

In NLP, words are represented as vectors in high-dimensional space. Words with similar meanings have vectors pointing in similar directions.

37Similarity Search

Finding similar words is just finding vectors with high cosine similarity. This powers search engines, recommendation systems, and semantic analysis.

50Word Vector Arithmetic

Famous result: king - man + woman ≈ queen. This shows that word vectors capture semantic relationships that can be manipulated algebraically!

65 lines without explanation
1import numpy as np
2
3def cosine_similarity(a, b):
4    """
5    Compute cosine similarity between two vectors.
6
7    Range: [-1, 1]
8    - 1: vectors point in same direction
9    - 0: vectors are orthogonal
10    - -1: vectors point in opposite directions
11
12    This is the normalized dot product.
13    """
14    mag_a = np.linalg.norm(a)
15    mag_b = np.linalg.norm(b)
16
17    if mag_a == 0 or mag_b == 0:
18        return 0.0
19
20    return np.dot(a, b) / (mag_a * mag_b)
21
22# Word embeddings example (simplified 2D)
23word_vectors = {
24    'king':    np.array([0.85, 0.70]),
25    'queen':   np.array([0.75, 0.82]),
26    'man':     np.array([0.55, 0.45]),
27    'woman':   np.array([0.48, 0.60]),
28    'prince':  np.array([0.72, 0.58]),
29}
30
31print("Word Similarity Analysis")
32print("=" * 40)
33
34# Compare king to other words
35reference = 'king'
36ref_vec = word_vectors[reference]
37
38similarities = {}
39for word, vec in word_vectors.items():
40    if word != reference:
41        sim = cosine_similarity(ref_vec, vec)
42        similarities[word] = sim
43
44# Sort by similarity
45sorted_words = sorted(similarities.items(),
46                      key=lambda x: x[1],
47                      reverse=True)
48
49print(f"\nWords most similar to '{reference}':")
50for word, sim in sorted_words:
51    print(f"  {word}: {sim:.4f} ({sim*100:.1f}%)")
52
53# The famous word arithmetic
54print("\n" + "=" * 40)
55print("Word Arithmetic: king - man + woman = ?")
56print("=" * 40)
57
58result = word_vectors['king'] - word_vectors['man'] + word_vectors['woman']
59print(f"Result vector: {result}")
60
61# Find closest word to result
62best_match = None
63best_sim = -1
64for word, vec in word_vectors.items():
65    sim = cosine_similarity(result, vec)
66    if sim > best_sim:
67        best_sim = sim
68        best_match = word
69
70print(f"Closest word: '{best_match}' (similarity: {best_sim:.4f})")

Common Pitfalls

Pitfall 1: Confusing Dot and Cross Products

The dot product ab\mathbf{a} \cdot \mathbf{b} returns a scalar. The cross product a×b\mathbf{a} \times \mathbf{b} returns a vector. They answer different questions and are not interchangeable.

Pitfall 2: Order Matters for Projection

projba\text{proj}_\mathbf{b} \mathbf{a} (projection of a onto b) is different from projab\text{proj}_\mathbf{a} \mathbf{b} (projection of b onto a). The first is in the direction of b; the second is in the direction of a.

Pitfall 3: Negative Dot Products

A negative dot product doesn't mean the vectors are "opposite" in length — it means the angle between them is obtuse (greater than 90°). Both vectors can point "generally forward" and still have a negative dot product if the angle exceeds 90°.

Numerical Precision

When computing angles using arccos\arccos, numerical errors can push the argument slightly outside [-1, 1], causing NaN results. Always clamp the input: np.clip(cos_theta, -1, 1).


Test Your Understanding

Test Your Understanding
Question 1 of 8

What is the dot product of a = (3, 4) and b = (2, -1)?


Summary

The dot product is one of the most important operations in vector mathematics, connecting algebra, geometry, physics, and modern machine learning.

Key Formulas

FormulaNameUse
a · b = a₁b₁ + a₂b₂ + a₃b₃Algebraic definitionComputation
a · b = |a||b|cos θGeometric definitionFinding angles
θ = arccos(a·b / |a||b|)Angle formulaAngle between vectors
a · b = 0 ⟺ a ⊥ bOrthogonality testPerpendicularity check
proj_b a = (a·b/|b|²)bVector projectionComponent along b
comp_b a = a·b/|b|Scalar projectionLength of projection
|a| = √(a·a)Magnitude formulaFinding vector length

Key Takeaways

  1. The dot product measures alignment between vectors — how much they point in the same direction
  2. Positive dot product: acute angle (similar directions)
  3. Zero dot product: right angle (orthogonal/perpendicular)
  4. Negative dot product: obtuse angle (opposite directions)
  5. Projection decomposes a vector into parallel and perpendicular components relative to another vector
  6. In physics, work = force · displacement
  7. In ML, cosine similarity uses the normalized dot product to compare text, images, and embeddings
The Essence of the Dot Product:
"The dot product distills the relationship between two vectors into a single number — measuring how much they cooperate, oppose, or ignore each other."
Coming Next: In the next section, we'll explore the Cross Product, which answers a different question: Given two vectors, what vector is perpendicular to both? This is essential for finding normal vectors, computing torque, and understanding rotational physics.
Loading comments...