35
$\begingroup$

I am looking for a function f(x) with a value range of [0,1].

f(x) should increase from 0 to 1 while its parameter x increases from 0 to +infinity.

f(x) increases very fast when x is small, and then very slow and eventually approach 1 when x is infinity.

Here is a figure. The green curve is what I am looking for:

enter image description here

Thanks.

It would be great if I can adjust the slope of the increase. Although this is not a compulsory requirement.

$\endgroup$
7
  • 3
    $\begingroup$ Do you want it to actually take on the values 0 and 1? $\endgroup$
    – user98602
    Commented Jul 16, 2014 at 17:20
  • $\begingroup$ @MikeMiller value 0 yes. value 1 no. f(x)=0 when x=0, =1 when x=infinity, and = a value between 0 and 1 otherwise. $\endgroup$ Commented Jul 16, 2014 at 17:22
  • 8
    $\begingroup$ Consider $f(x)=1-\frac1{x+1}$ $\endgroup$
    – abiessu
    Commented Jul 16, 2014 at 17:22
  • $\begingroup$ @Leo do you want this $f$ to be $\mathcal{C}^0$? or something more strict perhaps? $\endgroup$
    – DanZimm
    Commented Jul 16, 2014 at 19:20
  • 1
    $\begingroup$ It is always going to be relative fast when $x$ is small, a simple consequence of the fact that you require it to be bounded and monotone. $\endgroup$
    – Gina
    Commented Jul 16, 2014 at 19:21

8 Answers 8

68
$\begingroup$

I think this should work well for your purposes: $$ f(x) = \frac{x}{x + a} $$ Where $a$ can be any number bigger than $0$. The smaller $a$ is, the sharper the increase will be.

ADDENDUM: if you want to extend this to an odd (and continuously differentiable) function, simply take $$ f(x) = \frac{x}{|x| + a} $$

$\endgroup$
7
  • 2
    $\begingroup$ I love this function so much. So simple, elegant, and nice.... $\endgroup$ Commented Jul 16, 2014 at 17:30
  • 3
    $\begingroup$ And in particular, the slope at $x=0$ is $\dfrac{1}{a}$. $\endgroup$
    – Théophile
    Commented Jul 16, 2014 at 17:35
  • $\begingroup$ I like this, but it would be great to be able to parameterise the rate of convergence to the asymptote as well as the slope at the origin. $\endgroup$
    – Keith
    Commented Jul 17, 2014 at 3:15
  • $\begingroup$ @Keith in what sense do you mean? Would something like $f(x) = \frac{x^n}{x^n + a}$ be sufficient for those purposes? $\endgroup$ Commented Jul 17, 2014 at 10:56
  • $\begingroup$ @Omnomnomnom That $f(x)$ does not have the right gradient at $x=0$. $$g(x) = f(x)^{1+bf(x)}$$ would do, but seems a bit ugly. $\endgroup$
    – Keith
    Commented Jul 17, 2014 at 23:31
21
$\begingroup$

Here are two simple functions with slope $k$ at $x=0$, for some $k>0$:

$$f(x) = 1-e^{-kx}$$

and

$$g(x) = \frac{2}{\pi}\arctan\left(\frac{\pi}{2}kx\right)$$

The first of these approaches $1$ more quickly than the second.

$\endgroup$
1
  • 2
    $\begingroup$ One nice thing about the arctan version: it also approaches -1 as x approaches -infinity. $\endgroup$
    – Brilliand
    Commented Jul 16, 2014 at 21:00
20
$\begingroup$

One I use very often is : $$ \tanh x = \frac{\sinh x}{\cosh x} = \frac {e^x - e^{-x}} {e^x + e^{-x}} = \frac{e^{2x} - 1} {e^{2x} + 1} = \frac{1 - e^{-2x}} {1 + e^{-2x}}$$

The increase at the begining around 0 is "only" linear but can do the work. and you can choose the slope at $x \mapsto 0$ Hyperbolic tangent

$\endgroup$
1
  • 1
    $\begingroup$ Use $f(x) = \tanh mx$ if you want slope $m$ at $x = 0$. $\endgroup$
    – David K
    Commented Jul 17, 2014 at 20:18
16
$\begingroup$

I'm surprised no one has mentioned erf(x) aka the "Error Function", defined roughly as the normalized area under the bell curve as a function of the upper limit of integration. For x > 1, it satisfies your requirement and also has a slope that is easily controlled (and made arbitrarily large at 0) by the width of your Gaussian.

$\endgroup$
1
  • 1
    $\begingroup$ Why is this answer downvoted so much? The error function is in fact a sigmoid curve with limit $1$ as $x\to\infty$ and is different from the other suggestions. Perhaps the fact that it isn't an elementary function makes it less appealing, but it certainly meets the criteria in the OP. $\endgroup$ Commented Jul 17, 2014 at 3:27
8
$\begingroup$

$f(x) = 1 - \exp(-x/\epsilon)$ for $\epsilon > 0$ small will do.

$\endgroup$
6
$\begingroup$

Some time ago I had an interest in such a function, but with the added requirement that it should map negative values of $x$ onto the range $(-1,0)$, asymptotically approaching $-1$ as $x$ goes to $-\infty$. In fact, I wanted $f(-x) = -f(x)$.

I came up with something like this:

$$ f(x) = \frac{x}{\sqrt{a^2 + x^2}} .$$

This has slope $\frac{1}{|a|\,}$ at $x = 0$.

$\endgroup$
6
$\begingroup$

Simple version: $$f(x)=1-\mathrm e^{-a\sqrt{x}}\qquad (a\gt0)$$

Slightly more elaborate version:$$f(x)=1-\mathrm e^{-a\sqrt{x}-bx}\qquad (a\gt0,\ b\geqslant0)$$ Every such function fits every requisite in the question, including the infinite slope at $0$. The parameter $a$ can help to tune the increase near $0$. The parameter $b$ can help to tune the increase near $+\infty$. To get even quicker convergence to $1$ when $x\to+\infty$, one can replace $-bx$ in the exponent by $-bx^n$ for some $b\gt0$ and $n\gt1$.

Once one understands the principle, a host of other solutions springs to mind.

$\endgroup$
3
$\begingroup$

Try $f(x) = 1-e^{-x^2}$ , which will be 0 for x = 0 and approach 1 rapidly for big x.

$\endgroup$
3
  • 1
    $\begingroup$ But doesn't increase very fast when $x$ is small. $\endgroup$ Commented Jul 16, 2014 at 17:27
  • $\begingroup$ Judging from the scale of his sketch, i thought it would be very sufficiently fast. $\endgroup$ Commented Jul 16, 2014 at 17:28
  • 2
    $\begingroup$ Look at the derivative of the function at $x = 0$. It seems the OP wants something with initially a large positive slope that gradually flattens out, not a slope that starts flat, increases, then decreases. $\endgroup$
    – David K
    Commented Jul 16, 2014 at 17:35

You must log in to answer this question.

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