Formula for limiting a variable X between -Y and +Y on a logarithmic(?) to linear scale.

21 Views Asked by At

I am probably way overthinking this. And the main issue is that i have no technical words to google this with.

I have a variable X, which can be anything. I need to create a formula which scales this variable to be within -Y and +Y. But not lineary, but with a curve. The closer it gets to Y (either - or +) the slower it goes towards it (sort of logarithmic?) It actually would never really get there, it would just infinitely inch closer.

The steapness of this curve should be configurable with Z. So that i have control over how linear > logarithmic the behaviour is.

To me this would be bloody magic, but i have the impression that it can be done, and it isn't even that hard. Please educate me on how who this is/isn't possible and/or how to achieve this.

1

There are 1 best solutions below

1
On BEST ANSWER

Consider the arctangent function.

Arctangent function

It has horizontal asymptotes $y = \pi/2$, $y = -\pi/2$. As $x$ gets larger (or smaller), $\arctan(x)$ gets closer to $\pi/2$ (or $-\pi/2$), without ever reaching it. So $$ \frac{Y}{\pi/2} \arctan( k x) $$ will give results in $(-Y,Y)$. If you make $k > 1$, $kx$ is farther from zero, so the output will be closer to $\pm Y$. If you make $k < 1$, $kx$ is closer to zero, so the output will farther from $\pm Y$.

The arctangent is not the only function that is sigmoidal like this. The logistic function is another.