How to take derivative of sums of absolute values

2.2k Views Asked by At

Take the derivative of $f(m) = \sum_i | x_i - m |$.

I've been told that derivative of each term is +1 or -1. How do you show that?

1

There are 1 best solutions below

2
On BEST ANSWER

Recall that $$ |x|=\begin{cases} x & x\ge 0\\ -x & x<0 \end{cases} $$

So $$ \frac{d}{dx}|x|=\begin{cases} 1 & x> 0\\ -1 & x< 0 \end{cases} $$

The only problem is at zero, of course. The derivative is not defined there, and so it must be omitted.

Thus in your particular case, you get $1$ whenever $x_i> m$ and $-1$ whenever $x_i< m$