# How do I fit a non-linear function to data?

I have a function which looks like this:

f[x] = a-1/(b Exp[x]+ c x^2 + d x +e)


I have a number of data points. I need to be able to find {a,b,c,d,e} to fit the data as fast as possible (in terms of computing speed). What is the best way to do this?

• What software are you using? Matlab? Excel? Maple? R? Mathematica? Python? Also check your expression, do you mean $(a-1)/(...)$ or $a-\frac{1}{...}$? Oct 13 '17 at 20:07
• I'm doing it in c#. I did some experimentation with Mathematica, but I want the estimation to be done in stand-alone program, and maybe optimize the speed somewhat Oct 14 '17 at 8:55

You have $n$ data points $(x_i,y_i)$ and you want to fit the nonlinear model $$y=a -\frac 1 {b e^x+c x^2+d x+e}$$ and, as usual, you need good (or at least consistent) estimates of the parameters.
The easiest would be to assign $a$ an arbitrary value and define $\color{red}{z_i=\frac 1{a-y_i}}$
So, the model reduces to $$z= {b e^x+c x^2+d x+e}$$ So, for the given value of $a$, multilinear regression gives you parameters $b,c,d,e$ which all depend on $a$. Now, compute again the predicted $y$'s and the corresponding sum of squares $$SSQ(a)=\sum_{i=1}^n \left(a -\frac 1 {b e^{x_i}+c x_i^2+d x_i+e} \right)^2$$ Try a few values of $a$ and plot the function $SSQ(a)$ as a function of $a$. You will notice an area where it goes through a minimum; you do not need to be accurate at all. For this close to optimal value, you have the values of all remaining parameters.