For computational purposes it is desirable to have a formula that expresses the dot product of two vectors in terms of components. We will derive such a formula for vectors in 3 -space; the derivation for vectors in 2 -space is similar. Let $\mathbf{u}=\left(u_{1}, u_{2}, u_{3}\right)$ and $\mathbf{v}=\left(v_{1}, v_{2}, v_{3}\right)$ be two nonzero vectors. If, $\theta$ is the angle between $\mathbf{u}$ and $\mathbf{v}$, then the law of cosines yields $$ \|\overrightarrow{P Q}\|^{2}=\|\mathbf{u}\|^{2}+\|\mathbf{v}\|^{2}-2\|\mathbf{u}\|\|\mathbf{v}\| \cos \theta $$ Since $\overrightarrow{P Q}=\mathbf{v}-\mathbf{u}$, we can rewrite (14) as $$ \|\mathbf{u}\|\|\mathbf{v}\| \cos \theta=\frac{1}{2}\left(\|\mathbf{u}\|^{2}+\|\mathbf{v}\|^{2}-\|\mathbf{v}-\mathbf{u}\|^{2}\right) $$ or $$ \mathbf{u} \cdot \mathbf{v}=\frac{1}{2}\left(\|\mathbf{u}\|^{2}+\|\mathbf{v}\|^{2}-\|\mathbf{v}-\mathbf{u}\|^{2}\right) $$ Substituting $$ \|\mathbf{u}\|^{2}=u_{1}^{2}+u_{2}^{2}+u_{3}^{2}, \quad\|\mathbf{v}\|^{2}=v_{1}^{2}+v_{2}^{2}+v_{3}^{2} $$ and $$ \|\mathbf{v}-\mathbf{u}\|^{2}=\left(v_{1}-u_{1}\right)^{2}+\left(v_{2}-u_{2}\right)^{2}+\left(v_{3}-u_{3}\right)^{2} $$ we obtain, after simplifying, $$ \mathbf{u} \cdot \mathbf{v}=u_{1} v_{1}+u_{2} v_{2}+u_{3} v_{3} $$ The companion formula for vectors in 2 -space is $$ \mathbf{u} \cdot \mathbf{v}=u_{1} v_{1}+u_{2} v_{2} $$