Derivative of L2 norm and double summation I have to derive a constant vector μ for which the following equation is minimized:
$$ \sum_{i=1}^{n}\|x_i - \mu\|_{2}^{2} $$
I haven't done any of this in a long time and I want to know if I'm in the right direction or if I'm messing up. What I have so far is:
$$f(x) = \sum_{i=1}^{n}\|x_i - \mu\|_{2}^{2}  $$
$$f(x) =\sum_{i=1}^n \left(\sqrt{\sum_{j=1}^n(x_{ij}-\mu)^2}\right)^2$$
$$f(x) =\sum_{i=1}^n \sum_{j=1}^n(x_{ij}-\mu)^2$$
$$\frac{\partial f(x)}{\partial \mu} = -2 \sum_{i=1}^n \sum_{j=1}^n (x_{ij} -\mu) = 0$$
$$\sum_{i=1}^n \sum_{j=1}^n x_{ij} - \sum_{i=1}^n \sum_{j=1}^n \mu = 0 $$
$$\mu \cdot n^2 = \sum_{i=1}^n \sum_{j=1}^n x_{ij} $$
$$\mu = \frac{\sum_{i=1}^n \sum_{j=1}^n x_{ij}} {n^2}$$
Did I totally mess up? Can I reduce the double summation? Thanks for any leads
 A: Well, the best fit of a constant to a bunch of datapoints is their mean, which is what you got. If all your numbers $x_{ij}$ are in general different numbers, then you will have to use all of them in calculation of your mean. It's hard to imagine how a sum of numbers can be further simplified / reduced.
Perhaps it would be great to somehow discriminate between scalars and vectors in your notation. You can either emphasize your vectors (e.g. by being bold or having a hat), or use Einstein's notation
A: Here's a different derivation that does not use differentiation.
Compare with minimising a scalar quadratic:
\begin{align*}(x-\mu)^2+(y-\mu)^2&=x^2+y^2-2\mu(x+y)+2\mu^2\\
&=2\left(\mu-\frac{x+y}{2}\right)^2+(x^2+y^2-(x+y)^2/2
\end{align*} Clearly, the minimum value occurs when $\mu=(x+y)/2$. Now generalize to vectors:
\begin{align*}\sum_i\|x_i-\mu\|^2&=\sum_i\left(\|x_i\|^2-2\langle x_i,\mu\rangle+\|\mu\|^2\right)\\
&=\sum_i\|x_i\|^2-\langle2\sum_ix_i,\mu\rangle+n\|\mu\|^2\\
&=n\left\|\mu-\frac{1}{n}\sum_ix_i\right\|^2+\sum_i\|x_i\|^2-\|\sum_ix_i\|^2/n
\end{align*} Again, the minimum occurs when $$\mu=\frac{1}{n}\sum_ix_i$$
