# 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:

1. 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?

2. 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.

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.

• I see. Some further questions if I may: 1. $f'(a^+)$ just means the right derivative, right? 2. In other words, this question I am asking is what was not teach when we were in (arguably most) Calculus class? I mean in the sense that it is one of the few things where only the methods are taught, and probably not something that I missed in my class. Aug 30 '20 at 17:28
• You're right. This means the right derivative. Difficult to answer your second point as I don't know the content of the course you followed. Aug 30 '20 at 18:38

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.

• I see. Sorry, how do we obtain that the left-sided derivative is -1? The limit I believe involves $\frac{3-x-a-b}{x-1}$. How do we conclude from that? Aug 31 '20 at 7:14
• I can only deduce that if we want $\frac{3-x-a-b}{x-1}$ approaches something when $x$ goes to -1 from the left, the top part must go to zero, hence we obtain instead $a+b=2$. Hence, we obtain the two equations to obtain $a,b$, but then we do not need any usage of continuity here. Just using left and right derivative, we have what we want, although we do not have the derivative at 1 to be -1 at all. That is where I was confused at. Aug 31 '20 at 7:18
• I see. Isn't $f(1)=a+b$, since $f(1)\neq 3-1$? Yes, you are right that for $x<1$, we have $f(x)=3-x$, but if $x=1$, then we do not use $f(x)=3-x$ since this works only for $x<1$, not $x=1$. Aug 31 '20 at 8:29
• @10understanding Yes, but for $f(x)$ to be continuous, we must have $3-x=ax^2+bx$ at $x=1$. Since this must be the case, we can evaluate $f(1)=2$ using $3-x$ without needing to worry about $a$ or $b$ since both elements of the piecewise function should be equal for $x=1$. Aug 31 '20 at 9:05
• I see. Then we need that point to say $f(1)=2$. Thanks!!! Aug 31 '20 at 9:41