TITLE: Finding the derivative of the given piecewise function
QUESTION [5 upvotes]: I'm given the following function
$$f(x)= \begin{cases} \left(x-a\right)^2\left(x-b\right)^2\;,\quad x \in[a;b]\\ 0\;,\qquad\qquad\qquad\;\; x \notin[a;b] \end{cases}$$
I tried finding the derivative by using the definition, but I couldn't. I am not very familiar with the idea of taking the derivative of a piecewise function, that's why I'm stuck and don't know what to do. I would be great help for me if you could show how to take the derivatives of this kinds of functions or give some hints. Thank you very much.

REPLY [2 votes]: If $x\in\left(a,b\right)$ then there exists a neighbourhood of $x$, namely a small enough $\delta$ such that $f\left(x\right)=\left(x-a\right)^{2}\left(x-b\right)^{2}$. You may derive it the standard way.
If $x>b$ or $x<a$, then using a similar argument as above, $f\left(x\right)=0$ which you can also derive the standard way.
Now you need to check for $x_{0}=a$ and $x_{0}=b$. we will use the definition for that. on the case $x_{0}=a$:
$$\lim_{x\to a}\frac{f\left(x\right)-f\left(a\right)}{x-a}=\lim_{x\to a}\frac{f\left(x\right)}{x-a}$$
Now we look at the one-sided limits:
$$\lim_{x\to a^{+}}\frac{f\left(x\right)}{x-a}=\lim_{x\to a^{+}}\frac{\left(x-a\right)^{2}\left(x-b\right)^{2}}{x-a}=\lim_{x\to a^{+}}\left(x-a\right)\left(x-b\right)^{2}=0$$
$$\lim_{x\to a^{-}}\frac{f\left(x\right)}{x-a}=\lim_{x\to a^{-}}\frac{0}{x-a}=\lim_{x\to a^{-}}0=0$$
Hence $f$ is differentiable at $x_{0}=a$ and $f'\left(a\right)=0$
You can take it from here on the case $x_{0}=b$.