TITLE: First and second derivative of a summation
QUESTION [25 upvotes]: 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)$?

REPLY [11 votes]: 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
$$