TITLE: A smooth function instead of a piecewise function
QUESTION [5 upvotes]: I want to find a smooth function approximating f(x) as best as possible:
\begin{equation*}
f(x) =
\begin{cases}
x & \text{if } x \le a,\\
a & \text{if } x > a.
\end{cases}
\end{equation*}
as a  smooth function ($a$ is a positive constants and x is a positive real number). $f(x)=\sqrt[n]{x}$ has a similar trend, but not good enough. What is best alternative function for the piecewise one.

REPLY [7 votes]: As I said in one of my comments you can modify $f(x)$ in a neighbourhood of $x=a$, say $(a-\varepsilon,a+\varepsilon)$, for $\varepsilon>0$ as small as you wish. In that small interval you want to change your function by some other smooth function $g(x)$ satisfying the following conditions: $g(a-\varepsilon)=a-\varepsilon$, $g(a+\varepsilon)=a$, $g'(a-\varepsilon)=1$, $g'(a+\varepsilon)=0$. These conditions ensure that $g$ glues well (smoothly) with $f$.
If my computations are not wrong a function satisfying the conditions above is $$g(x)=-\frac{1}{4\varepsilon}\left(x^2-2(a+\varepsilon)x+(a-\varepsilon)^2\right).$$
Then a smooth function approximating $f$ would be
$$
f_{\varepsilon}(x)=\left\{
\begin{array}{ccl}
x &\mbox{if}& x\leq a-\varepsilon\\-\frac{1}{4\varepsilon}\left(x^2-2(a+\varepsilon)x+(a-\varepsilon)^2\right)&\mbox{if}&  a-\varepsilon\leq x\leq a+\varepsilon\\
a&\mbox{if} & x\geq a+\varepsilon
\end{array}
\right.
$$
Notice the subscript $f_\varepsilon$ indicating the dependence on the parameter $\varepsilon$. The smaller you take the parameter, the better the approximation (since you're modifying $f$ in a smaller interval).