# What can I do to get a better fit to my data?

I have started quite recently to use Mathematica and i found a problem, I'm trying to fit a function to my data, but i can't find the best fit around the minimum values (around 3.14).

w1 = 2.8602
w2 = 3.4209;


The model used here is

model = (a b/(b^2 + (t - w1)^2)) + (c d/(d^2 + (t - w2)^2))
result =
NonlinearModelFit[data, model, {a, b, c, d}, t,
MaxIterations -> 800, Method -> {NMinimize}]


The model above should fit my data:

https://www.dropbox.com/scl/fi/a9mjfhc409fdu9nqw5l8g/data.xlsx?dl=0&rlkey=bdvvzp819f2ntfuktg2g466fh

which gives

Any ideas ?

• The data you've posted is incomplete. Try using the backticks    to delimit the code block in your question instead of four spaces. Aug 16, 2020 at 15:08
• The data given is incomplete. It ends with {2.7093, 0.3385}, {2.7103,. And about two-thirds into the data is {2.6553 0.206} (i.e., a comma is missing and Mathematica multiplies the two number leaving you with just a single number rather than a list with two numbers).
– JimB
Aug 16, 2020 at 15:26
• Thank you for your remarks, i updated my data.
Aug 16, 2020 at 15:50

The issue is that the model is not complex enough to adequately describe the data. Mathematica functions are working just fine.

Your data is fairly symmetric around 3.14 and without much loss of generality the model

model2 = (a b/(b^2 + (t - w1)^2)) + (a b/(b^2 + (t - w2)^2))


produces a function nearly identical to the original model locking in the symmetry.

If values of b are chosen to get the function values near zero for t around 3.14, this results in a poor fit. Again, you really only have 2 parameters, a and b if you want to keep the symmetry. Using Manipulate you can convince yourself that the model is inadequate for your data:

Manipulate[
Show[ListPlot[data, PlotStyle -> Red],
Plot[(a b)/(b^2 + (-3.4209 + t)^2) + (a b)/(
b^2 + (-2.8602 + t)^2), {t, 2.5, 4}, PlotRange -> All]],
{{a, 0.08}, 0, 0.2, Appearance -> "Labeled"},
{{b, 0.08}, 0, 0.2, Appearance -> "Labeled"},
TrackedSymbols :> {a, b}]
`

You need a more complex model to obtain an adequate description of your data.

• Thank you for your answer. I used a model from the literature, which describes this kind of function. I will check if there are other complex models.