# How to improve the nonlinear fit to a data set [closed]

Some data to begin with

data = {{0, 0}, {0.05, 0.5786}, {0.5, 0.7202}, {1, 0.7902}, {2, 0.8978},
{3, 0.9246}, {4, 0.9620}, {5, 0.993}, {6, 1}, {7, 1}, {8, 1},
{9, 1}, {10, 1}};


I know from theory that the best fist to such data is the formula $0.5(1 + tanh(a + bx))$.

So I use the NonlinearModelFit

fit = NonlinearModelFit[data, 0.5*(1 + Tanh[a*x + b]), {a, b, c}, x]


which gives

where the dots correspond to the data, while the solid line to the fit. As we can see the result is not so good.

So, is there a way to obtain a better fit to my data? When I say better I mean that the solid fit line should pass very close from all given data points.

• "In theory there is no difference between theory and practice; in practice there is." What are the consequences of your data not matching the theory? Instrument problems? Theory is wrong? And if you just need a fit with no interpretation of the coefficients, why not just perform a linear interpolation between points? – JimB Jan 5 '16 at 17:55
• are you sure about your data? The curve does not seem to match well a Tanh. If you remove the {0,0} point it gets much better. Is it possible that that point is wrong? – glS Jan 5 '16 at 17:59
• Actually just dropping the first point and fixing c=1/2 is all you need. Note the given form can not pass through (0,0) and the data clearly asymptotes to 1 so you can fix c. – george2079 Jan 5 '16 at 19:22

workingData = Rest @ data;