Values such that piecewise function is differentiable everywhere A small discussion on calculus. I have a function
$$f(x)=\begin{cases}3-x, & \text{$x<1$}\\ ax^2 +bx, &\text{$x\geq1$}\end{cases}$$
I need to find $a,b$ such that this function is differentiable everywhere.
Usually we proceed like this (correct me if I am wrong): We must have continuity, so that $2=a+b$. We also must have equal left and right derivative at 1, so by calculating each one-sided derivative at 1, we have $-1=2a+b$. Solving the system, we get $a,b$.
By the way, I am not studying this as new student in Calculus. This is just something that bothers me even though I have passed Calculus class. My two questions here are:

*

*What is the theory behind equating both one-sided derivatives here? Are we arguing this way: at any $x<1$, the derivative is $-1$, and at any $x>1$, the derivative is $2ax + b$. Limiting to $1$, they have to be equal, hence $-1=2a+b$. However, aren't we limiting $f'(x)$ (for $x\neq 1$) here? Is one-sided limit of $f'(x)$ the definition of one-sided derivative?


*Still related, I thought one-sided derivative comes from the definition $\frac{f(x)-f(1)}{x-1}\rightarrow \text{(some number)}$ as $x\rightarrow 1^-$ (for left side, and similarly for right side) instead? If it is the case, then I tried to calculate by definition and wanted to equate the result, but it does not look easy at all, and I could not obtain $-1=2a+b$.
Thanks a lot for clearing my misunderstanding.
 A: Let's have a look at right side derivative (look at left side would be similar).
You're right that the definition of the right derivative at $a$ is
$$f^\prime(a^+)=\lim\limits_{h \to 0^+} \frac{f(a+h)-f(a)}{x-a}.$$
The trick is that when $f^\prime$ is right continuous at $a$, then you have $\lim\limits_{x \to a^+} f^\prime(x) = f^\prime(a^+)$. This can be proven using the Mean Value Theorem.
This is the result that you're using behind the scene: you compute the derivative that is indeed right continuous and write that the right limit of the derivative at $1^+$ is equal to the left limit of the derivative at the same point.
A: You are correct about the one-sided derivative. The right-sided derivative of the piecewise function at $x=1$ is
$$\lim_{x \to 1^+} \frac{f(x)-f(1)}{x-1}$$
Since when taking this from the right side, the only part of the function being used is that represented by $f(x)=ax^2+bx$, we can substitute it in:
$$\lim_{x \to 1^+} \frac{ax^2+bx-a-b}{x-1}$$
$$=\lim_{x \to 1^+} a\frac{x^2-1}{x-1}+b\frac{x-1}{x-1}=\lim_{x \to 1^+} a\frac{(x-1)(x+1)}{x-1}+b=\lim_{x \to 1^+} a(x+1)+b=2a+b$$
The left-sided derivative at $x=1$ is
$$\lim_{x \to 1^-} \frac{f(x)-f(1)}{x-1}$$
Since coming from the left, $f(x)=3-x$ we have the fact that the left-sided derivative is
$$\lim_{x \to 1^-} \frac{3-x-(3-1)}{x-1}=\lim_{x \to 1^-} \frac{1-x}{x-1}=\lim_{x \to 1^-} -\frac{x-1}{x-1}=\lim_{x \to 1^-} -1=-1$$
Since we now know the left-sided derivative is equal to $-1$, and the right-sided derivative must have the same value, we have the equality, $2a+b=-1$. After this, solving a system of equations to find the values of $a$ and $b$  is simple.
