I'm looking for the equation of a family of functions that roughly resembles the sketch below (with apologies for the crudeness of said sketch):
Properties I'm looking for:
- $\lim_{x\to-\infty}f(x)=y_1$ (i.e. approaches asymptote y=y1)
- $\lim_{x\to+\infty}f(x)=y_2$ (i.e. approaches asymptote y=y2)
- $|f'(x)|$ is at a maximum at x=0
I remember something involving ex/(??), but I can't remember exactly and can't seem to come up with the formula. I want to use it to weight tags in a tag cloud (i.e. the more recently a tag was used (smaller x), the more weight (larger y) the tag gets). The whole graph would be shifted up and to the right of what is shown in the sketch, but I know how to do that part once I have a formula.
$\endgroup$ 33 Answers
$\begingroup$I think what you're looking for is a form of logistic function, such as $$f(x)=\frac{2}{1+e^x}-1.$$
edit: For your specific criteria with $y_1$ and $y_2$: $$f(x)=\frac{y_1-y_2}{1+e^x}+y_2.$$
edit 2: For comparison of my answer to the other two answers:
dashed/black: $\frac{2}{1+e^x}-1$; blue: $-\frac{2}{\pi}\arctan x$; red: $-\frac{x}{\sqrt{x^2+1}}$
$\endgroup$ $\begingroup$Just take $- tan^{-1} x$. Vary it appropriately for additional constraints.
$\endgroup$ 1 $\begingroup$Another famous family of functions that behave as you describe is those of form $y=\dfrac{x}{\sqrt{x^2+1}}$. (This function is actually the sine of the arctan function George suggested)
Graph of $y=-\dfrac{x}{\sqrt{x^2+1}}$:
For a general y1 and y2, the formula would be $y=-\dfrac{y_1-y_2}{2}*\dfrac{x}{\sqrt{x^2+1}}+\dfrac{y_1+y_2}{2}$
$\endgroup$