How to find for which real numbers $a$ and $b$, the following functions are differentiable at $0$? I need to find for which real numbers $a$ and $b$, the following functions are differentiable at $0$:
$$f(x)=\begin{cases}
ax+b & x < 0 \\
x−x^2 & x \geq 0
\end{cases}$$
$$f(x)=\begin{cases}
ax+b & x < 1 \\
x−x^2 & x \geq 1
\end{cases}$$
 A: Hint:
The piecewise functions and the derivatives of those functions have to agree at the "splitting point".
In the first case, for example, we have:
$$a(0)+b=0-0^2,$$
from which it is apparent that $b=0$. Next, taking derivatives, we have
$$a=1-2(0),$$
from which we conclude that $a=1$.
A: (This is in response to @Always learning's later request for more detail.)
Looking at
$$f(x)=\begin{cases} ax+b & x < 0 \\ x−x^2 & x \geq 0, \end{cases}$$
I see that on the left side the graph is part of a line and on the right side the graph is part of a parabola. It will help to sketch what these look like. I don't know how to get nice graphs into an answer like some people are able to do, so I'll have to talk my way through it.
Let's start with the parabola first, since there are no unknown constants in it. For the purposes of this problem, it is enough make a rough sketch, and fortunately that is easy to do. I know the graph of $y = x - x^2$ is the graph of a parabola because it's the graph of a second degree polynomial, and I know roughly what parabolas look like. For this parabola, since $x - x^2 = x(1 - x),$ I immediately know that the $x$-intercepts (points where the $y$-coordinate equals $0)$ are $x=0$ and $x=1.$ So mark these two points on the $x$-axis. I also know that this parabola opens downward, because the coefficient of $x^2$ is negative. This is enough to make a rough sketch. Draw a downward opening parabola that passes through the two points $(0,0)$ and $(1,0).$ You don't need to worry about how high the parabola gets between the points $x=0$ and $x=1,$ but if you did want to know how high it gets, then plug $x = \frac{1}{2}$ (the midpoint of the two $x$-intercepts) into $x - x^{2}.$ (The turning point of a parabola occurs on its axis of symmetry, and this always lies midway between the two intercepts of the parabola with any horizontal line. Or just set the derivative equal to zero . . .) Here is what it looks like if you need more visual clues.
Now erase the part of the parabola that corresponds to $x < 0,$ since it is only the part of the parabola to the right of the $y$-axis that goes into making up the graph of your function.
Now for the $ax + b$ part of your function. This is a linear polynomial, so its graph is a line, and lines are easy to draw -- you only need to locate two points on the line and then draw the line containing these two points. However, things are a bit more complicated because we don't know what $a$ and $b$ are. However, these constants do correspond to certain aspects of the line, so let's start there. The constant $b$ is the $y$-intercept, so the line crosses the $y$-axis at the point $(0,b).$ For the time being, we don't know what $b$ is, so the line could cross the $y$-axis at any location on the $y$-axis (at least now, before solving the problem), but it will help to pick several points along the $y$-axis and imagine various lines going through these points. Notice that even if we knew what the value of $b$ was, there would still be infinitely many possible lines, since there are infinitely many directions a line can have and still cross the $y$-axis at $(0,b).$ That's where the value of $a$ comes in. The constant $a$ is the slope of the line, so $a$ tells you what direction the line has.
Since your function is not an entire line, but instead it consists only of those points on a line such that $x < 0,$ what the $ax + b$ part of your function does is give you the part of a line to the left of the $y$-axis, which is a ray.
Note that the endpoint of the parabola part were looking at earlier, the point $(0,0),$ is included. On the other hand, the endpoint of the ray, namely the point $(0,b),$ is NOT included, at least not unless $b=0,$ which would then put the ray's endpoint directly on the parabola's endpoint. And, in fact, this is something we want to happen. (If you're wondering what happens when a non-endpoint lies on top of an endpoint like this, go back and ask yourself what you get if you plug $x=0$ into $f(x)$ when $b=0.)$
Now let's consider the derivative of your function. At any point where $x>0,$ you'll be nicely tucked within the parabola part of the graph and the derivative will exist and be equal to $1 - 2x$ there. (Pretend you're an ameba crawling along the parabola part somewhere where $x>0.$ You'd be so small that you probably couldn't even see the "ray part" of the graph, and as far as you could tell, you are on a bendy parabola that has no corners or other nasties that would prevent a derivative at your location from existing.) In a similar manner, at any point where $x<0,$ you'll be nicely tucked within the line part of the graph and the derivative will exist and be equal to $a$ (whatever its value might wind up being).
The only problematic location is at $x=0,$ where you change over from being on a line to being on a parabola. So let's examine what's going on at $x=0.$
First of all, to even have a chance of the derivative at $x=0$ to exist, we need for the two halves of the graph (the half-line part and the half-parabola part) to join up at the same point (i.e. the graph doesn't break apart at $x=0),$ which in more technical language is that your function is continuous at $x=0.$
Now if you have a clear idea of what the graph looks like from what went on earlier, it should be obvious that we need to have $b=0$ in order to get the two halves of the graph to join up at $x=0.$ This takes care of one of the constants we were trying to find the value of. (For worryworts, who are wondering what we would do if we didn't know what the graphs looked like, we simply go back to the definition of continuity. We need the limit to exist at the point, so you must ensure that the left and right limits at the point are equal, and we need the limit to equal the value at the point. For piecewise functions, where the pieces are "nice", you just have to plug in the $x$-coordinate of the point into each of the formula pieces to get the left and right limits, and the value at the point is ... well, you should know how to do that.)
By using $b=0,$ what we now have is a parabola part to the right of the $y$-axis, a line part to the left of the $y$-axis, and the two ends join together at the point $(0,0).$ However, there might not be a derivative at $x=0,$ because the parabola end might be "pointing in a different direction" than the line end is pointing. If you look at the graph, you'll see that the parabola part is crossing the $x$-axis with some positive slope at $x=0.$ In fact, since the derivative of $x - x^2$ is $1 - 2x,$ which equals $1$ when $x=0,$ the parabola part is "diving into" the point $(0,0)$ with a slope of $1.$ What about to the left of the $y$-axis, where the line part of the graph is? Well, the line could be rising from (or falling from) the point $(0,0)$ in any direction, namely the direction that corresponds to slope equal to $a.$
In order for the derivative to exist at $x=0,$ we need for these directions to match up. So we want $a=1.$ And there you have it, we need $a=1$ and $b=0.$
Since I pretty much used up all the time I had available, I'll stop here and leave the second one for you to work through. It is very similar to the one I did.
A: Hint: if the functions are to be differentiable, they must also be continuous at the point. Use this information for an extra expression involving $a$ and $b$, in both cases. Then you can solve a $2 \times 2$ system for $a$ and $b$.
A: The geometrical motivation behind the derivative $f^\prime(x)$ of a real valued function $f(x)$ at a point $x_0$ is to be understood as the slope of the graph of $f$ at this point. If the function consists of two parts as in 
\begin{align*}
  f(x)=
  \begin{cases}
    ax+b & x < 0 \\
    x-x^2 & x \geq 0
  \end{cases}\tag{1}
  \end{align*}
and we are asked for the derivative of $f$ at $x=0$, we have to analyse under which conditions the slope of the first part $ax+b$ and the slope of $x-x^2$ coincide at $x=0$ provided they exist (i.e. are finite).

In a somewhat more rigid mathematical context we define the derivative $f^{\prime}(x)$ at $x=0$ as the limit
\begin{align*}
  f^{\prime}(x)=\lim_{x\rightarrow 0}\frac{f(x)-f(0)}{x-0}\tag{2}
  \end{align*}
Crucial for our analysis is the characterization of a limit by its right and left-hand limit.
The derivative $f^\prime(x)$ exists at $x=0$ if and only if the right and left-hand limit
  \begin{align*}
\lim_{x\rightarrow 0^-}\frac{f(x)-f(0)}{x-0}=L \quad \text{ and } \quad \lim_{x\rightarrow 0^+}\frac{f(x)-f(0)}{x-0}=R
\end{align*}
  exist and they are equal. These limits are then called right and left-hand derivative of $f(x)$ at $x=0$ provided they exist.

Now we have everything to properly analyse the function $f$ in (1). We start with the easy one

Value of $f(x)$ at $x=0$:
The definition (2) of the derivative explicitely uses the value $f(0)$. So, we have to assure that $f$ is well-defined at $x=0$ which means, that both parts of $f$ have to coincide at that point.
\begin{align*}
  a\cdot0+b=0-0^2
  \end{align*}
  which implies that
  \begin{align*}
  b=0
  \end{align*}

The next part is to analyse the left and right-hand derivative of $f$ at $x=0$

Left-hand derivative of $f(x)$:
\begin{align*}
  \lim_{x\rightarrow 0^-}\frac{f(x)-f(0)}{x-0}&=\lim_{x\rightarrow 0^-}\frac{(ax+b)-(0x+b)}{x-0}=\lim_{x\rightarrow 0^-}a=a
  \end{align*}
and finally the 
Right-hand derivative of $f(x)$:
\begin{align*}
  \lim_{x\rightarrow 0^+}\frac{f(x)-f(0)}{x-0}&=\lim_{x\rightarrow 0^+}\frac{(x-x^2)-(0-0^2)}{x-0}=\lim_{x\rightarrow 0^+}(1-x)=1
  \end{align*}
We see the left-hand derivative and the right-hand derivative coincide if and only if $$a=1$$

Btw it's plausible, that we could find only one value for the slope, since the part $f(x)=x-x^2$ for $x\geq 0$ of the function uniquely determines a slope. So, we could only hope to find a value with this specific slope at the other part.

The short way:
We could also simply write the derivative of both parts of the function $f(x)$ to obtain a function $g(x)$ with
\begin{align*}
  g(x)=
  \begin{cases}
    a & x < 0 \\
    1-2x & x \geq 0,
  \end{cases}\tag{2}
  \end{align*}
We observe this function $g(x)$ represents the derivative of $f(x)$ in (1) for general $a,b\in \mathbb{R}$ for all $x\neq 0$. 
If we analyse the situation for $x=0$ we consider the part
  \begin{align*}
  g(x)=a\qquad\qquad x<0
  \end{align*}
  and take it as the left-hand derivative of the function $f(x)$. Next we consider the part
  \begin{align*}
  g(x)=1-2x\qquad\qquad x\geq 0
  \end{align*}
  as the right-hand derivative and see immediately that $a=1$ in case $x=0$.

Note, that the second part of OPs question refers to a function
\begin{align*}
  h(x)=
  \begin{cases}
    ax+b & x < 1 \\
    x-x^2 & x \geq 1,
  \end{cases}
  \end{align*}
and differentiability at $x=0$ reduces to the analysis of the function
$$y=ax+b$$
at $x=0$, which is easily seen to be differentiable for all values of $a,b\in \mathbb{R}$.
A: in case first 
\begin{equation}
\lim_{x\to 0^{-}} ax +b=b\\
\lim _{x\to 0^{+}} x-x^2=0
\end{equation}
of equation be have up that b=0, for differntiable have 
\begin{equation}
\lim_{x\to 0^{-}} a\\
\lim {x\to 0^{+}} 1-2x=1\\
\end{equation}
of the equation have up a=1 then in equation first a=1 and b=0 
in second array have
\begin{equation} 
\lim_{x\to 1^{-}} ax+b= a+b\\
\lim_{x\to 1^{+}} x-x^2=0\\
\end{equation}
then \begin{equation*}
a+b=0
\end{equation*}
then be have for differentiable
\begin{equation}
\lim_{x\to 1{-}} a=a\\
\lim_{x\to 1{+}} 1-2x=-1\\
\end{equation}
of the equation up be have $a=-1$
then $a+b=0$ therefore $-1+b=0\Longrightarrow b=1$
