Compare Two Fits in an Optimization Problem
Compare Two Fits in an Optimization Problem
It is often useful to compare two different fits generated by FindFit.
model = a Exp[-b (x - c) ^ 2] + d Sin[ω x + ϕ];
data = Table[{x, model /. {a -> 2, b -> 1, c -> 0, d -> 2, ω -> 0.67, ϕ -> 0.1}}, {x, -5, 5, .1}] + RandomReal[.25, 101];f1 = FindFit[data, model, {a, b, c, d, ω, ϕ}, x]f2 = FindFit[data, model, {a, b, {c, 0}, d, ω, ϕ}, x]Show[Plot[Evaluate[model /. {f1, f2}], {x, -5, 5}, PlotStyle -> {Red, Blue}], ListPlot[data, PlotRange -> All, PlotStyle -> Gray]]