Linear Algebra
The Dot Product Explained
By MathSolver Pro Editorial Team · Published
The dot product combines two vectors into a single number that measures how much they point in the same direction. It is the tool for finding angles between vectors, checking perpendicularity, projecting one vector onto another and computing work in physics.
The component formula
The dot product, also called the scalar product, takes two vectors of the same length and returns a single number, not a vector. To compute it, multiply matching components and add the results:
Example 1: a dot product in three dimensions
- Let and .
- Multiply matching components: , and .
- Add: .
The formula works in any number of dimensions, which is why the dot product is so common in data science, where vectors may have thousands of components. It is also the building block of matrix multiplication: every entry of a matrix product is the dot product of a row with a column.
The geometric formula and the angle between vectors
The dot product has a second, geometric description. If is the angle between the two vectors when they are drawn from the same point, then:
Here is the length, or magnitude, of . The two formulas always agree, a fact that follows from the law of cosines applied to the triangle formed by , and . Combining them gives a practical way to find the angle between any two vectors:
Example 2: finding an angle
- Let and .
- .
- and .
- , so .
What the sign tells you
Since lengths are positive, the sign of the dot product matches the sign of . That gives a quick reading of the angle without computing it:
- Positive: the angle is acute, less than 90 degrees, and the vectors point broadly the same way.
- Zero: the vectors are perpendicular, also called orthogonal.
- Negative: the angle is obtuse, more than 90 degrees, and the vectors point broadly in opposite directions.
The zero case is the most useful. For example, , so these vectors are perpendicular. In two dimensions, swapping the components of a vector and negating one of them always produces a perpendicular vector, which is a handy trick for finding normals to lines.
Lengths and unit vectors
A vector dotted with itself gives its length squared, because the angle is zero and :
So the length of is . Dividing a vector by its length produces a unit vector, which has length 1 and points in the same direction. Unit vectors are convenient because the dot product of two unit vectors is simply the cosine of the angle between them.
Projecting one vector onto another
The projection of onto is the shadow that casts on the line through when light shines perpendicular to that line. The dot product gives it directly:
Example 3: a vector projection
- Project onto .
- and .
- .
- Check: the leftover part should be perpendicular to , and indeed .
The number , about 4.427 here, is the scalar component of along : the signed length of the shadow. Projections split a vector into a part along a direction and a part perpendicular to it, a step used everywhere from physics to the least squares method in statistics.
Work done by a force
In physics, only the part of a force that acts along the direction of motion does work. The work done by a constant force moving an object through a displacement is therefore a dot product: .
Example 4: pulling a sled
- A rope pulls a sled with a force of 50 newtons at 30 degrees above the horizontal, and the sled moves 10 metres along flat ground.
- joules.
- The vertical part of the force does no work, because the sled does not move vertically.
Properties and applications
- Commutative: .
- Distributive: .
- Scalars factor out: .
- Cauchy-Schwarz inequality: , which guarantees the cosine formula always gives a value between and 1.
Beyond geometry, the dot product drives cosine similarity, which search engines and recommendation systems use to measure how alike two documents or users are; lighting in 3D graphics, where brightness depends on the dot product of the surface normal with the light direction; and neural networks, whose neurons compute dot products of inputs with weights. The dot product calculator computes the product, the angle and projections with steps, and the cross product calculator handles the other way of multiplying vectors, covered in our cross product guide.
A classic geometry problem
The dot product makes some geometry questions surprisingly quick. What angle does the long diagonal of a cube make with one of its edges? Place the cube with one corner at the origin and edges of length 1 along the axes. The diagonal runs from the origin to , and one edge runs to .
Their dot product is 1, the diagonal has length and the edge has length 1, so and . Doing this with classical geometry requires constructing a right triangle inside the cube and reasoning carefully about its sides; with vectors it takes three lines. The same approach finds the angle between any two lines, planes or chemical bonds once you can describe their directions as vectors.
Common mistakes
- Writing the answer as a vector, for example instead of the sum 2.
- Forgetting to take square roots when computing lengths for the angle formula.
- Dividing by instead of in the vector projection formula.
- Using degrees and radians inconsistently when evaluating or its inverse on a calculator.
- Concluding that vectors are perpendicular when one of them is actually the zero vector.
A good sanity check is the sign. If two vectors clearly point in similar directions in your sketch, the dot product must be positive; if your calculation gives a negative number, look for a sign error in one of the components.
Practice problems
Work these out, then compare with the answers that follow. First, find ; the products are 4, and , so the answer is , and the negative value means the angle is obtuse. Second, find so that is perpendicular to : setting gives . Third, find the angle between and : the dot product is 1 and the lengths are 1 and , so the angle is 45 degrees, as a quick sketch confirms.
A short history
Vector notation is younger than most of school mathematics. In the 1840s, William Rowan Hamilton invented quaternions, numbers with one real and three imaginary parts, and the product of two of his pure quaternions contained both a scalar part and a vector part. In the 1880s, Josiah Willard Gibbs and Oliver Heaviside separated those two pieces into the dot product and the cross product, giving physicists the simpler vector algebra still taught today. Gibbs chose the centred dot as the symbol, which is how the operation got its everyday name.
Frequently asked questions
Is the dot product a vector or a number?
A number, which is why it is also called the scalar product. The cross product is the operation that produces a vector.
How do I know if two vectors are perpendicular?
Compute their dot product. If it is zero, and neither vector is the zero vector, they are perpendicular.
Can I take the dot product of vectors with different lengths?
Vectors of different magnitudes are fine, but they must have the same number of components. A two-component vector cannot be dotted with a three-component one.
Why does the dot product use the cosine of the angle?
Because is the length of the part of that lies along . The dot product multiplies that aligned length by the length of .
What does a dot product of zero mean for two nonzero vectors?
It means the vectors meet at a right angle. Neither has any component in the direction of the other, so the projection of one onto the other is the zero vector.