TITLE: Making a piecewise function continuous and differentiable at point
QUESTION [5 upvotes]: Problem:
Let $f(x) = \left\{
  \begin{array}{lr}
    \frac{\arctan(x)}{(1+x)^2} & : x \geq 0\\
    Ae^x + B & : x < 0
  \end{array}
\right.
$
Find $A$ and $B$ such that the function is continuous and differentiable at $x=0$.
My attempt:
To ensure continuity at $x = 0$ I figured $A = B = 0$ would be the only option. But this, of course, seems very wrong, and in any case, it wouldn't cause differentiability at $x=0$.
As far as I could tell, the derivative of $\frac{\arctan(x)}{(1+x)^2}$ at $x=0$ would be $1$. While the second piece's derivative evaluates trivially to $0$.

REPLY [2 votes]: $f$ is continuous at $0$ means that
\begin{align*}
\lim_{x\to0^+}f(x)&=\lim_{x\to0^-}f(x)
\\\iff0&=A+B.
\end{align*}
Also, $f$ is differentiable at $0$ means that
\begin{align*}
\lim_{x\to0^+}f'(x)&=\lim_{x\to0^-}f'(x)
\\\iff1&=A.
\end{align*}
(actually, this is valid since each piecewise defined part is smooth in its given domain.)
Thus we have $A=1,B=-1$.