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 = \left \Vert{ \mathbf v }\right \Vert \left \Vert{ \mathbf w }\right \Vert \cos \theta$

where:


 * $\left\Vert{\cdot}\right\Vert$ 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:


 * $\left\Vert{ \mathbf {v}-\mathbf{w} }\right\Vert^2 = \left\Vert{ \mathbf w }\right\Vert^2 + \left\Vert{ \mathbf v }\right\Vert^2 - 2 \left\Vert{ \mathbf v }\right\Vert \left\Vert{ \mathbf w }\right\Vert \cos \theta$.

Now, observe that:

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

which is exactly the desired result.

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

WLOG 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