Q:

Dot product and its representation as sum. 

If I define the dot product $u\cdot v $ where $u,v\in \mathbb{R}^n$ as $u\cdot v= |u||v|\cos \theta$ where $\theta$ is the angle between $u$ and $v$. How can I get that 
  $$u\cdot v= u_1v_1+u_2v_2+u_3v_3 $$
  with $u=u_1e_1+u_2e_2+\cdots+u_ne_n$ and $v=v_1e_1+v_2e_2+\cdots+v_ne_n$?  

$e_1... e_n$ is the canonical base.  
If we think in $\mathbb{R}^2$ we can suppose that, $u$ have an angle of $\alpha$  with the X axis, $v$ have an angle $\beta$ with the $X$ axis, and $\alpha\geq\beta$. Then $\theta=\alpha-\beta$. We get
$$\cos(\alpha-\beta)=\cos\alpha\cos\beta+\sin\alpha\sin\beta $$
Using the relation $cos\alpha= \displaystyle\frac{u_1}{|u|}, \sin \alpha=\displaystyle\frac{u_2}{|u|}$ and analogous  relation for $v$
$$\cos\theta= \displaystyle\frac{u_1}{|u|}\displaystyle\frac{v_1}{|v|}+\displaystyle\frac{u_2}{|u|}\displaystyle\frac{v_2}{|v|}$$
multiplying by |u||v| we get the result.  
Can we generalize this idea to $\mathbb{R}^n$? 
Thanks! 

A:

The dot product defined as 
$$u\cdot v = \|u\|\cdot\|v\|\cos\theta $$
is just the (signed) length of the projection of $u$ on $v$ (or viceversa).  To find such projection, it is sufficient to compute the $\lambda\in\mathbb{R}$ such that $\|u-\lambda v\|$ is minimal.  Notice that:
$$\|u-\lambda v\|^2 = \sum_{i=1}^{n}(u_i-\lambda v_i)^2=p(\lambda) $$
is a quadratic polynomial in $\lambda$ and:
$$p(\lambda) = \|v\|^2\,\lambda^2 - 2\left(\sum_{i=1}^n u_i v_i\right)\lambda + \|u\|^2,$$
hence the minimum for $p(\lambda)$ is attained when:
$$\lambda = \frac{\sum_{i=1}^n u_i v_i}{\|v\|^2}$$
so the (signed) length of the projection of $u$ on $v$ is just:
$$\sum_{i=1}^{n} u_i v_i $$
as wanted.