Im looking for a function that's continuous everywhere and whose second derivative is continuous everywhere with the following properties:

  1. Near the origin, the function is approximately constant: $$f\approx c$$ with $c \in \mathbb{R}$
  2. Far from the origin (outside some scale), the function is approximately linear: $$f(x) \approx m*x+b$$ with $m \neq 0$

So the function would look like


I just defined this function piecewise in mathematica as an example, but the second derivative is not continuous, because the curvy bits are quadratic and the flat bits are linear, so the second derivative is a series of steps.

I will eventually define a vector field from this scalar field which describes a flow in a flat manifold. Moreover, there is an energy functional that is defined in terms of the second derivatives of this scalar field, hence the reason for continuity.

I tried using bump functions and integrating backwards to get the scalar field I want, but the integrals became messy quite fast, as you might expect. Similarly, I tried using hyperbolic tangents, but I wasn't able to smoothly attach the pieces together.

I am also trying to minimize the magnitude of the second derivative (because it relates to the energy functional). So I am hoping to find a function that approaches the origin in a linear way, then curves in such a way that the second derivative has constant sign, then approaches zero again, then has constant opposite sign. Here is an example of such a second derivative using bump functions.


I tried integrating this and using the integration constants to satisfy my required properties, but the integrals are quite messy!

I appreciate any help!

  • $\begingroup$ $f\equiv 0$ is constant near the origin and linear far from the origin. $\endgroup$ Nov 20, 2020 at 12:40
  • 2
    $\begingroup$ haha, I guess I should be more specific! $\endgroup$
    – shanedrum
    Nov 20, 2020 at 12:57
  • $\begingroup$ Yes, that was the point of my comment ;) $\endgroup$ Nov 20, 2020 at 12:59

2 Answers 2


I actually found a descent enough function. I started with the conditions on the second derivative I wanted to satisfy. So I construct the following function, which is just the sum of two gaussians, such that the entire function is odd about the origin $$ \alpha(x) = - e^{-\frac{(x+a)^2}{\sigma}} + e^{-\frac{(x-a)^2}{\sigma}}$$ with $a,\sigma \in \mathbb{R}$. Now, this function is what I want the second derivative to look like. To get the original function, I integrated this function twice to get

$$ \phi(x) = \frac{1}{2}\Bigg( e^{-\frac{(x-a)^2}{\sigma}} - e^{-\frac{(x+a)^2}{\sigma}}\Bigg)\sigma + C_1 + C_2 x + \frac{\sqrt{\pi \sigma}}{2}\Bigg( (a-x)ERF\bigg(\frac{a-x}{\sqrt{\sigma}}\bigg) - (a+x)ERF\bigg(\frac{a+x}{\sqrt{\sigma}}\bigg)\Bigg)$$

where $C_1, C_2$ are integration constants and $ERF$ is the error function from integrating a gaussian. Now, to have a linear function at large values of x and a flat function near the origin, we just massage the parameters until the function has vanishing derivative at the origin (flat) and constant non-zero at large x (linear). For example, I find $C_1=0$, $C_2 = 1.5$, and $a \approx 1.0087$ gives me:

enter image description here

Now, differentiating this twice yields the original function:

enter image description here

Hope this helps someone else in the future if you ever look for a function like this!


Is approximation of standard $f(x) = x \cdot (1 - e^{-x^2})$ good enough?

function plot

If not - then probably $x \cdot (1 - w(x)) + w(x)$ where $w(x)$ is bump function is the best we can get.

  • $\begingroup$ Thank you for your response! While this does in fact satisfy what my original question asks for, I am actually also trying to minimize the magnitude of the second derivative. The second derivative of this function peaks near the x values of -1.7 (1.7), since the function curves up (down) briefly. I tried adding a gaussian weight and modulating it to rid the brief upturns, but to no avail. $\endgroup$
    – shanedrum
    Nov 21, 2020 at 12:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .