# Thread: Differentiation of absolute values

1. ## Differentiation of absolute values

Is the solution to:

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

just

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

Thanks!

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

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

just

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

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

So no, your formula is not correct

3. The easiest way to do this is:

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

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

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