CCalclabhub

Vectors

Cosine similarity and scalar projection

Dividing by both magnitudes removes scale and leaves a dimensionless similarity; dividing by |b| alone leaves the signed length of a's shadow on b.

Last updated

The Formula

cos(theta) = (a · b) / (|a||b|), projection = (a · b) / |b|

Dividing by both magnitudes removes scale and leaves a dimensionless similarity; dividing by |b| alone leaves the signed length of a's shadow on b.

SymbolMeaning
cos(theta)Cosine similarity
|a||b|Product of the two magnitudes
(a · b) / |b|Scalar projection of a onto b

What Each Symbol Means

cos(theta)dimensionless

Cosine similarity

A dimensionless value between -1 and 1 measuring alignment of direction.

|a||b|square length

Product of the two magnitudes

The denominator that normalises the dot product in cosine similarity.

(a · b) / |b|length

Scalar projection of a onto b

The signed length of the component of a lying along the direction of b.

See It Worked With Real Numbers

A formula on its own does not tell you which number goes where. The how to calculate the dot product of two vectors page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.

Where This Formula Appears

This equation is the working core of How To Calculate The Dot Product Of Two Vectors, filed under Math. Every number the guide produces comes from substituting into this one line.

Common Questions

What is the formula for Cosine similarity and scalar projection?

The formula for Cosine similarity and scalar projection is cos(theta) = (a · b) / (|a||b|), projection = (a · b) / |b|. Dividing by both magnitudes removes scale and leaves a dimensionless similarity; dividing by |b| alone leaves the signed length of a's shadow on b.

What does each symbol in Cosine similarity and scalar projection stand for?

cos(theta) is cosine similarity; |a||b| is product of the two magnitudes; (a · b) / |b| is scalar projection of a onto b.

What units should I use with Cosine similarity and scalar projection?

Substitute cos(theta) in dimensionless, |a||b| in square length, (a · b) / |b| in length. Convert every input to those units before you start, because the equation only returns the right answer when the units on both sides agree.

What is a common mistake when using Cosine similarity and scalar projection?

Dropping a negative sign. For a = (2, 0, 0) and b = (-3, 0, 0) the product is -6, not 6. A missing minus sign reverses the qualitative conclusion, turning an obtuse angle into an acute one. Multiply with signs attached from the start rather than taking absolute values and deciding later.