Differentiable approximation of the absolute value function [duplicate]

Are there any good approximations of the absolute value function which are $C^2$ or at least $C^1$? I've thought about working with exponentials and then adding in more terms to keep the function from growing too fast away from zero, but I was hoping to find something a bit neater.

• Welcome to MSE! "Good" often resides in the eye of the beholder. (For example, there are obvious real-analytic uniform approximations.) Do you have some specific purpose in mind, and if so, could you please add it to your question? Commented Mar 2, 2015 at 21:09
• Thanks, I actually ended up finding the answer I wanted here, math.stackexchange.com/questions/172439/… . Oddly, I only found it using Google instead of the internal search function. Commented Mar 2, 2015 at 21:17
• Does this answer your question? Approximate $|x|$ with a smooth function Commented Mar 25, 2021 at 10:08

A "natural" approximation of $x \mapsto |x|$ is given by the hyperbola $$x \mapsto \sqrt{x^2+c}$$ for some $c > 0$.

• In the same vein, but with asymptotically better convergence, one can use $\log(e^{2 x}+1)-x$. The "faster" the inner function grows, the better the convergence. Commented Mar 2, 2015 at 21:21

How about $$\newcommand{\abs}[1]{\left\lvert#1\right\rvert} f_\epsilon(x) = \begin{cases} \abs{x} & (\abs{x} \geqslant \epsilon) \\ \abs{x}\left(1 - e^{\textstyle\frac{x^2}{x^2 - \epsilon^2}}\right) & (\abs{x} < \epsilon) \end{cases}$$ [I'm reminded of Littlewoood's anecdote, "$\ldots$ where $\epsilon$ is very small"! Can one fix this in MathJax?]

If my magnifying glass can be relied upon, the exponent in that expression is: $$\frac{x^2}{x^2 - \epsilon^2}.$$

If I'm not mistaken, $f_\epsilon$ is $C^\infty$ on $\mathbb{R} \setminus\{0\}$, and $C^1$ at $0$; $f_\epsilon''(0) = 0$; and $0 \leqslant f_\epsilon(x) \leqslant \epsilon$ if $\abs{x} \leqslant \epsilon$.

• You could use $e^{\textstyle \frac{x^2}{x^2 - \epsilon^2}}$ or even $e^{\displaystyle \frac{x^2}{x^2 - \epsilon^2}}$; but I suspect the cleanest notation is simply $\exp\left(\frac{x^2}{x^2 - \epsilon^2}\right)$. Commented Mar 2, 2015 at 22:38
• The Littlewood typesetting anecdote actually concerned a minuscule $\sigma$ rather than a minuscule $\epsilon$ (a mistake others on the Net have also made, so it could too easily go uncorrected): see e.g. here, or here. Commented Mar 2, 2015 at 22:45

Just simply $$x. \tanh(\alpha x)$$ Example plot