# I need someone to create a function with certain features

• Sep 28th 2010, 06:16 AM
nathanf534
I need someone to create a function with certain features
I need a function f(x), that uses a as a constant.

-1<a<1

I need:
f(-1)=0
f(1)=1
f(a)=.5

The function must always have a positive (or zero) slope, and I would like it to be as smooth as possible.
I would also like the slope to be highest near a.

It must be continuous and differentiable everywhere from x=-1 to 1. Thanks :D

The function will be used in a computer program, so the most simple solution is best.
• Sep 28th 2010, 09:43 AM
Ackbeet
Very interesting problem, nathanf534! It took me a very long time to find even one solution. A simple cubic won't work, even if you use $\displaystyle y$ as the independent variable. Neither will a straight-forward arctangent function work. I'm assuming you need $\displaystyle x$ as the independent variable. My solution is a pasting of two functions together at $\displaystyle a$ such that the function values and the function derivatives match up there. Is that an acceptable solution? I also have a vertical tangent at $\displaystyle a$. I'm not sure if that's acceptable or not. Technically, the function is not differentiable there. I've tried making the solution better behaved there, but for some reason it's balking. Here is my solution so far:

$\displaystyle \displaystyle{f(x)=\begin{cases} \frac{a+1-\sqrt{a+1}\sqrt{a-x}}{2(1+a)}&\quad x\in[-1,a]\\ \frac{a-1+\sqrt{a-1}\sqrt{a-x}}{2(a-1)}&\quad x\in[a,1] \end{cases}}.$

Let me know if this works for you. I obtained this solution through a rather circuitous route. First I solved the same problem, but with $\displaystyle x\in[0,1].$ The conditions turn out nicer and were easier to work with. I then transformed the solution into the proper domain by a linear transformation on $\displaystyle x$. The ansatz was two quadratics in $\displaystyle y$ that I pieced together at the required point, matching up both function values and derivatives. I also forced the concavities in order to assure that the derivative was maximized at $\displaystyle a$.
• Sep 28th 2010, 10:22 AM
Ackbeet
After further computations, I have discovered that, using this approach, the solution found above is the only solution. Now, a different ansatz may give better answers. However, this is what you get with this approach.
• Sep 28th 2010, 10:37 AM
nathanf534
Thank you for taking time to solve this. I was hoping there was a more simple solution, but I will try out what you gave me and see what I can do with it.
• Sep 30th 2010, 05:40 AM
Ackbeet
There's another solution that my father produced. The only difficulty is that there is one parameter for which it is difficult to solve. Here is the solution:

$\displaystyle \displaystyle{y=\frac{\tan^{-1}\left(\frac{x-a}{b}\right)-\tan^{-1}\left(\frac{-1-a}{b}\right)}{\tan^{-1}\left(\frac{1-a}{b}\right)-\tan^{-1}\left(\frac{-1-a}{b}\right)}}.$

This satisfies $\displaystyle f(-1)=0,\;f(1)=1,$ monotone increasing, and the slope is maximized at $\displaystyle a$. However, you must solve for $\displaystyle b$ such that $\displaystyle f(a)=1/2.$ For all the cases I've tried, this is possible to do. However, I don't know how easy it would be to do numerically in whatever programming language you're using. You might try different methods, as well, depending on how many different $\displaystyle a$'s for which you must produce the curve.

If you simply write out the equation $\displaystyle f(a)=1/2,$ you obtain

$\displaystyle \displaystyle{\frac{-\tan^{-1}\left(\frac{-1-a}{b}\right)}{\tan^{-1}\left(\frac{1-a}{b}\right)-\tan^{-1}\left(\frac{-1-a}{b}\right)}=\frac{1}{2}}.$

It is possible to eliminate all the arctangents. However, the resulting algebraic equation is quite messy. If you can solve for $\displaystyle b$ numerically quickly enough for your application, I'd recommend that instead.