Very basic formula question

53 Views Asked by At

I know that this site is usually used for complex math questions that I'll never understand, but I'm having a brain fart and whilst I am a programmer I certainly don't claim to be great at Math.

Two variables: x, s

If x > 0.1
s = 1

Else x <= 0.004
s = 0.1

How can I make the value s vary between 1 and 0.1 based on the value of x. For example, if x = 0.05, s needs to equal 0.5.

1

There are 1 best solutions below

0
On BEST ANSWER

If you want a linear relationship, you can scale the position arithmetically.

$x$ ranges from $0.004$ to $0.1$

$s$ ranges from $0.1$ to $1.0$

so if $x$ lies within that range,

$s = 0.1 + (1.0 - 0.1) * (x - 0.004) / (0.1 - 0.004)$

$s = 0.1 + 0.9 * 0.046 / 0.096$

$s = 0.53125$