Let $a_1, a_2, ... a_n$ be real numbers and let $f$ be defined on $\Bbb R$ by $\sum_{i=1}^{n} (a_i -x)^2 , x \in \Bbb R$. A friend and I have been struggling with this for half an hour now. If someone could help us take the derivative of this (or help us determine the final sum), that would be great.

  • $\begingroup$ Remember that differentiation is linear. So you can differentiate each term in the sum individually. $\endgroup$ – carmichael561 Feb 18 '16 at 2:31

There are a number of ways to do this.


$\begin{array}\\ \frac{d}{dx}\sum_{i=1}^{n} (a_i -x)^2 &=\sum_{i=1}^{n} \frac{d}{dx}(a_i -x)^2\\ &=\sum_{i=1}^{n} (-2)(a_i -x)\\ &=-2\sum_{i=1}^{n} (a_i -x)\\ &=-2\sum_{i=1}^{n} a_i +2\sum_{i=1}^{n}x\\ &=-2\sum_{i=1}^{n} a_i +2nx\\ \end{array} $


$\begin{array}\\ \frac{d}{dx}\sum_{i=1}^{n} (a_i -x)^2 &=\frac{d}{dx}\sum_{i=1}^{n} (a_i^2-2a_ix +x^2)\\ &=\sum_{i=1}^{n} \frac{d}{dx}(a_i^2-2a_ix +x^2)\\ &=\sum_{i=1}^{n} (-2a_i +2x)\\ &=-2\sum_{i=1}^{n} a_i +2nx\\ \end{array} $


$\begin{array}\\ \frac{d}{dx}\sum_{i=1}^{n} (a_i -x)^2 &=\frac{d}{dx}\sum_{i=1}^{n} (a_i^2-2a_ix +x^2)\\ &=\frac{d}{dx}\left(\sum_{i=1}^{n} a_i^2-\sum_{i=1}^{n}2a_ix +\sum_{i=1}^{n}x^2\right)\\ &=\frac{d}{dx}\left(\sum_{i=1}^{n} a_i^2-2x\sum_{i=1}^{n}a_i +nx^2\right)\\ &=\frac{d}{dx}\sum_{i=1}^{n} a_i^2-2\frac{d}{dx}x\sum_{i=1}^{n}a_i +\frac{d}{dx}nx^2\\ &=-2\sum_{i=1}^{n}a_i +2nx\\ \end{array} $

In all three cases (fortunately), the derivative is zero when $x = \frac1{n}\sum_{i=1}^{n}a_i $, the average of the $a_i$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.