Find a function with certain requirements I'm trying to find a function $y=f(x)$ that can be described as follows:
$f(x) = g(x) + c/(x-x_a)$.
With $f(x)$ I want to design a function with the following properties:


*

*$f(0) = 0$;

*$f(x)$ has a maximum at $x_1, \quad x_1>0$;

*the maximum of $f(x)$ is $\max(f(x))=f(x_1)=y_\max$

*$f(x_2) = 0, \quad x_2>x_1$;

*$f(x)$ has a vertical asymptote at $x=x_a, \quad x_a<0$;

*$f(x)$ has a second asymptote which is a function $g(x)$;


Thus: I want to set $x_1, x_2$ and $y_\max$ and provide a function $g(x)$ to create a function with the listed requirements.
I have tried to implement this by solving a system of non-linear equations, but I could not achieve a function with all the listed conditions being met. I used MATLAB function fsolve to solve the unknown parameters of $g(x), c$ and $x_a$, by solving $f(x)$ for the unknown parameters manually (this could be done using the symbolic math toolbox as well).
An example, to give you a better feeling for what I'm looking for, is shown in the figure below. In the example, the asymptote function I used was $g(x) = ax+b$, so $a$ and $b$ are additional parameters to solve.

From the figure you can see that conditions $f(0)=0$ and $f(x_2)=0, x_2=7$ have been met, but in this case I didn't manage to set the desired value of the maximum ($y_\max$) at the desired $x$-value ($x_1$). How do I do this (by hand and/or using MATLAB)? Do I need to solve $\mathrm{d}f(x)/\mathrm{d}x=0$ for the parameters involving the peak height and $x$-location, or can this be done in a different or more efficient way?
 A: Without loss of generality (by rescaling $x$ and $y$), one may assume $x_1=t$ (with $0<t<1$), $x_2=1$, and $y_{max}=1$.
Your parametric model is (setting $\frac{x_a}{x_2}=d$):
$$f(x)=ax+b+\frac c{x-d},$$
which can be rewritten as
$$ax^2+b'x+c'+df(x)=xf(x),$$
where $b'=b-ad,c'=c-bd$.
The derivative is such that
$$2ax+b'+df'(x)=f(x)+xf'(x).$$
From the first condition $f(0)=0$, you get $c'=0$. Plugging the remaining conditions, you get an easy linear system of $3$ equations in $3$ unknowns:
$$\begin{align}f(t)=1&\implies at^2+b't+d=t,\\
f'(t)=0&\implies 2at+b'=1,\\
f(1)=0&\implies a+b'=0.\end{align}$$
Then
$$a=\frac1{2t-1},\\
b'=-\frac1{2t-1},\\
d=\frac{t^2}{2t-1}.
$$
From there,
$$b=b'+ad=\frac{(t-1)^2}{(2t-1)^2},\\
c=bd=\frac{t^2(t-1)^2}{(2t-1)^3}.$$
For $t<\frac12$ (i.e. $x_1<\frac{x_2}2$ like in your example), the value of $d$ (and $x_a$) is negative and this model works.
A: In this case, you just multiply the answer you have by a constant. If we call your current answer $f$, then you have $f(x_1) = c$ for some value $c$. Yo'd like it to be, say, $e$. So define
$$
F(x) = \frac{e}{c} f(x)
$$
and you've got your function. 
A: OK, so my initial answer totally missed the point, but after having considered this a bit more, I came up with the following:
$$
\begin{align}
f(x)&=-\frac23x+\frac{50}9+\frac{-200/27}{x+4/3}
\end{align}
$$
which appears to solve the exact problem you posed. Here is a Wolfram|Alpha table confirming that $f(0)=f(7)=0$ and $f(2)=2$ as desired.

Here is how I found it:

The blue curve is given by $(x+k)^2(y+1)=(k+2)^2$ passing through $(2,0)$ and having asymptotes $x=-k$ and $y=-1$. The purple curve is given by
$$
h(x)=-\frac{(k+2)^2}{x+k}-x
$$
and is a primitive function of the blue curve $y=\dfrac{(k+2)^2}{(x+k)^2}-1$. Then writing out $h(0)=h(7)$ and solving for $k$ yields $k=4/3$. With this we are able to define the red curve, the solution to your problem, namely by scaling and transposing $h$ as follows:
$$
f(x)=\frac{2}{h(2)-h(0)}\cdot(h(x)-h(0))
$$
in which $h(2)-h(0)=3$ and $h(0)=-25/3$, and the constants I wrote in the beginning of my answer follows as an immediate consequence of this after a couple of simple calculations.
