44

I was just wondering what the derivative of $f(x) = \max(0,1-x)^{2}$ would be. What technique do you use to determine this derivative?

A.M.
  • 3,944
phil12
  • 1,547

4 Answers4

60

It might be of help to sketch the function or write it without the $\max$. We get $$f(x) = \begin{cases} (1-x)^2 & \text{if } x \leq 1\\ 0 & \text{if }x \geq 1\end{cases}$$ It is easy to work out the derivative everywhere except at $x=1$. At $x=1$, work out explicitly from definition. $$\lim_{h \to 0^+} \dfrac{f(1+h) - f(1)}{h} = 0$$ $$\lim_{h \to 0^-} \dfrac{f(1+h) - f(1)}{h} = \lim_{h\to 0^-} \dfrac{h^2}{h} = 0$$ Hence, we have $$f'(x) = \begin{cases} 2(x-1) & \text{if } x \leq 1\\ 0 & \text{if }x \geq 1\end{cases}$$

  • 2
    in your function definition for all x >= 1, you are returning 0. But let's take x = 2, then (1 - 2) ^ 2 will be (-1) ^2 which is nothing but 1 and according to op's max function, 1 should be returned. But since you gave the condition of x >= 1, we always return 0 even when x is something like 2. I think in comments what Andre Holzner said is correct. since (1−x)2≥0 (for x a real number), max(0,(1−x)2) is equal to (1−x)2 – theprogrammer May 29 '21 at 00:21
10

HINT : Analyze this function on different intervals.

Kalissar
  • 283
5

I would generalize this as follows:

Let

f(x) = max(0, g(x))^2

Then

f'(x) = [2*g(x)*g'(x)] if g(x) is > 0 else [0]

Does it make sense?

khan
  • 213
1

I know that this is an old question but here an other way that can help.

It may be easier to apply the basic properties of derivatives on your problem knowing the following result $max\left \{ a;b \right \}=\frac{a+b+|a-b|}{2}$ and that $\frac{\partial |x|}{\partial x}=\frac{x}{|x|}=sign(x)$.

After all you need to do is to derivate: $(\frac{1-x+|1-x|}{2})^2$.
$\frac{\partial }{\partial x}(\frac{1-x+|1-x|}{2})^2=\frac{1}{4}2(1-x+|1-x|)\frac{\partial }{\partial x}(1-x+|1-x|)=\frac{1}{2}(1-x+|1-x|)(-1+\frac{\partial }{\partial x}(|1-x|))=\frac{1}{2}(1-x+|1-x|)(-1-sign(1-x))=...=(x-1)-|1-x|$ (different expression of the same function given above).

After you need to carefully check what happen at $x=1$ as allready explained above.