I am having trouble with the below code. I have two data sets, dataf and datag, which are exponential decays. datag decays faster than dataf. These two data sets are then later joined to make datah. I would like to simultaneously fit these two data sets with the functions f[x] and g[x], respectively. In the NonLinearModelFit of datah I use suitable initial conditions for the values of a and b, but as can be seen from the below plot the fits are not good. If I don't use initial conditions, I get the following error message: "General::munfl: Exp[-1.25177*10^10] is too small to represent as a normalized machine number; precision may be lost", and other similar error messages.
dataf = Table[{x, Exp[-x/250]}, {x, 0, 500, 50}];
datag = Table[{x, Exp[-x/100]}, {x, 0, 500, 50}];
datah = Join[{1, Sequence @@ #} & /@ dataf, {2, Sequence @@ #} & /@
datag];
f[x_] := Exp[-47000^2 ((a (4 a^2 + 21 a b + 9 b^2))/(
30 (a + b) (4 a + b))) x];
g[x_] := Exp[-130000^2 ((a (4 a^2 + 21 a b + 9 b^2))/(
30 (a + b) (4 a + b))) x];
h[\[Omega]_, x_] :=
KroneckerDelta[\[Omega] - 1]*f[x] +
KroneckerDelta[\[Omega] - 2]*g[x];
Clear[a, b]
nlmf = NonlinearModelFit[datah,
h[\[Omega], x], {{a, 10^-12}, {b, 10^-12}}, {\[Omega], x}];
Show[ListPlot[{dataf, datag}, PlotMarkers -> {\[FilledCircle], 10},
Joined -> False], Plot[{nlmf[1, x], nlmf[2, x]}, {x, 0, 500}]]
nlmf["ParameterConfidenceIntervalTable"]
If the exponential decays are quicker and the values inside the exponentials are smaller then the fits become reasonable. If anyone has any suggestions about how to resolve this issue then that would be greatly appreciated. Thanks.
dataf = Table[{x, Exp[-x/2]}, {x, 0, 5, 1/2}]; datag = Table[{x, Exp[-x/1]}, {x, 0, 5, 1/2}]; data = {dataf, datag} // N; f[x_] = Exp[-a x]; g[x_] = Exp[-b x]; fit = ResourceFunction["MultiNonlinearModelFit"][ data, {f[x], g[x]}, {a, b}, {x}]; Show[ ListPlot[data], Plot[{fit[1, x], fit[2, x]}, {x, -5, 5}] ]
$\endgroup$