# Trouble fitting with NonlinearModelFit

I'am having a bit of a headache comparing the results from the NonlinearModelFit to a particular dataset. I have the following dataset,

data = {{0.1, 4.00159}, {0.2, 8.22197}, {0.3, 0.992585}, {0.4, 1.00674}, {0.5, 0.831299}, {0.6, 0.780187}, {0.7, 0.87409}, {0.8, 0.910718}, {0.9, 1.11082}, {1., 0.88152}, {1.1, 0.742595}, {1.2, 0.691634}, {1.3, 0.768007}, {1.4, 0.770361}, {1.5, 0.83516}, {1.6, 0.754678}, {1.7, 0.870984}, {1.8, 0.970947}, {1.9, 0.911232}, {2., 0.912085}, {2.1, 0.944218}, {2.2, 0.959657}, {2.3, 0.879098}, {2.4, 1.11405}, {2.5, 1.12227}, {2.6, 1.04505}, {2.7, 1.0546}, {2.8, 1.04352}, {2.9, 1.11671}};

nlm = NonlinearModelFit[data, a (b - x)^2 + c, {a, b, c}, x]
Show[ListPlot[data], Plot[nlm[x], {x, 0, 3}]]


This gives me the model as FittedModel[0.429375 + 1.0901 (1.78331 - x)^2], plotting this agains the datapoints results in the following graph.

Now this model seems rather far off to what one might expect. I have a few datasets, similar to the one above, and I'm solely interested in the b parameter, that is, the shift of the quadratic function. Using these, I'd expect b to be around 1.30 .

To give an example of a different dataset,

FittedModel[0.711971 + 0.130242 (1.25498 - x)^2]

So my question is, why does NonlinearModelFit find this solution, even when given starting values near the expected model? And how can I get it to find a model closer to the expected model?

• You could try to impose a constraint on the possible values of your parameter. Take a look at the third syntax form in the NonlinearModelFit documentation page. Constraints can be expressed as inequalities. Jun 10, 2015 at 12:56
• Dropping the first 2 datapoints provides a fit with a b parameter within your expected region. Substitute data[[3;;]] for data in your first code block and get ~ 1.29 for b. Jun 10, 2015 at 13:02

## 1 Answer

The problem is due to the first two data points.

Show[ListPlot[data], Plot[nlm[x], {x, 0, 3}], PlotRange -> All]


• Sigh.. Yes that explains it, I did not realise the first two data points where that far off, I've got to make a habit of including PlotRange->All. Thank you for your time! Jun 10, 2015 at 13:49