# How to get the formula for the derivative of the $y=x|x|$ function?

I have this exercise:

(a) Sketch the graph of the function $$f(x) = x|x|$$.

(b) For what values of $$x$$ is f differentiable?

(c) Find a formula for $$f'(x)$$.

The sketching part was easy, since this function is basically $$f(x)=x^2$$, except that the part of the plot on the interval $$(- \infty, 0)$$ is mirrored against the $$x$$ axis.

The $$b$$ part was easy too, since the function is differentiable for every $$x$$ in the Reals domain, which probably should be substantiated by a reference to the theorem, that "if functions $$f(x)$$ and $$g(x)$$ are defined at a, then the function $$fg$$ is also defined at $$a$$".

But I have no idea how can I solve the third part about the formula of the derivative. I understand, that the formula is $$f'(x) = 2|x|$$, but how can I derive it from the definition of the derivative, which is $$f'(a) = \lim_{x \to a}\frac{f(x) - f(a)}{x - a} => f'(x) = \lim_{x \to a}\frac{x|x| - a|a|}{x - a}$$?

I tried to use the $$a^2 - b^2 = (a - b)(a + b)$$ formula for the $$x|x| - a|a|$$ expression, but it didn't work, since $$x|x| - a|a| \neq (x - a)(x + a)$$, if the x and a have different signs.

I tried to split the problem into 4 cases and got the results in the right part:

• $$x > 0, a > 0 \implies f'(a) = 2a$$, in detail: $$\lim_{x \to a}\frac{x^2 - a^2}{x - a} = \frac{(x - a)(x + a)}{x - a} = 2a$$ and the formula would be $$f'(x) = 2x$$
• $$x > 0, a < 0 \implies f'(a) = a$$, in detail: $$\lim_{x \to a}\frac{x^2 - -a^2}{x - -a} = \frac{2a^2}{2a} = a$$ and the formula of the derivative here would be $$f'(x) = x$$
• $$x < 0, a > 0 \implies f'(a) = a$$
• $$x < 0, a < 0 \implies f'(a) = 2a$$

This is definitely incorrect.

So could anyone provide any help here, please?

• Hint $f(x)=\begin{cases}x^2 & \text{ if } x \geq 0\\ -x^2 & \text{ if } x < 0\end{cases}$. So $f'(x)=..$?? – Anurag A Dec 1 '17 at 7:41
• "if the x and a have different signs." That's not a problem, since you're assuming that $x$ is very close to $a$ when you take the limit, thus they have the same sign for any $x$ which is relevant. The only time you have to be careful with the sign of $x$ is when $a=0$. – Arthur Dec 1 '17 at 7:43
• @Arthur, I tried this too, to check cases where a and x > 0, a and x < 0, and a = 0, x > 0, a = 0, x < 0. And got the same result f(a) equals either 2a or a (in the cases where a = 0) – Dmitry Korolyov Dec 1 '17 at 7:46

If $a>0$, and $x$ gets very close to $a$, you only have to consider the case when $x>0$.

Similarly for $a<0$.

When $a=0$, $f(0)=0$.

$$\lim_{x \to 0} \frac{f(x)-f(0)}{x-0}=\lim_{x \to 0}\frac{f(x)}{x}=\lim_{x \to 0}|x|=0=2|0|$$

when $a<0$:

$$\lim_{x \to a}\frac{f(x)-f(a)}{x-a}=\lim_{x \to a}\frac{x(-x)-a(-a)}{x-a}=\lim_{x\to a}\frac{a^2-x^2}{x-a}=-2a$$

Remark:

Use Piyush's method for $a<0$, I am just helping you to find your mistake for getting $2a$.

Your reasoning for part $b$ is wrong. knowing $fg$ exists doens't imply $fg$ is differentiable. The working in $c$ justifies part $b$ actually that it is differentiable everywhere.

• thank you, my main error was that I changed the signs not only for |a| and |x| but for a and x too. – Dmitry Korolyov Dec 1 '17 at 8:03

Write it as following $$f(x) = x^2 \quad x\in[0,\infty) \\ f(x) = -x^2\quad x \in(-\infty,0)$$

It is differentiable everywhere. And the derivative is $$f'(x) = 2x \quad x\in[0,\infty) \\ f'(x) = -2x\quad x \in(-\infty,0)$$

Edit: Limit at $x = 0$ $$\lim_{h \rightarrow 0^-}\frac{f(0)-f(0-h)}{h}=\lim_{h \rightarrow 0^-}\frac{h^2}{h}=0=\text{LHD} \\ \lim_{x \rightarrow 0^+}\frac{f(0+h)-f(0)}{h}=\lim_{x \rightarrow 0^+}\frac{h^2}{h}=0=\text{RHD} \\ \text{LHD} =\text{RHD}$$

This implies it is differentiable at $0$

• Though you have the right final answer but at $x=0$ you need to show the existence of the limit by taking two cases. – Anurag A Dec 1 '17 at 7:48
• Yes that should be shown. – Sonal_sqrt Dec 1 '17 at 7:49