33

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)$?

bryan.blackbee
  • 4,161
  • 2
  • 29
  • 50
  • BTW, why not write $f(\mu)$ as $f(\mu) = \sum_{i=1}^n(\mu-i)^2$? – Anon Jan 29 '13 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. – Brian M. Scott Jan 29 '13 at 19:39
  • 1
    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$. – André Nicolas Jan 29 '13 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 – bryan.blackbee Jan 29 '13 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 '13 at 19:42
  • Hello, the answers also agree with you, Anon...it should be an accepted convention in writing. Thanks though! – bryan.blackbee Jan 29 '13 at 19:43
  • @Anon: It could have meant that the $x_i$’s are a permutation of ${1,\dots,n}$. (Of course this would not have affected the derivatives.) But in my view substantive changes, no matter how plausible, should never be made without explicit approval by the OP, both because they might be wrong and because one learns better by correcting one’s own errors. – Brian M. Scott Jan 29 '13 at 19:48
  • Just let me clarify in case I have screwed up. In general, you may take $x_i,,i=1,\ldots,n$ as arbitrary real numbers, in which case the final results may depend on $x_i$s themselves (as in the answer of rlgordonma below). Substituting $x_1=1,\ldots,x_n=n$, you obtain the answer for the particular case as stated in the question now. – Anon Jan 29 '13 at 19:49
  • Your $x_i=1,\dots,n$ is meaningless. There is no convention for interpreting it, and there should not be one. – Brian M. Scott Jan 29 '13 at 19:49
  • @BrianM.Scott Sure, I agree with that. I cannot actually edit without approval anyway. The site tells me that my edits will be accepted after a "peer review" process. I thought that the reviewer was the asker itself. – Anon Jan 29 '13 at 19:52
  • @Anon: No, it’s anyone with enough rep to approve edits, and it takes two. Apparently two people who thought the edit acceptable beat me to it; I’d have rejected it had I seen it in the edit queue, with a note similar to what I said above. Never mind; it turned out okay in the end. – Brian M. Scott Jan 29 '13 at 19:56

3 Answers3

29

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 $$

26

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

M.H
  • 11,498
  • 3
  • 30
  • 66
  • 14
    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.) –  Jan 29 '13 at 20:46
  • 2
    hi michael corleone this is hint because i don't write all arithmetic detail – M.H Jan 29 '13 at 20:49
  • 2
    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. –  Jan 29 '13 at 20:55
  • 1
    ok,thanks i accept your idea (but in simple question hint and answer is same ) – M.H Jan 29 '13 at 21:02
  • 5
    @user50407 is it only about asker? There are lot of others who lend here in search of a answer. – Ravinder Payal Sep 04 '16 at 20:55
  • 1
    Is the negative sign (-2) due to chain rule derivation? – Steak Overflow May 23 '17 at 11:13
  • The negative sign (-2) is due to the extended power rule – treeorriffic Sep 19 '18 at 20:03
  • 2
    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−μ) – treeorriffic Sep 19 '18 at 20:11
19

$$\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 $$

Ron Gordon
  • 138,521
  • helly rlgordonma, should i start from 1, instead of 0? – bryan.blackbee Jan 29 '13 at 19:45
  • Oh yes, sorry about that. I'll fix that error - doesn't change the gist of the result of course. – Ron Gordon Jan 29 '13 at 19:47
  • 2
    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. – Talespin_Kit Aug 26 '18 at 14:51
  • 1
    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. – AkThao Mar 15 '20 at 17:02