I have a little math problem. I would like to have a function with these properties:
So the function should look somewhat like this:
^
| /
| /
| /
___.-+´
--´-----+------>
|
The best I got so far is x/(1 + e^(-x))
but then I recognized that it drops below 0 and is not monotonically increasing.
A great help for playing around with these function is GraphFunc Online.
Also, it would be helpful if the function is fast to calculate as I need to execute it very often.
EDIT: I am using this in a program to limit values. I have an optimization algorithm, that uses curve fitting with a Levenberg-Marquardt algorithm. But this algorithm does not allow constraints, and optimizes over the full range of real values. So I need a function like this so that I can add an artificial constraint so that the function is bigger than 0. A simple approach would be to use f(x) = x²
but then the function is not monotonically increasing and it has two minimas.
The Levenberg-Marquardt approximates derivatives, so I think it would be best when the function is smooth too. But I am not sure if this is absolutely necessary.
Here's a smooth function that satisfies your requirements:
f(x) = (x + sqrt(x^2 + 4)) / 2
For x = 0, you can see that f(x) = 1. For very large positive x, sqrt(x^2 + 4)
is approximately x, so f(x) ≈ x. For very large negative x, sqrt(x^2 + 4)
is approximately -x, so f(x) ≈ 0.
The first derivative is
f'(x) = 1/2 + 1/2*x/sqrt(x^2 + 4)
For x > 0, x/sqrt(x^2 + 4) > 0
, so f'(x) > 0. For x < 0,
0 < x^2/(x^2 + 4) < 1
0 < |x|/sqrt(x^2 + 4) < 1
-1 < x/sqrt(x^2 + 4) < 0
-1/2 < 1/2*x/sqrt(x^2 + 4) < 0
1/2 + 1/2*x/sqrt(x^2 + 4) > 0
Hence, f'(x) > 0 for all x, so f(x) is monotonically increasing as desired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With