Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What simple math function f(x) has these properties?

Tags:

function

math

I have a little math problem. I would like to have a function with these properties:

  1. for x much bigger than 0: lim f(x) = x
  2. for x much smaller than 0: lim f(x) = 0
  3. and f(0) = 1 (sorry, I had here f(1)=1 which was wrong!)
  4. f(x) should be monotonically increasing

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.

like image 844
martinus Avatar asked Mar 04 '09 17:03

martinus


1 Answers

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.

like image 157
Adam Rosenfield Avatar answered Sep 19 '22 20:09

Adam Rosenfield