# A simple function equation

I come from a programming background and I can’t find a simple math function. The request might seem strange, but I needed it a graphical context to alter some points locations:

I need a function $f(x) = y$ defined for $x \ge 0$ such that:

• $f(x) \in [0, x)$
• $f(0) = 0$
• $f(x) \approx x$ as $x\to \infty$.
• It has to slowly grow at first — sort of like $x^2$ — and then get closer and closer to x.

The simplest equation form that satisfies this restrictions will do.

I tried to plot this so that I can make myself better understood:

http://www.wolframalpha.com/share/clip?f=d41d8cd98f00b204e9800998ecf8427eo8stqhpe1s

Actual values don’t matter, just the shape of the plot.

None of the basic functions (and combinations of them) that I tried were doing this (e.g. $x^2, \log x, \sqrt x, 1/x$).

-
Thank you and sorry if the question is in any way inappropriate for this site (I use mostly Stack Overflow). Please let me know if I can edit this question to make it more adequate for this site. – bolov Jun 28 '14 at 15:51
Am I right in saying that you want $y = x$ to be an asymptote? Or is it just that you want the slope of the curve to approach $45^\circ$ (so $y = x - c$ is an asymptote for some suitable constant $c$)? – M. Vinay Jun 28 '14 at 15:57
@M.Vinay either will do, I will have to test them in my program to see the final results. I think that $y=x$ an asymptote would be better. – bolov Jun 28 '14 at 16:03
If $y = x$ is an asymptote, then the curve will initially lie below the asymptote and approach it from the right. If $y = x - c$ is an asymptote for an appropriate $c$, then the curve will always be to the left of the asymptote and approach it from the left. – M. Vinay Jun 28 '14 at 16:05
@M.Vinay yes, I understand. I still need to see the visual result, but I think if y=x an asimptote is better for me. – bolov Jun 28 '14 at 16:08

This one fulfills your requirements: $$f(x)=\frac{x^2+x^3}{1+x+x^2}.$$ We have: $$\forall x>0,\ 0<f(x)<x$$ $$f(0)=0,$$ $$f(x)-x^2=-\frac{x^4}{1+x+x^2}$$ so that $f(x)$ and $x^2$ are very close for small values of $x$, and $$f(x)-x=-\frac{x}{1+x+x^2}$$ so that $f(x)$ and $x$ get closer and closer as $x\to+\infty$.

It's also cheap to compute with 2 additions, 2 multiplications and 1 division if you proceed thus:

• Compute $x^2$ (1 mult) and $x+x^2$ (1 addition); set $a=x+x^2$.
• Compute $x\times a$ (1 mult); set $b=x\times a$.
• Compute $1+a$ (1 addition); set $c=1+a$.
• Compute $b/c$ (1 division): that's $f(x)$.
-
the plot looks good. Thank you – bolov Jun 28 '14 at 16:21

You could use a common hyperbola $y = \sqrt{a^2 + x^2} - a$.

Example with $a = 10$:

-
yes, I saw it. No problem. – bolov Jun 28 '14 at 16:26
thank you. You guys are great. For now I went with @gniourf_gniourf answer because at first glance it looks faster to compute. – bolov Jun 28 '14 at 17:17
@bolov Here $y = x - a$ is the asymptote. My misgiving with $y = x$ being the asymptote is that there would be an (ugly) inflection point in that case, as mentioned by Yves. – M. Vinay Jun 28 '14 at 17:18
the inflection point unless it would be very "abrupt" (I don’t know the right terminology) isn’t a problem. – bolov Jun 28 '14 at 17:21
@gniourf_gniourf Thought as much. That's perhaps one reason (apart from ease of computation) that your answer is the accepted one. As I said, I find the inflection point ugly, and bolov's last reply-comment (on the question) says he's not fully sure he wants $y = x$ to be the asymptote, and would like to see the graph and then decide. Hence my answer. – M. Vinay Jun 28 '14 at 18:10

You can use a weighting function $w(x)$ that allows you to create a mixture between the functions $x^2$ and $x$, as $\frac{x^2+w(x)x}{1+w(x)}$. Ensure $w(0)=0$ so that the initial behavior is $x^2$ and $w$ growing sufficiently fast that the term $x$ supersedes it. $$w(x)=x^3\to y=\frac{x^2+x^4}{1+x^3}.$$ $$w(x)=e^x-1\to y=\frac{x^2+x(e^x-1)}{e^x}.$$

Note that if you really want to reach $y=x$ (and not $y=x-c$), there must be an inflection point.

-
Nice. I thought of a similar one with a weight function $\theta = 1/e^x$ (and $y = \theta x + (1 - \theta)x$): $$y = \dfrac{x^2}{e^x} + x\left(1 - \dfrac{1}{e^x}\right)$$ – M. Vinay Jun 28 '14 at 17:03
thank you. You guys are great. For now I went with @gniourf_gniourf answer because at first glance it looks faster to compute. – bolov Jun 28 '14 at 17:18

Consider the derivative of your function. It has to be positive,increasing and $f'(x→inf)=1$ $f'(x)=tanh(x)$ fits.

$\int \tanh(x) dx = \log (\cosh (x))+c$

Since we want $f(0)=0$

$\log (\cosh 0)+c=0\Leftrightarrow c=0$

Therefor $f(x)= \log (\cosh (x))$ works.

-
thank you. You guys are great. For now I went with @gniourf_gniourf answer because at first glance it looks faster to compute. – bolov Jun 28 '14 at 17:19

Using your data, I found that $y=a x^b$ fits very well. My results are $a=0.008755$ and $b=3.134091$. The corresponding $R^2=0.999$.

This is a very flexible form.

-
f(x) > x for a certain C, f(x) > x for x > C – bolov Jun 28 '14 at 16:11