[Math] Can piecewise defined functions always be differentiated piece by piece

derivativesfunctions

Guess you have a function $f(x) : \mathbb{R} \rightarrow \mathbb{R}$ (or a subset of $\mathbb{R}$) with
$f (x) := \begin{cases}
x^3 & \text{if } x \geq 0 \\
x^2 & \text{otherwise}
\end{cases} $.

The derivative $f': \mathbb{R} \rightarrow \mathbb{R}$ of $f(x)$ is $f' (x) := \begin{cases}
3 \cdot x^2 & \text{if } x \geq 0 \\
2 \cdot x & \text{otherwise}
\end{cases}$.

To get this derivative I could simply differentiate the first part and the second part.

Can you calculate the derivative of every piecewise defined function this way?

I recently saw Thomae's function:

$f(x)=\begin{cases}
\frac{1}{q} &\text{ if } x=\frac{p}{q}\mbox{ is a rational number}\\
0 &\text{ if } x \mbox{ is irrational}.
\end{cases}$

I thought there might be a differentiable function which is defined like that and which can't be derived simply by deriving it piece by piece.

Best Answer

The derivative of your $f(x)$ is automatically $3x^2$ only for $x>0$. It happens to have derivative $0$ at $x=0$, but that's "because" the derivative of $x^2$ happens to be $0$ at $x=0$. If we replace $x^2$ by $x$, then the derivative will not exist at $x=0$.

The Thomae function is not ordinarily considered to be piecewise defined.

Related Question