Definition
The dot product (also called scalar product or inner product) is an operation that takes two vectors and returns a single number (scalar).
Algebraic Definition
For two vectors \(\vec{a} = (a_1, a_2, ..., a_n)\) and \(\vec{b} = (b_1, b_2, ..., b_n)\):
Simply multiply corresponding components and add them up.
Geometric Definition
The dot product can also be defined using magnitudes and the angle between vectors:
This reveals the geometric meaning: the dot product measures how much the vectors "agree" directionally.
Geometric Interpretation
Calculating the Angle
Rearranging the geometric formula, we can find the angle between any two vectors:
This is how the demo above calculates the angle in real-time!
Properties
- Commutative: \(\vec{a} \cdot \vec{b} = \vec{b} \cdot \vec{a}\)
- Distributive: \(\vec{a} \cdot (\vec{b} + \vec{c}) = \vec{a} \cdot \vec{b} + \vec{a} \cdot \vec{c}\)
- Scalar multiplication: \((c\vec{a}) \cdot \vec{b} = c(\vec{a} \cdot \vec{b})\)
- Self dot product: \(\vec{a} \cdot \vec{a} = |\vec{a}|^2\)
Applications
1. Testing Orthogonality
Two vectors are perpendicular if and only if their dot product is zero:
2. Vector Projection
Project vector \(\vec{a}\) onto vector \(\vec{b}\):
3. Cosine Similarity (AI/ML)
In machine learning, the normalized dot product measures similarity between vectors:
This is the foundation of semantic search, recommendation systems, and RAG (Retrieval Augmented Generation).
4. Physics Applications
- Work: \(W = \vec{F} \cdot \vec{d}\) (force times displacement)
- Power: \(P = \vec{F} \cdot \vec{v}\) (force times velocity)
Code Examples
JavaScript
function dotProduct(a, b) {
return a.reduce((sum, val, i) => sum + val * b[i], 0);
}
// Example
const vecA = [3, 4];
const vecB = [2, 1];
console.log(dotProduct(vecA, vecB)); // 10
Python
import numpy as np
a = np.array([3, 4])
b = np.array([2, 1])
dot = np.dot(a, b) # 10
# Or using @ operator
dot = a @ b # 10
Common Mistakes
- The dot product returns a scalar, not a vector
- Don't confuse with the cross product (which returns a vector)
- Vectors must have the same dimension
Next Steps
- Cross Product - The 3D vector operation
- Vector Projection - Using dot products for projections
- Cosine Similarity - AI applications of dot product
- Dot Product Calculator - Interactive calculation tool