[Math] Exponential function to map from [0, 1] to arbitrary [min, max]

calculus

Maybe you can help out a programmer whose last math class was 20 years ago:

Given a base $b$, $y_{min}$ and $y_{max}$:

Define a function so that $f(0) = y_{min}$, $f(1) = y_{max}$ and f(x) is exponential in [0, 1] using the given base.
Define the inverse function.

Trivial example

$y_{min} = 1$, $y_{max} = 16$, $b = 2$

$$y = 2 ^ 4x$$

$$x = log_2(y) / 4$$

For positive values of $y_{min}$

I came up with the general form:

$$y = 2^{ x (log_b(y_{max}) – log_b(y_{min})) + log_b(y_{min}) }$$

$$x = \frac{log_b(y) – log_b(y_{min})}{(log_b(y_{max}) – log_b(y_{min})}$$

Arbitrary ranges?

How to make it work, with arbitrary values, for example $b = 10$, $y_{min} = -1.000$, $y_{max} = 10,000$.

I suspect the question is not even valid for this range, but for my requirement it looks sensible at first sight:

Have a slider (user interface component) whose

  • minimum value is -1,000
  • maximum value is 10,000
  • with equal-distances for -100, -10, 0, 10, 100, 1000
  • sensible values in between

slider component

It also looks simple when you define x = 0 for leftmost slider position, x = 1 for rightmost position and draw the graph with a (pseudo?) logarithmic scale on the y-axis:

graph

How to best handle that?
A problem, of course is that there is just no $x$ for which $b^x = 0$.

Maybe we need three separate functions: One for $y = [y_{min}, -eps]$, one for $y = [eps, y_{max}]$, and one for $y = ]-eps, eps[$ where we cheat and approximate?

Best Answer

In a truly logarithmic scale, where your $0$ is there would be $1$, where your $-10$ is there would be $0.1$, where your $-100$ is, there would be $0.01$, and where your $-1000$ is there would be $0.001$.

I guess you would be better served with a $(\sinh x)$-style solution, that is, the difference between two exponentials of opposite sign of the exponent. Close to $0$ that's linear, and then it goes into exponential quite fast. For example, consider $$f(x) = 10^x - 10^{-x}$$ Then you've got $f(0)=0$, $f(1)=9.9\approx 10$, $f(2)=99.99\approx 100$, $f(3)=999.999\approx 1000$, $f(4)=9999.9999\approx 10\,000$, and of course $f(-x)=-f(x)$.

So taking the function $7x-3$ which is $-3$ for $x=0$ and $4$ for $x=1$, the function $$f(x)=10^{7x-3} - 10^{-(7x-3)}$$ would range from $-999.999$ to $9999.9999$, which I guess is close enough to your desired range of $-1000$ to $10\,000$.

If you need exact values, you can use the reverse function to $f$, which is $$f^{-1}(y) = \log_{10}\frac{y+\sqrt{y^2+4}}{2}$$ and then use a standard linear scaling to map that to the range $[0,1]$.

Related Question