Friday 8 March 2013

Getting 0 To ∞ On A Linear Slider

Problem

I use Mathematica for all my attempts at developing mathematical models for all kinds of problems. The beautiful thing about Mathematica is its ability to provide custom user interface boxes that allow fiddling around with the parameters in those models.


This shows a generated user interface with a slider for changing the value of "m", which is the slope in the depicted function. But the slider has a maximal value (100 in this case) and therefore you could never conveniently explore the whole range of values for "m". Every concrete value for "m", no matter how high, would always be just at the beginning of the slider.

Solution

What I needed was a function that would map the interval 0 to ∞ on a linear scale. The actual linear scale doesn't matter but the most versatile one is, of course, a normalized scale from 0 to 1. One function that does this is:
f(x) = x / (1 - x)
and it looks like this.
 The function has these properties:
  1. at x = 0, it returns 0
  2. at x = 0.5, it returns 1
  3. for x approaching 1 it approaches infinity
  4. at x = 1 it is undefined

Mathematica

In Mathematica I use the following definition, which makes it easier to use in the context of parameter boxes as mentioned above.
This avoids the error with an undefined result at x = 1 and, in this context, is the correct interpretation of the undefined value.

No comments:

Post a Comment