After some trial-and-error I've got this:

$$f(x;a,b)=\textrm{arctanh}\left( 2\frac{x-a}{b-a}-1 \right)$$

Illustrated here on WolframAlpha: arctanh((2*((x-a)/(b-a))-1)) where a=2 and b=12

arctanh((2*((x-a)/(b-a))-1)) where a=2 and b=12

It kind of does what I wanted, but I wonder if there are any functions like this that doesn't use trigonometric functions. Maybe something like an inverse general sigmoid function. I haven't been able to come up with anything like that.

  • 5
    $\begingroup$ $\operatorname{artanh} x = \frac12\log_e\frac{1+x}{1-x}$ is a logarithmic function rather than a trigonometric function. Using $\operatorname{arctan}$ instead would be trigonometric $\endgroup$
    – Henry
    Aug 8, 2023 at 10:22
  • $\begingroup$ @Henry Thanks. Yes, it seems I was confused. I generally use sigmoid functions (0 to 1) as activation functions when I manually play around with neural networks, and just always assumed the cousin tanh (-1 to 1) was the trigonometric tan function. TIL. $\endgroup$ Aug 9, 2023 at 20:39
  • $\begingroup$ Of course the actual tangent function can do that too: $\textrm{tan}(\pi\frac{x-a}{b-a}-\frac{\pi}{2})$ - this is what you didn't want. $\endgroup$
    – tevemadar
    Sep 12, 2023 at 17:11

3 Answers 3


$\frac1 {a-x}+\frac 1 {b-x}$ is continuous and increasing on $(a,b)$ and its range is $(-\infty, \infty)$.

The derivative is $\frac 1 {(a-x)^{2}}+\frac 1 {(b-x)^{2}} >0$.

  • 1
    $\begingroup$ @AndréChristofferAndersen the function geetha290km proposed, has $a-x$ in the first denominatior. Check this out: wolframalpha.com/… $\endgroup$ Aug 7, 2023 at 7:51
  • 1
    $\begingroup$ @VeselinDimov Yes. Thanks. I noticed, and I tried to delete my comment in time, but you were too fast. I had a typo when I tested it out. This is a beautifully simple solution. $\endgroup$ Aug 7, 2023 at 7:54

Here's another one $$\ln \left( \left| \frac{x-a}{b-x} \right| \right)$$


Let us follow your suggestion of finding something like an inverse general sigmoid function.

Start with the sigmoid expression $\frac{1}{1+e^{-y}}$.

We can scale the expression by $b-a$, and add $a$ to get an expression whose values lie in $(a,b)$. Then we can solve the equation

$x = a+\frac{b-a}{1+e^{-y}}$

for $y$ to find an expression for the inverse function. This gives us the expression

$y = -\ln(\frac{b-a}{x-a}-1) = \ln(\frac{x-a}{b-x})$,

which is the same answer as Tony Mathew gave.

  • 2
    $\begingroup$ Interesting, you don't actually need to take the absolute. What I like about it, is that I am very familiar with manipulating sigmoid functions. I played around with doing what you did with the full generalized logistic function on Wikipedia and got this: wolframalpha.com/… $\endgroup$ Aug 7, 2023 at 18:36
  • 1
    $\begingroup$ The reason you don't need to take the absolute is because $b - x > 0$ and $x - a > 0$ implicitly since our domain is $(a,b)$. $\endgroup$ Aug 7, 2023 at 18:42
  • 1
    $\begingroup$ @AndréChristofferAndersen This is btw also essentially the same function as you came up with. Just scale your function by $1/2$. I think you might be confusing the inverse trigonometric function arctan with the inverse hyperbolic function arctanh (or artanh), as arctanh(x) is just $\frac{1}{2}\ln(\frac{1+x}{1-x})$. $\endgroup$ Aug 7, 2023 at 18:45
  • 1
    $\begingroup$ That is so illuminating! Why didn't I bother to check? Here is my a=2 and b=12 example with the scaling you said. Fits like a glove: wolframalpha.com/… $\endgroup$ Aug 7, 2023 at 18:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .