How to find the derivative of a piecewise function?

388 Views Asked by At

How to find the derivative of $\sqrt{x^{2}+4+3(x+\operatorname{sgn}(x))}$. That is find $\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{x^{2}+4+3(x+\operatorname{sgn}(x))})$. Now we clearly know that $\operatorname{sgn}(x)$ is a piecewise function. We know that $\operatorname{sgn}(x)=\frac{|x|}{x}$ when $x\neq0$ and $0$ when $x=0$. Therefore when $x>0$ then the value of $\frac{|x|}{x}$ is $1$. When $x<0$ then the value of $\frac{|x|}{x}$ is $-1$. Now let's take cases.

Case-1): When $\operatorname{sgn}(x)=1$, then $\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{x^{2}+4+3x+3\operatorname{sgn}(x)})=\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{x^{2}+7+3x})=\frac{1}{2\sqrt{x^{2}+3x+7}}(2x+3)$.

Case-2): When $\operatorname{sgn}(x)=0$, then $\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{x^{2}+4+3x+3\operatorname{sgn}(x)})=\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{4})=0$.

Case-3): When $\operatorname{sgn}(x)=-1$, then $\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{x^{2}+4+3x+3\operatorname{sgn}(x)})=\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{x^{2}+3x+1})=\frac{1}{2\sqrt{x^{2}+3x+1}}(2x+3)$.

So, we can clearly see that $3$ different results are occuring for $\frac{\mathrm{d}}{\mathrm{d}x}(\sqrt{x^{2}+4+3(x+\operatorname{sgn}(x))}$. But I want to know that is my process correct? Are $3$ different results possible? Please do let me know.

2

There are 2 best solutions below

0
On

I would always be wary about taking the derivative at a single point, unless you know for sure the function is differentiable with continuous derivative ($\mathcal{C}^1$) around that point. Otherwise, issues might arise. Consider the contrived case of $$ f(x) = \begin{cases} 1, & x = 0 \\ 0, & x \ne 0 \end{cases} $$ where the derivative wouldn't even exist at $x=0$, but if you take the derivative of each "piece" of the function you would just naively conclude $f' \equiv 0$ everywhere. But you can see the issues arise via a number of techniques, including the limit definition of the derivative: $$ f'(\xi) := \lim_{x \to \xi} \frac{f(x) - f(\xi)}{x-\xi} \equiv \lim_{h\to 0} \frac{f(\xi+h) - f(\xi)}{h} $$ Some enlightening examples are here.


Thanks to the definition of $\newcommand{\sign}{\operatorname{sign}} \sign(x)$, then, your function - let's call it $f$ - technically has three pieces to be concerned with: $$ f(x) := \begin{cases} \sqrt{x^{2}+3x+7}, & \sign(x) =1 \text{; i.e., } x > 0 \\ \sqrt{x^{2}+3x+4}, & \sign(x) =0 \text{; i.e., } x = 0 \\ \sqrt{x^{2}+3x+1}, & \sign(x) =-1 \text{; i.e., } x < 0 \end{cases}$$

Graphically, $f$ has graph looking like this, each color representing one "case" above:

enter image description here

Notice how $f$ isn't even defined when $x^2+3x+1<0$, i.e. when $$ x \in \left( \frac{-3 - \sqrt 5}{2} , \frac{-3 + \sqrt 5}{2} \right) $$ so another concern of problems of this type to be wary of is when your derivative is defined for functions not even in the domain of $f$. I remember getting tripped on a problem of this type once, where we sought $f'$ for $f(x) := \ln(\ln(\sin(x)))$, the issue being $f$ isn't defined for any real number.

This isn't an issue for your problem, since your answer implicitly incorporates that, but I figured it worth noting in the general case.

Anyhow, the graph makes it clear that $f'$ doesn't exist at $x=0$: it isn't even continuous there. This can be seen from the limit definition, if you please. Essentially, you have

  • $\sqrt{x^2+3x+1} \xrightarrow{x \to 0^-} 1$ on the left branch
  • $\sqrt{x^2+3x+7} \xrightarrow{x \to 0^+} \sqrt 7$ on the right branch
  • $f(0)=2$

so the limit doesn't exist, you do not have continuity, and hence do not have differentiability.


In principle, can a piecewise-defined function have a (nontrivial) piecewise-defined derivative, though? Sure, that's not an issue by any means, and sometimes is even an important thing to have (such as in the implementation of splines). A very simple example is $$ f(x) := \begin{cases} x^2, & x \ge 0 \\ 0, & x < 0 \end{cases} $$ Clearly, $f'$ is $2x$ for $x > 0$ and $0$ for $x<0$, and it is not hard to see from the limit definition that $f'(0) = 0$, ensuring that $f$ is differentiable despite being piecewise.

0
On

First of all, if a function (defined in a neighborhood of $a$) is differentiable at $a$, then it is continuous at $a$. Thus, if you have a noncontinuous function at $a$, trying to compute the derivative is moot.

Now, if the function is continuous at $a$ and differentiable in a neighborhood of $a$ except, possibly at $a$, two cases are possible:

  1. the limit of $f'$ for $x\to a$ exists finite;
  2. the limit of $f'$ for $x\to a$ doesn't exist or is infinite.

In the first case, l'Hôpital's theorem allows you to say that $$ f'(a)=\lim_{x\to a}f'(x) $$ In the second case the derivative at $a$ may still exist. For instance $$ f(x)=\begin{cases} x^2\sin(1/x) & x\ne0 \\[6px] 0 & x=0 \end{cases} $$ where the limit of the derivative for $x\to0$ doesn't exist, but the function is differentiable at $x$.

You see that continuity at $a$ is the main aspect to check. In your case, the fact that $\operatorname{sgn}$ isn't continuous at $0$ shows that we need to check continuity of $f$. Since we have $$ f(x)=\begin{cases} \sqrt{x^{2}+4+3(x+1)} & x>0 \\[6px] 2 & x=0 \\[6px] \sqrt{x^{2}+4+3(x-1)} & x>0 \end{cases} $$ we clearly see that $f$ isn't continuous at $0$, so we're done: the derivative cannot exist.


A different example where one can compute the derivative at a point as a limit. Consider $$ f(x)=\begin{cases} \dfrac{e^x-1}{x} & x\ne0 \\[6px] 1 & x=0 \end{cases} $$ For $x\ne0$ we clearly have $$ f'(x)=\frac{xe^x-e^x+1}{x^2} $$ and we see that, using l'Hôpital, $$ \lim_{x\to0}f'(x)=\lim_{x\to0}\frac{xe^x}{2x}=\frac{1}{2} $$ so we can state that $f'(0)=1/2$.

Related Questions in DERIVATIVES-OF-PIECEWISE-FUNCTIONS