# NonlinearModelFit won't fit to gaussian data

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",
"Table"];

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 =
NonlinearModelFit[databeta,
peakresponse[\[Beta], e1, e2], {{\[Beta], 80}, {e2, 100}}, e1,
MaxIterations -> Infinity];
nlmbeta
Print[nlmbeta["ParameterTable"]]
betaplot = Plot[nlmbeta[e1], {e1, 0, 500}, PlotRange -> All]
Show[databetaplot, betaplot]

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



Plot of my data Data + the bad fit Form of the fit

I am out of options to try.

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

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

nlmbeta["ParameterTable"]


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