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

I know that $$f(x)=x\cdot|x|$$ have no derivative at $$x=0$$ but how do I calculate it's derivative for the rest of the points? When I calculate for $$x>0$$ I get that $$f'(x) = 2x$$ but for $$x < 0$$ I can't seem to find a way to solve the limit. As this is homework please don't put the answer straight forward.

-
Hint: what is $|x|$ if $x<0$? –  Sigur Jan 7 '13 at 23:49
I know that it's -x but I still can't get further... I'm stuck with a big polynom –  Georgey Jan 7 '13 at 23:51
I believe you have a derivative at $x=0$. –  timur Jan 7 '13 at 23:51
Do you know the following characterization, which is the root of linear approximation: $f$ is differentiable at $0$ with derivative $f'(0)$ if and only if $f(x)=f(0)+xf'(0)+x\epsilon(x)$ with $\lim_{x\rightarrow 0}\epsilon (x)=0$? In your case, $\epsilon(x)=|x|$ and $f(0)=f'(0)=0$. Here is a reference: pirate.shu.edu/~wachsmut/ira/cont/proofs/diffaprx.html –  1015 Jan 8 '13 at 0:22

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

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.

-
I'm not supposed to draw the graph, just calculate the derivative. –  Georgey Jan 7 '13 at 23:52
Do the extra work. –  copper.hat Jan 7 '13 at 23:52
But how can I formally prove with tools I'm not allowed to use? –  Georgey Jan 7 '13 at 23:52
I think the idea is that the picture can help you figure out what answer you're supposed to get; it might not end up being the method you ultimately use in your written answer. –  Christopher A. Wong Jan 8 '13 at 0:03
You can turn it into a slightly more formal proof by observing that the definition of the derivative of a function at a point only depends on its values around that point. So if two functions agree near that point, they have the same derivative there. For example, since $f(x)=x^2$ for $x>0$, the derivative of $f$ and the derivative of $x\mapsto x^2$ are equal at any point $x$ with $x>0$. –  user108903 Jan 8 '13 at 0:04
• 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$.

-

Hint If $x\gt 0$ we are looking at $x^2$, easy. If $x\lt 0$, we are looking at $-x^2$, easy. For $x=0$, use the definition of the derivative.

So at $0$ we want $\displaystyle\lim_{h\to 0}\,\dots$,

-

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|) \, .$$

-

When $x<0$ replace $|x|$ by $-x$ (since that is what it is equal to) in the formula for the function and proceed.

Please note as well that the function $f(x)=x\cdot |x|$ does have a derivative at $0$.

-
so is $f(x)' = 2x$ for $x >= 0$ and $f(x)' = -2x$ for $x < 0$? –  Georgey Jan 7 '13 at 23:58
@Eran Strictly speaking, $f(x)$ is a number and so $f(x)' = 0$ for all $x$. It's better to write $f'(x)$, i.e. $f'$ evaluated at $x$. –  Fly by Night Jan 8 '13 at 0:10
@Fly by Night Even more strictly speaking, f(x) is a number and so it is not a function and thus can't be differentiated at all. –  Ittay Weiss Jan 8 '13 at 0:19
@IttayWeiss Of course it can. You can think of it as a constant function if you like. –  Fly by Night Jan 8 '13 at 0:28
Not if you are being strict about the notation. Otherwise, you can also think of f(x)' as the derivative of f at x. Either f(x)' has no meaning (if you want to be strict), or you assign to it some plausible meaning. There are at least two (inconsistent) ways to do the latter. –  Ittay Weiss Jan 8 '13 at 0:36

By definition, the derivative (if exists) of $f$ at $x_0$ is $$f'(x_0)=\lim_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0}.$$ When $x_0<0$, $f(x_0)=x_0(-x_0)=-x_0^2$. Now you have \begin{align} f'(x_0)&=\lim_{x\to x_0}\frac{x|x|+x_0^2}{x-x_0}\\ &=\lim_{x\to x_0;x\in(x_0-\epsilon,x_0+\epsilon)\setminus\{x_0\}}\frac{x|x|+x_0^2}{x-x_0}\\ &=\lim_{x\to x_0;x\in(x_0-\epsilon,x_0+\epsilon)\setminus\{x_0\}}\frac{-x^2+x_0^2}{x-x_0}\\ &=\lim_{x\to x_0;x\in(x_0-\epsilon,x_0+\epsilon)\setminus\{x_0\}}-(x+x_0)=-2x_0. \end{align} Here $\epsilon$ is such that $x_0+\epsilon<0$.

-


-