I'm trying to fit the array data as follow:
NonlinearModelFit[
data,
s*t^r + (A/(w*(Pi/2)^0.5))*Exp[-2*((t - u)/w)^2],
{s, r, A, w, u},
t];
But when I run it, it gives the following problem:
Exp[] is too small to represent as a normalized machine number; precision may be lost.
Do you know how to solve it?
Thank you!
Here the code:
data={{9331200, 2.25014*10^-14}, {9590400, 2.94221*10^-14}, {12441600,
2.25158*10^-14}, {13219200, 1.88385*10^-14}, {13564800,
8.74689*10^-15}, {13824000, 1.65873*10^-14}, {13910400,
1.91969*10^-14}, {14083200, 1.85371*10^-14}, {14256000,
1.21808*10^-14}, {22464000, 1.55479*10^-14}};
errors={2.35061*10^-15, 4.03579*10^-15, 2.57128*10^-15, 3.17395*10^-15,
4.44869*10^-15, 3.86327*10^-15, 3.73115*10^-15, 1.55858*10^-15,
4.62527*10^-15, 1.50732*10^-15};
dataPlot = ListLogLogPlot[data, PlotRange -> Full];
(*First Fit with Powerlaw, it works*)
Pow = NonlinearModelFit[data, k*t^h, {k,h}, t,
MaxIterations -> 1000, Weights -> 1/errors^2];
PowPlot =
LogLogPlot[Pow[t], {t, 100*24*3600, 260*24*3600}, PlotStyle -> Red,
PlotRange -> Full];
"Plot powerlaw:"
Show[{PowPlot, dataPlot}, PlotRange -> Full]
Pow["ParameterTable"]
chi1r = Pow["EstimatedVariance"]
(*Second Fit with Powerlaw+Gaussian, where it gives that problem*)
Pgauss = NonlinearModelFit[data,
s*t^r + (A/(w*(Pi/2)^(1/2)))*Exp[-2*((t - u)/w)^2], {s, r, A, w,
u}, t, Weights -> 1/errors^2, MaxIterations -> 1000,
WorkingPrecision -> 50, Method -> NMinimize];
PgaussPlot =
LogLogPlot[Pgauss[t], {t, 100*24*3600, 260*24*3600}, PlotStyle -> Red];
"Plot powerlaw+gaussiana:"
Show[{PgaussPlot, dataPlot}]
Pgauss["ParameterTable"]
chi2r = Pgauss["EstimatedVariance"]
Thank you very much!
NonlinearModelFit[data, model, {{s, 1.}, {r, 2.}, etc}}]
or choosingMethod->"NMinimize"
might help. $\endgroup$Rationalize
your data, change0.5
to1/2
, and specify aWorkingPrecision
to use arbitrary-precision:NonlinearModelFit[data, st^r + (A/(w (Pi/2)^(12))) Exp[-2 ((t - u)/w)^2], {s, r, A, w, u}, t, WorkingPrecision -> 25]
Even higher precision may be needed. $\endgroup$