How do I calculate the derivative of $x|x|$?

  • For $x \ge 0$ you have $f(x)=x \times |x| = x \times x = x^2$

  • For $x \le 0$ you have $f(x)=x \times |x| = x \times (-x) = -x^2$

so you can calculate the derivative when $x \gt 0$ and the derivative when $x \lt 0$ in the usual way.

You are wrong when you say there is no derivative when $x=0$.


First, draw a picture. Second, make a guess. Third, confirm your guess.

enter image description here

Hmm, looks like $x \mapsto x^2$ for $x \geq 0$ and $x \mapsto -x^2$ for $x \leq 0$. Indeed $f(x) = x^2$ for $x >0 $, so $f'(x) = 2 x$ when $x > 0$. Similarly, $f(x) = -x^2$ when $x <0$, so $f'(x) = -2x$ for $x <0$.

The only issue is $x=0$. Looking at the picture, and indeed, looking at the limiting value for $x \downarrow 0$ and $x \uparrow 0$ suggests that if $f$ is differentiable at $x=0$, then $f'(0) = 0$.

So, working with this guess, we try $$|f(x)-f(0) - 0.x| = |(x|x|)-0 -0.x| = |x|^2$$ If $x\neq 0$, we have $\frac{|f(x)-f(0) - 0.x|}{|x|} = |x|$, from which it follows that $f'(0) = 0$. Formally.

To wrap up, notice that $f'(x) = 2|x|$.

Working without the intuition is difficult. For me, drawing a rough picture provides much of the intuition. If the intuition is sound, then it is often straightforward to formalize the result.


There's a great trick that you can use. Notice that for all real $x \neq 0$ you have $|x| \equiv \sqrt{x^2}$.

If you want to know the derivative of $x|x|$ away from $x=0$ then consider $x\sqrt{x^2}$. Using the chain rule and the product rule we can show that, assuming $x \neq 0$,

$$\frac{d}{dx}x|x| \equiv \frac{d}{dx} x\sqrt{x^2} = \sqrt{x^2} + \frac{x^2}{\sqrt{x^2}} \equiv |x| + \frac{x^2}{|x|} \, . $$

Moreover, this little trick works in many more situations. For example, consider $f(|x|)$. Provided we stay away from $x = 0$, $g(|x|) \equiv g(\sqrt{x^2})$ and so:

$$\frac{d}{dx} g(|x|) = \frac{x}{|x|}\frac{d}{dx}g(|x|) \, . $$