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 trying to create a slider that lets the user pick a value as low as some given minimum, or as high as some given maximum. The slider must also, when positioned half way, have a value that is some given "mid point".

So I'm looking for an increasing function $f(x) : [0,1] \to \mathbb{R}$ such that




for any $k_{\mathrm{max}} ≥ k_{\mathrm{mid}} ≥ k_{\mathrm{min}}$.

What could I choose? My first thought was a quadratic, since I have three unknowns, but this was non-inreasing for some values.


share|cite|improve this question
I think a quadratic should work as long as the middle point is actually in between the min and the max... How did you get non-increasing functions? – Vhailor Aug 23 '11 at 15:53
Is piecewise linear too simple? – Hans Lundmark Aug 23 '11 at 16:12
@Vhailor: consider the function $f(x) = -(x-1)(x-3/4)+3/4$. $f(0) = 0$, $f(1) = 3/4$, $f(1/2) = 3/4 - 1/8$. $f$ attains a global maximum at $x = 7/8$. – Willie Wong Aug 23 '11 at 17:15
up vote 0 down vote accepted

There are many ways of fitting a function to your requirements. Here is one particular way, which assumes some sort of power law type distribution between the min and the max values.

We first define the case where the min is 0 and the max is 1. Then we can set

$$ f(x; k_{\mathrm{min}}, k_{\mathrm{max}}, k_{\mathrm{mid}}) = k_{\mathrm{min}} + (k_{\mathrm{max}} - k_{\mathrm{min}})\cdot f(x; 0,1, k) $$


$$ k = (k_{\mathrm{mid}} - k_{\mathrm{min}}) / (k_{\mathrm{max}} - k_{\mathrm{min}}) $$

Now we consider the function $g(x) = x^p$. This function satisfies $g(0) = 0$, $g(1) = 1$, and it is guaranteed to be increasing between 0 and 1. It suffices to find the $p$ such that $g(1/2) = k$. We solve:

$$ (1/2)^p = k \iff p = - \log_2 k $$

So in the end we can take the function

$$ f(x; k_{\mathrm{min}}, k_{\mathrm{max}}, k_{\mathrm{mid}}) = k_{\mathrm{min}} + (k_{\mathrm{max}} - k_{\mathrm{min}}) x^{\log_2 (k_{\mathrm{max}} - k_{\mathrm{min}}) - \log_2 (k_{\mathrm{mid}} - k_{\mathrm{min}})} $$

share|cite|improve this answer

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.