The modulus (or absolute value) function of x is defined as:

y=|x|, \qquad \text{ where }\qquad |x| = \begin{cases} x, & \text{if } x \geq 0, \\ -x, & \text{if } x < 0. \end{cases}


To compute the derivative, consider two cases separately:


  1. For x > 0:

    \frac{d}{dx} |x| = \frac{d}{dx} x = 1.


  2. For x < 0:

    \frac{d}{dx} |x| = \frac{d}{dx} (-x) = -1.

Conclusion

The derivative of the function |x| for x\neq 0 is

\boxed{ \frac{d}{dx} |x| = \begin{cases} 1, & \text{if } x > 0, \\ -1, & \text{if } x < 0. \end{cases} }


Other writings. It is possible to write the result with a single formula. For example, using the sign of x, function, which is defined just as that function that is 1 for any positive input, and -1 for negative input:

\operatorname{sgn}(x) = \begin{cases} 1, & \text{if } x > 0, \\ -1, & \text{if } x < 0. \end{cases}


We thus have the compact formula

\frac{d}{dx} |x| = \operatorname{sgn}(x), \quad \text{per } x \neq 0,


which can also be written like this:

\frac{d}{dx} |x| = \frac{|x|}{x}, \quad \text{for } x \neq 0.


The function y=|x| is also defined in x=0. How do we study the derivative in this value?


The absolute value function of x is not differentiable in x=0

To show this we must resort to the definition of derivative. Denoted by f the function f(x)=|x| by definition f is differentiable at 0 if the limit of the difference quotient of f at 0,

\displaystyle \lim_{h \to 0} \frac{f(0+h) - f(0)}{h}


exists and is finite. Since here f(0+h)=f(h)=|h| e f(0)=0 we find

\displaystyle \lim_{h \to 0} \frac{|h|}{h}.

Now let’s observe that

 \frac{|h|}{h}=\begin{cases} 1, & \mbox{if }h > 0 \\ -1, & \mbox{if } h < 0 \end{cases}


So the limit from the right as h\to 0 is 1, while the limit from the left is -1. We conclude that the limit of the difference quotient does not exist: this means that f is not differentiable at x=0.

Observation

Here is the graph of the function y= |x|: let’s see what happens from a geometric point of view.

grafico della funzione


for x\geq 0 the graph is that of the line y=x, while for  x < 0 it is the line y=-x. In x = 0, the graph has a corner point: it is not definire possible to define a tangent line to the graph at the origin.