Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using R to plot some data and I'd like to transform a distance variable with $[0,\infty)$ to a transparency parameter that accepts inputs $[0,1$]. I'd like $0$ distance to map to $1$ and increasing distances to map to decreasing numbers asymptotically approaching $0$. It's been a while since I've taken any math so the function I want might be obvious, but can anyone help me out? Bonus if you explain how the function would be scaled to alter the rate that the range approaches $0$.


share|cite|improve this question
up vote 4 down vote accepted

$e^{-x}$ will do the trick. If it's any easier, the same is true for any base value greater than 1. So $2^{-x}$ also works. Higher values approach 0 more quickly with respect to $x$.

share|cite|improve this answer

Another possibility is hyperbolic decay, which is slower than exponential decay:

$$f_\alpha(x)=\frac{1}{\alpha x + 1} $$

Where $\alpha > 0$ is a scaling factor. The larger $\alpha$, the steeper the descent towards $0$.

Here's a plot to compare:

Plot of hyperbolic and vs. exponential decay

share|cite|improve this answer
This function also has the advantage of being substantially faster to compute than the exponential, for circumstances where that can matter. – Steven Stadnicki Jan 14 '13 at 1:20

This function maps (0,inf) to (0,1):

$$f(x)=1 - \frac{2\arctan(x)}{\pi}$$

You can replace x in the formula with a polynomial or any other function mapping (0, inf) to (0, inf) to alter the rate of change.

share|cite|improve this answer

$f(x)=e^{-x}$ have all the properties you want. If you are using a computer and programming, then you can approximate the function by $\sum_{k=0}^N \frac{(-x)^k}{k!}$.

If you use bigger numbers than $e \sim 2,7$ then the function approaches $0$ more quickly.

share|cite|improve this answer
It would be better to use a language's built-in exp function, if it has one (and most do), instead of coding in the Maclaurin series. – Reid Jan 14 '13 at 0:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.