0
$\begingroup$

Given two values, I'm trying to come up with a formula that will return 50% if both values are equal, 25% if the first value is half the second, 75% if the second is half the first. In other words:

given (a=3,b=12) returns .125

given (a=3,b=6) returns .25

given (a=3,b=3) returns .5

given (a=6,b=3) returns .75

given (a=12,b=3) returns .875

(a and b will always be positive)

... the idea being that if a is half of b, it's 25%, if it's half of half, it's 12.5% or half of 25%, if it's half of half of half, etc - the numbers go down if a is greater, but up in the same way if b is greater.

I'd love to know what that equation would look like - I don't really know enough about how this stuff fits together to do much more than fiddle with it on my own. (not even sure what tags to apply to this)

  • 0
    .125 is half of .25, which is half of .5 - in the other direction, .75 is .5 plus half of .5, and .875 is .75 plus half of half of .52011-10-19

1 Answers 1

1

This function will reproduce your numbers (at least if $a$ and $b$ are positive):

$f(a,b)= \frac{a}{2b} \text{ when } a \le b$ $f(a,b)= 1- f(b,a) \text{ when } a \gt b$

You can write the latter case as $f(a,b)= \dfrac{2a-b}{2a}$ when $a \ge b$.

You can write both as $\dfrac{1}{2}+\dfrac{(a-b)\times \min(a,b)}{2ab}$.

  • 0
    ...and you're right, this does exactly what I want.2011-10-19