The form I'm using should be correct because when I input my initial guesses it plots a shape similar to my data. When I use NonlinearModelFit, the fit is not correct at all and is almost flat, then curves at the end.

ClearAll[compton, \[Beta], l, e1, ec, e2, peakresponse, comptonresponse, response, e0]

listdata = 
  Import["B:\\PHY353L\\RelativisticDynamics\\NA22 day22.Spe", 

databeta = Transpose[{Range[501], listdata[[2500 ;; 3000, 1]]}];
databetaplot = ListPlot[databeta]

peakresponse[\[Beta]_, e1_, e2_] := (Abs[\[Beta]*e2*\[Pi]])^(-1/2) * 
  Exp[(-(e1 - e2)^2/(2*\[Beta] * e2))]

nlmbeta = 
   peakresponse[\[Beta], e1, e2], {{\[Beta], 80}, {e2, 100}}, e1, 
   MaxIterations -> Infinity];
betaplot = Plot[nlmbeta[e1], {e1, 0, 500}, PlotRange -> All]
Show[databetaplot, betaplot]

Plot[peakresponse[130, e1, 100], {e1, 0, 500}]

Plot of databeta Plot of my data Show[databetaplot, betaplot] Data + the bad fit peakresponse plot Form of the fit

In this google drive link are my notebook and data. https://drive.google.com/open?id=1YVKG7ZhNp3jBhbGDLHdBu-mR7iq0Z91N

I am out of options to try.

  • $\begingroup$ Notice the y-axis on your data, compared to the plot of peakresponse[130, e1, 100]. $\endgroup$
    – MelaGo
    Oct 31, 2019 at 19:15

1 Answer 1


Notice the y-axis range of the data (~20000), compared to the plot of the model (~0.005) . If you add an amplitude parameter to the model, it works much better.

peakresponse[a_, β_, e1_, e2_] := 
 a (Abs[β*e2*π])^(-1/2)*Exp[(-(e1 - e2)^2/(2*β*e2))]

nlmbeta = 
  NonlinearModelFit[databeta, peakresponse[a, β, e1, e2], 
   {{a, 3000000}, {β, 80}, {e2, 100}}, e1, 
   MaxIterations -> Infinity];


enter image description here

betaplot = Plot[nlmbeta[e1], {e1, 0, 500}, PlotRange -> All, PlotStyle -> Red];
Show[databetaplot, betaplot]

enter image description here


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.