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 programming a game and am looking to create a non-linear relationship between input and output, such that as the input increases, the output increases, but the higher the input value, the corresponding output increment is less and less.

I've looked at logarithms, and that seems to be the effect I'm looking at.

o = log(i), where o is the output value and i is the input value.

But this is too extreme - the curve is too steep. If I try to modify this with

o = log(i)k, where k is some constant multiplier, creates too steep of a curve in the lower end.

I'd like to find a way to make the falloff more gradual. Unfortunately, I can't seem to find any other functions in my programming language (ActionScript 3) that will do the trick.

Where should I be looking? Are there any functions I should be trying to replicate?

Thanks in advance - I realize this is a pure maths forum, but it seemed like the best place to ask.

share|cite|improve this question
What's the domain for your inputs, and what do you want the curve to look like at the lower end? It seems like you could simply move the logarithm to the left appropriately and that would resolve your problems... – anon Aug 4 '11 at 3:18
the inputs would be positive real numbers. The curve should be fairly linear in the lower end. I'd like to then be able to "play" with the factor to tweak the slope of the curve. How do you "move the logarithm to the left?" log(i-n)? – Tom Auger Aug 4 '11 at 3:32
You're close: $\log(\mathrm{input}+x)$, for some translation distance $x$. Try it out for yourself. (Have you heard of Wolfram|Alpha yet?) – anon Aug 4 '11 at 3:34
If $\log i$ ultimately grows too slowly for you, you can try $i^k$ for some $k$ between $0$ and $1$, like $k=1/2$, or $1/3$. There is still the steepness problem, which can be fixed for example with $(1+i)^{1/3}-1$, which is in the spirit of what @anon suggested. You will need to fool around, tweak parameters until things look good. – André Nicolas Aug 4 '11 at 3:54
@anon, wow Wolfram|Alpha is pretty sweet. So this formula gets me reasonable close: (log(n+30)-log(30))70 with the problem that the slope doesn't fall off to 0 at the outer end. That would be ideal. Note that I found that when you add to n, you have to subtract the log of that same amount in order to keep the line above 0 – Tom Auger Aug 4 '11 at 4:20

I would suggest trying a function of the form f(X)=A*(1-exp(-B*x))+C.

This functional form gives you pretty good control over the appearance of the curve since it starts with f(0)=C and converges to f(inf)=A with the rate of convergence given by B.

share|cite|improve this answer
Thanks, this looks promising, though I can only make it work reliably for B = .01 – Tom Auger Aug 4 '11 at 4:28
(ran out of edit time!) I'm having trouble figuring out how A and B relate, if I'm looking to "cap" the slope to 0 at X=n. For example, say I'm plotting this from 0 to 400 and want to see the slope at 0 when X=400. Is there some logic to A and B that I can apply? In my tests, for example, 400(1-exp(-.005*x)) flattens out around x = 1000. What if I wanted it to flatten out at 400 - am I just playing around with A and B until my plot empirically seems to achieve that? – Tom Auger Aug 4 '11 at 4:36
@Tom Augur: If you want to cap the slope at X=n, just do if X>n: X=n. Then apply your function to X. – Ross Millikan Aug 4 '11 at 4:45
@Ross Millikan, unfortunately that would then truncate the curve - making a "hard stop" rather than a smooth decay. – Tom Auger Aug 4 '11 at 5:00
@Tom Auger, Basically you have to just play with parameters until it fits what you want it to do. If you can't get it to work then you have to increase the complexity of the function. This function had a slope that is given by f'(x)=ABexp(-Bx), this means it goes to zero as Bx gets large, this means for smaller B the function will converge slower. – NGaffney Aug 5 '11 at 3:25

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.