# Thread: Differentiation of absolute values

1. ## Differentiation of absolute values

Is the solution to:

$\frac{d}{da} \sum_{i=1}^n |x_{i}-a|$

just

$-\sum_{i=1}^n |x_{i}-a|$

Thanks!

2. Hello,
Originally Posted by evidor
Is the solution to:

$\frac{d}{da} \sum_{i=1}^n |x_{i}-a|$

just

$-\sum_{i=1}^n |x_{i}-a|$

Thanks!
Assume $x_i$ is a constant with respect to a.
Take just $|x_1-a|$
What is its derivative ?
If $x_1-a>0$, then $|x_1-a|=x_1-a$ and hence the derivative is $\color{red} -1$
If $x_1-a<0$, then $|x_1-a|=-x_1+a$ and hence the derivative is $\color{red} +1$
If $x_1-a=0$, the derivative is $0$

So no, your formula is not correct

3. The easiest way to do this is:

$\frac{d}{da} \sum_{i=1}^n |x_{i}-a| = \frac{d}{da} \sum_{i=1}^n ((x_{i}-a)^2)^\frac {1}{2}$

and then the solution becomes:

$\sum_{i=1}^n \frac {1}{2} \frac {-2(x_{i}-a)}{ ((x_{i}-a)^2)^\frac{1}{2} } = -\sum_{i=1}^n \frac {x_{i}-a}{|x_{i}-a|}$

so now my new question is how do you take the second derivative?

$\frac{d}{da} -\sum_{i=1}^n \frac {x_{i}-a}{|x_{i}-a|}$