Creating a function F(x) such that all outputs exist between -5 and 5

Take this sample graph illustration: As $X$ approaches negative infinity the output approaches $-5$

As $X$ approaches positive infinity the output approaches $5$

From what I recall this would be leveraging $\log, \ln$ or $e$ but I'm failing to remember the specific principles involved to come up with this function.

Other things that would be nice for this function is that it accelerates very quickly from the origin and tapers off which I tried to illustrate.

Bring this back to the real world and not just conceptual, realistic values of $X$ will primarily exist between $-10,10$ and much less frequently $-20,20$ and $-50,50$. My goal is to produce scoring algorithm with constrained limits on the output of the score.

The simpler the function, the better.

This function seems to be very close to what I'm looking for:

$5*\frac{x}{1+|x|}$

The graph it produces is: At $F(5)$ and $F(-5)$ the graph is approximately 4 and -4.

How can I stretch out this function that $F(10)$ and $F(-10)$ are roughly 4 and -4 instead?

Able to answer this question myself, replace $X$ with $0.5X$

• You guys really rock, it's going to be hard to pick an answer from all these great responses! – Chris Marisic May 5 '17 at 1:34

You have many alternatives. Have a look at this picture: You can choose any one of these functions and just multiply it by the max value you want to obtain (you wrote about $5$). If you replace $x$ with $kx$ you are able to tune how steep the curve is in the middle. You can find this functions and even a few other examples on Wikipedia's entry about sigmoid functions.

FOLLOW UP: you can tune the purple function to get what you need in two different ways: $y=5\frac{x/2}{1+|x/2|}$ and $y=5\frac{x}{5/2+|x|}$.

• Added a follow up question about your purple function – Chris Marisic May 5 '17 at 4:52
• And here you are! @Chris – lesath82 May 5 '17 at 6:14

It looks like you want a sigmoid function. $$y = 5\left(\frac{2}{1 + e^{-kx}} - 1\right)$$ Increasing k will give a faster change through the origin. This one will go between $-5$ and $5$, replace the $5$ out front for a different range.

The simplest is $$f(x)=\frac{10}{1+e^{-x}}-5$$

It is a simple logistic function subtracted by 0.5 multiplied by $10$.

• When is that ever negative? – Zain Patel May 4 '17 at 23:29
• @ZainPatel I fixed it, thanks for pointing it out. – KKZiomek May 4 '17 at 23:32
• I downvoted. It's still wrong. – Zain Patel May 4 '17 at 23:34
• Now it's correct, I had a brainfart. @ZainPatel – KKZiomek May 4 '17 at 23:35

What about this :$$f(x)=\frac{10}{\pi} \tan^{-1}x$$