# Derivative of a summation in order to minimize

I am asked to minimize $\sum^n_{i=0}(x_i - C)^2$ with respect only to C so I know I have to take the derivative respect to C, set it equal to 0, and then solve. I have never done summation in my life and this is very new. I have been trying to search the web for information about how to proceed in this cases but all I have found is long theorems of summation or explanayions of very simple operations with summation notation. I have found nevertheless the answer to my question whis is as follows: $$S = \sum^n_{i=0}(x_i - C)^2$$

$$\frac{\partial S}{\partial C} = \sum^n_{i=0} 2 (x_i - C)(-1) = -2 \sum^n_{i=0} (x_i - C)$$

$$\frac{\partial S}{\partial C} = 0 \implies \sum^n_{i=0} (x_i - C) = 0$$

$$\sum^n_{i=0} x_i - \sum^n_{i=0} C = 0$$

$$\sum^n_{i=0} x_i = \sum^n_{i=0} C = nC$$

$$C = \frac{\sum^n_{i=0} X_i}{n}$$

First step , I don't get what this guy is doing, so when he takes the derivative why he puts that (-1) at the end? is it because is originally the square of a difference? that's the only thing I can think of..

Second step, where has the -2 gone? just vanished.

Third step, I get this one.

Fourth, what the hell? what is this nC comng from? what does it mean? I understand that at the end what he is doing is $\sum^n_{i=0} x_i= nC$ so isoltaes C and he finnally gets the result $C = \frac{\sum^n_{i=0} X_i}{n}$. Any reasons though why he chooses to swap $\sum^n_{i=0} C$ instead of $\sum^n_{i=0} x_i$ for $nC$?

Thanks a lot, I'd really appreciate if you could please refer me to any page you might know about summation which doesnt go about 1000 theorems and properties . Unfortunately I can spend much time on sumation as I have many other topics in my exam I need to cover and that's just a a very little part of it. Cheers

-

First step

Think of the sum as a function. To find a minima/maxima for a certain function we need to find it's derivative and set it to 0. And because we have 2 terms in between the parenthesis, we can't just apply the rule $\frac{\partial}{\partial x} x^n = nx^{n-1}$, but instead we apply the chain rule. So that -2 is from the chain rule.

Second step

Let's denote the derivative of the sum as $S_1$, the when $2S_1 = 0$? It's only possible if $S_1 =0$, so we left out the 2.

Fourth step

$C$ is a constant that's independent from $n$ so after every step we just add $C$. If $n$ is the number of steps then we have added $nC$

-

Consider $f(C)=\sum_{i=1}^{n}(x_{i}-C)^{2}$ so by chain rule the derivative of $f$ is:

$f'(C)=\sum_{i=1}^{n}2(x_{i}-C)(-1)$.

To minimize at a differentiable point we need that $f'(C)=0$ so the above is $0$ when:

$0=-\sum_{i=1}^{n}(2x_{i}-2C)$

Multiplying both sides by $-1$ we get

$0=\sum_{i=1}^{n}(2x_{i}-2C)=2\sum_{i=1}^{n}x_{i}-2\sum_{i=1}^{n}C=2\sum_{i=1}^{n}x_{i}-2C\sum_{i=1}^{n}1=2\sum_{i=1}^{n}x_{i}-2Cn$.

$\sum_{i=1}^{n}1=n$ since $\sum_{i=1}^{n}a_{i}=a_{1}+...+a_{n}$ by definition and we can take $a_{i}=1$ for all $i$.

So

$2Cn=2\sum_{i=1}^{n}x_{i}$

Dividing by $2n$ we get $C=\frac{\sum_{i=1}^{n}x_{i}}{n}$

-
Thanks very much for your answer. When you have 2Σ Xi - 2ΣC and you go 2Σ Xi - 2C Σ 1 , why dont you do the same with the 2Σ Xi? So it becomes 2 x1 Σ 1? Sorry though, about not writing it in proper notation. Cheers –  Maximilian1988 Sep 14 '13 at 2:25
You can't pull the $x_{i}$ out of the sum since it depends on the index $i$. –  user71352 Sep 14 '13 at 2:29
Ok, thanks a lot for your answers. You have been indeed very helpful. :) –  Maximilian1988 Sep 14 '13 at 2:30
Your welcome. Always happy to help. –  user71352 Sep 14 '13 at 2:31

Step 1: the $-1$ comes from the chain rule.

Step 2: We set the derivative equal to $0$, then divide both sides by $2$. That's why the $2$ goes away.

Step 4: $C + \cdots + C = nC$. ($C$ appears $n$ times on the left.)

-