# First and second derivative of a summation

Consider the function $f(\mu) = \sum_{i = 1}^{n} (x_i - \mu)^2$, where $x_i = i,\,i=1, 2,\dots, n$.

What is the first and second derivative of $f(\mu)$?

• BTW, why not write $f(\mu)$ as $f(\mu) = \sum_{i=1}^n(\mu-i)^2$?
– Anon
Jan 29, 2013 at 19:39
• @Anon: How do you know that your edit is what was intended? If you don’t know for sure, it should be rolled back. Jan 29, 2013 at 19:39
• Expand, or better imagine expanding. Differentiate with respect to $\mu$. If you do it twice, you get a bunch of $2's$. Simplifying the result for "once" requires knowing $1+2+\cdots +n$. Jan 29, 2013 at 19:40
• Hey Anon, honestly I thought of your notation too...I just used the notation my prof gave me...his notation's quite weird sometimes too...Figured this community will really help me much more haha Jan 29, 2013 at 19:41
• @BrianM.Scott I would agree with that. It is tough (at least for me) to imagine $x_i = 1,\ldots,n$ would mean something else though.
– Anon
Jan 29, 2013 at 19:42

$f'(\mu) = -2\sum_{i = 1}^{n} (x_i - \mu)$ and $f''(\mu)=2n$

• This is right, but I don't see how this is a hint, you just gave the full answer (not that there is anything wrong with that.)
– user50407
Jan 29, 2013 at 20:46
• hi michael corleone this is hint because i don't write all arithmetic detail
– M.H
Jan 29, 2013 at 20:49
• Ok, I suppose it doesn't really matter, as the tick on the side shows that the asker was happy with this answer :). I just think of hints as being more about helping the person get started than giving them the answer.
– user50407
Jan 29, 2013 at 20:55
• @user50407 is it only about asker? There are lot of others who lend here in search of a answer. Sep 4, 2016 at 20:55
• Here we have one function (xi−μ) that is part of a larger function in that it is raised to a power of 2, (μ−i)^2 ? According to the extended power rule, we multiply the derivative of the outer function (μ−i)^2 x the derivative of the inner function (xi−μ). The derivative of the outer function brings the 2 down in front as 2*(xi−μ), and the derivative of the inner function (xi−μ) is -1. So the -2 comes from multiplying the two derivatives according to the extend power rule: 2*(xi−μ)*-1 = -2(xi−μ) Sep 19, 2018 at 20:11

$$\frac{d}{d \mu} f(\mu) = -2 \sum_{i=1}^n (x_i - \mu) = -2 \sum_{i=1}^n x_i + 2 n \mu$$

$$\frac{d^2}{d \mu^2} f(\mu) = 2 n$$

• helly rlgordonma, should i start from 1, instead of 0? Jan 29, 2013 at 19:45
• Oh yes, sorry about that. I'll fix that error - doesn't change the gist of the result of course. Jan 29, 2013 at 19:47
• What rule did you use to get to this answer and how the basic rules (sum, product, chain, e.t.c) fit in this derivation at each step. Could you please explain. Thanks. Aug 26, 2018 at 14:51
• In the 1st step on line 1, the chain rule is applied. The term within the brackets is differentiated, producing a -1. Then the bracket itself is differentiated, producing the 2 at the front. The 2nd step on line 1 involves no differentiation. Instead, the bracket is split into two terms. The second term has an n because it is simply the summation from i=1 to i=n of a constant. The summation of a constant is equal to n multiplied by the constant. Then for the second line, there are no extra rules. The first term becomes 0 because it's a constant and the second term loses mu. Hope this helps. Mar 15, 2020 at 17:02

Adding an answer here to further clarify the other ones which are simply answers without steps. To get the first derivative, this can be re-written as:

$$\frac{d}{d\mu}\sum(x-\mu)^{2} \\ = \sum\frac{d}{d\mu}(x-\mu)^{2}$$

After that it's standard fare chain rule

$$= \sum-1 \cdot 2(x-\mu) \\ = -2\sum(x-\mu)$$

Second derivative: you can observe the same property of linear summation: $$\frac{d}{d\mu}-2\sum(x-\mu) \\ =-2\sum\frac{d}{d\mu}(x-\mu) \\ =-2\sum(-1) \\ =2n$$