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:


which gives

enter image description here

Any ideas ?

  • $\begingroup$ The data you've posted is incomplete. Try using the backticks ``` ` ``` to delimit the code block in your question instead of four spaces. $\endgroup$
    – flinty
    Aug 16, 2020 at 15:08
  • $\begingroup$ 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). $\endgroup$
    – JimB
    Aug 16, 2020 at 15:26
  • $\begingroup$ Thank you for your remarks, i updated my data. $\endgroup$
    – Adam
    Aug 16, 2020 at 15:50

1 Answer 1


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:

 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}]

Selection of a and b to get values near zero for t around 3.14

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

  • $\begingroup$ 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. $\endgroup$
    – Adam
    Aug 16, 2020 at 17:33
  • $\begingroup$ @Adam just as a general suggestion, you might find that you need to add to your model another function with separate parameters which helps to better define the curvature you want to fit to. $\endgroup$ Aug 17, 2020 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.