I want to fit some data to a model of exponential decay using the FindFit
function:
data = {{0, 78}, {24, 64.5}, {48, 70.5}, {96, 54}, {144, 64.5}, {216, 3}, {336, 0}, {696, 0}};
model = data[[1, 2]]*Exp[-k1*t];
fit1 = FindFit[data, model, k1, t]
fit2 = FindFit[data, {model, k1 > 0}, k1, t]
modelf1 = Function[{t}, Evaluate[model /. fit1]];
modelf2 = Function[{t}, Evaluate[model /. fit2]];
Plot[#[t], {t, 0, 696}, Epilog -> Map[Point, data], PlotRange -> All] & /@ {modelf1, modelf2}
Interestingly, the model with no specified constraint on k1 finds a much better solution than the constrained model, but the solution of the unconstrained problem falls within the range of the constrained one. Here is the output:
{k1 -> 0.00512571}
{k1 -> 1.01979}
Why isn't the solution to the constrained problem at least as good as the solution of the unconstrained one?
fit2 = FindFit[data, {model, k1 > 0}, k1, t, Method -> NMinimize]
$\endgroup$ – P. Fonseca Aug 23 '12 at 13:13