Example of a convex function which goes to $0$ at infinity and behaves like $-1/|x|$ in the origin I am trying to find an example of a real valued function $f\in C^1(\mathbb{R}\setminus \{0\})$ such that:

*

*in a neighborhood of the origin it behaves like
$$g(x) = -\frac{1}{|x|};$$


*$$\displaystyle\lim_{|x|\to\infty} f(x)=0;$$


*it is convex "as $|x|\to\infty$, i.e. it is convex at infinity.
I was thinking thinking to consider exactly $g(x) = -\frac{1}{|x|}$, but I realized that actually it is concave.
Could someone please show me an example of such a function?
Thank you in advance.
 A: Consider the function $f(x)=\frac{\ln(|x|)}{|x|}$.
Clearly $\lim_{x \to 0}f = -\infty$ so it behaves like $-\frac{1}{|x|}$ near $0$. Also, $$\frac{d^2}{dx^2} f = \frac{2 \ln \! \left({| x |}\right)-3}{{| x |}^{3}}>0 \implies x\in\left\{\left(-\infty , -{\mathrm e}^{\frac{3}{2}}\right), 
\left({\mathrm e}^{\frac{3}{2}}, \infty \right)\right\}$$
we also have:
$\frac{d}{dx}f = \frac{1-\ln \left({| x |}\right)}{{| x |} x}<0 \implies x\in\{\left(-{\mathrm e}, 0\right), \left({\mathrm e}, \infty \right)\}$. Therefore if $|x| > \mathrm e^{\frac{3}{2}}$, the function becomes convex. Finally, $\lim_{|x|\to\infty}f = 0$. Hope I didn't miss anything.
A: Consider the function
$$
  f(x) = -\frac{1}{|x|} + \frac{2}{1+|x|}.
$$
As $x\to 0$, the term $\frac{2}{1+|x|} \to 2$, so $f(x)$ behaves like $-\frac 1 {|x|}$ near $0$. Clearly as $f(x)\to 0$ $|x|\to \infty$. It remains to show that $f(x)$ is convex for $|x|$ large enough. Intuitively, the terms  $-\frac{1}{|x|}$ and $\frac{1}{1+|x|}$ approximately cancel each other as $|x|\to \infty$, but the later one, which is convex (on $(-\infty,0)$ and $(0,\infty)$) is multiplied by two, so it dominates the other one. For an exact proof, take derivate of $f(x)$ at $x>0$ (the convexity for $x\to-\infty$ follows the fact that the function is even):
$$
  f'(x) = \frac{1}{x^2} - \frac{2}{(1+x)^2},
$$
and
$$
  f''(x) = -\frac{2}{x^3} + \frac{4}{(1+x)^3},
$$
which is positive for $x$ large enough.
