Cosine Formula for Dot Product

Theorem
Let $\mathbf v,\mathbf w$ be two non-zero vectors in $\R^n$.

The dot product of $\mathbf v$ and $\mathbf w$ can be calculated by:


 * $\mathbf v \cdot \mathbf w = \norm {\mathbf v} \norm {\mathbf w} \cos \theta$

where:


 * $\norm {\, \cdot \,}$ denotes vector length and


 * $\theta$ is the angle between $\mathbf v$ and $\mathbf w$.

Proof
There are two cases, the first where the two vectors are not scalar multiples of each other, and the second where they are.

Case 1

 * AngleBetweenTwoVectors.png

Let the two vectors $\mathbf v$ and $\mathbf w$ not be scalar multiples of each other.

Then by the definition of angle between vectors, we have $\theta$ defined as in the triangle as shown above.

(Note that from Angle Between Non-Zero Vectors Always Defined, such a triangle is guaranteed to exist).

By the Law of Cosines:


 * $\norm {\mathbf v - \mathbf w}^2 = \norm {\mathbf w}^2 + \norm {\mathbf v}^2 - 2 \norm {\mathbf v} \norm {\mathbf w} \cos \theta$

Now, observe that:

Equating these two expressions for $\norm {\mathbf v - \mathbf w}^2$ gives:

which is exactly the desired result.

Case 2
Let $\mathbf v = \paren {v_1, v_2, \ldots, v_n}$ and $\mathbf w = \paren {w_1, w_2, \ldots, w_n}$.

, let $\mathbf v = c \mathbf w$, where $c$ is some scalar.

If $c > 0$, then by the definition of angle between vectors:


 * $\theta = 0 \implies \cos \theta = 1$

If $c < 0$, then by the definition of angle between vectors:


 * $\theta = \pi \implies \cos \theta = -1$

(Note that $c$ cannot be $0$ because we have stipulated $\mathbf v$ and $\mathbf w$ to be non-zero).

Then:

Also see

 * Angle Between Vectors in Terms of Dot Product