- #1
martix
- 169
- 5
- TL;DR Summary
- How to inverse f(x) = (x*e^(x-1))^(x/(x+1))
Preface: I have not done serious math in years. Today I tried to do something fancy for a game mechanic I'm designing.
I've got an item with a variable power level. It uses x amount of ammo to produce f(x) amount of kaboom. Initially it was linear, e.g. fL(x) = x, but I didn't like the scaling. So I figure I'd make it scale exponentially.
Something like fe(x) = ex-1.
That way it's still 1 at x=1. The low-end values look weird though. Like x=0 is not 0.
So I figure multiply both: fL*fe
f2 is now 0 at x=0 and 1 at x=1
But I am multiplying to very similar values, so a square root seemed in order: f2 = √fL*fe
It's higher than the linear function below 1, but that's fine for now. Above 1, with the square root it's not quite exponential, but it's close enough and certainly above linear.
And normally that would have been the end of the story. But then I started tinkering with the function. At this point I'm just in it for the math and (re)learning things long forgotten.
Interesting things happen when you mess with the power. f2 = (fL*fe)p, p>0.5
This makes it go above exponential growth for a while, and then dip below, depending on how close p is to 1.
The item has a max power level, it can't go to infinity. So I started thinking, can I somehow align this max level with the inflection point of f2?
I made a new function, to look at how and when this happens: fratio = f2/fe, which has a very interesting shape and properties. More specifically, it's global minimum is the point where f2 goes from above exponential, to below. Which immediately got me thinking calculus and derivatives.
An hour or two of struggle with WolframAlpha later, I arrive at the following function of power as a function of ammo: f(x) = (x*ex-1)x/(x+1)
But I don't know how to find the inverse. Or to be more explicit I want an f(y) = x function. I tried some algebra, but that got me nowhere. It seems to me the inverse function should exist, but I'm stumped at this point.(Step-by-step in the spoiler below, should anyone feel the need to double-check my work. I plopped everything in an excel sheet to verify my results, so I'm reasonably certain it's correct, even if I don't know why. Explanations appreciated tho.)
1. We're looking for the minima of fratio, so derivatives ahoy! With WolframAlpha as a substitute for my non-existent calculus skills.
2. Our function has 2 variables x (ammo) and p (exponent). I mess around with both partial derivatives, looking for anything useful to fall out. Turns out ∂fr/∂x = e^(p (-x) + p + x - 1) x^(-p - 1) (x - p (x + 1)) is the one I need (I have no idea why); We have 3 multiplicands here, so for the derivative to be 0, either one should be 0. Not the e^ part and x^ is only 0 when x=0, which is not what we're looking for. So the only working part left is (x - p (x + 1)) = 0 which gives us a relation between x and p: p = x / (x+1)
3. Substitute: f2 = (fL*fe)p => f2 = (x*ex-1)x/(x+1)
I've got an item with a variable power level. It uses x amount of ammo to produce f(x) amount of kaboom. Initially it was linear, e.g. fL(x) = x, but I didn't like the scaling. So I figure I'd make it scale exponentially.
Something like fe(x) = ex-1.
That way it's still 1 at x=1. The low-end values look weird though. Like x=0 is not 0.
So I figure multiply both: fL*fe
f2 is now 0 at x=0 and 1 at x=1
But I am multiplying to very similar values, so a square root seemed in order: f2 = √fL*fe
It's higher than the linear function below 1, but that's fine for now. Above 1, with the square root it's not quite exponential, but it's close enough and certainly above linear.
And normally that would have been the end of the story. But then I started tinkering with the function. At this point I'm just in it for the math and (re)learning things long forgotten.
Interesting things happen when you mess with the power. f2 = (fL*fe)p, p>0.5
This makes it go above exponential growth for a while, and then dip below, depending on how close p is to 1.
The item has a max power level, it can't go to infinity. So I started thinking, can I somehow align this max level with the inflection point of f2?
I made a new function, to look at how and when this happens: fratio = f2/fe, which has a very interesting shape and properties. More specifically, it's global minimum is the point where f2 goes from above exponential, to below. Which immediately got me thinking calculus and derivatives.
An hour or two of struggle with WolframAlpha later, I arrive at the following function of power as a function of ammo: f(x) = (x*ex-1)x/(x+1)
But I don't know how to find the inverse. Or to be more explicit I want an f(y) = x function. I tried some algebra, but that got me nowhere. It seems to me the inverse function should exist, but I'm stumped at this point.(Step-by-step in the spoiler below, should anyone feel the need to double-check my work. I plopped everything in an excel sheet to verify my results, so I'm reasonably certain it's correct, even if I don't know why. Explanations appreciated tho.)
1. We're looking for the minima of fratio, so derivatives ahoy! With WolframAlpha as a substitute for my non-existent calculus skills.
2. Our function has 2 variables x (ammo) and p (exponent). I mess around with both partial derivatives, looking for anything useful to fall out. Turns out ∂fr/∂x = e^(p (-x) + p + x - 1) x^(-p - 1) (x - p (x + 1)) is the one I need (I have no idea why); We have 3 multiplicands here, so for the derivative to be 0, either one should be 0. Not the e^ part and x^ is only 0 when x=0, which is not what we're looking for. So the only working part left is (x - p (x + 1)) = 0 which gives us a relation between x and p: p = x / (x+1)
3. Substitute: f2 = (fL*fe)p => f2 = (x*ex-1)x/(x+1)