What is the proposed approach if one wants to simultaneously fit multiple functions to multiple datasets with shared parameters?
As an example consider the following case: We have to measurements of Gaussian line profiles and we would like to fit a Gaussian to each of them but we expect them to be at the same line center, i.e. the fitting should use the same line center for both Gaussians.
The solution I came up with looks a little clumsy. Any ideas on how to do this better, especially in cases where we have more than 2 datasets and more than one shared parameter?
Example:
f[x_, amplitude_, centroid_, sigma_] :=
amplitude Exp[-((x - centroid)^2/sigma^2)]
data1 = Table[{x, RandomReal[{-.1, .1}] + f[x, 1, 1, 1]}, {x, -4, 6,
0.25}];
data2 = Table[{x, RandomReal[{-.1, .1}] + f[x, .5, 1, 2]}, {x, -8, 10,
0.5}];
gauss1 = NonlinearModelFit[data1, f[x, a1, x1, b1], {a1, x1, b1}, x,
MaxIterations -> 1000, Method -> NMinimize];
gauss2 = NonlinearModelFit[data2,
Evaluate[f[x, a2, x1, b2] /. gauss1["BestFitParameters"]], {a2,
b2}, x, MaxIterations -> 1000, Method -> NMinimize];
Join[gauss1["BestFitParameters"],gauss2["BestFitParameters"]]
datpl = ListPlot[{data1, data2}, Joined -> True,
PlotRange -> {{-10, 10}, All}, Frame -> True,
PlotStyle -> {Black, Red}, Axes -> False, InterpolationOrder -> 0];
Show[{datpl,
Plot[{Evaluate[f[x, a1, x1, b1] /. gauss1["BestFitParameters"]],
Evaluate[
f[x, a2, x1 /. gauss1["BestFitParameters"], b2] /.
gauss2["BestFitParameters"]]}, {x, -10, 10}, PlotRange -> All,
PlotStyle -> {Black, Red},
Frame -> True, Axes -> False]}]