2
$\begingroup$

I want to fit my data as the sum of two exponential along with the condition a + b = 1; How I can introduce the constraint into my model.

data = 
  {{0., 100.}, {0.02, 81.87}, {0.04, 67.03}, {0.06, 54.88}, 
   {0.08, 44.93}, {0.1, 36.76}};

model = a Exp[-k1 t] + b Exp[-k2 t];

fit = FindFit[data, model, {a, k1, b, k2}, t]
$\endgroup$

1 Answer 1

3
$\begingroup$

Since a+b=1, then b=1-a and it seems we can do what you are asking for thus:

data = {{0.,100.},{0.02,81.87},{0.04,67.03},{0.06,54.88},{0.08,44.93},{0.1,36.76}};
model = a Exp[-k1 t] + (1 - a) Exp[-k2 t];
fit = FindFit[data, model, {a, k1, k2}, t]

which gives us {a -> 100.039, k1 -> 10.0085, k2 -> 423.019}

Show[ListPlot[data], Plot[model /. fit, {t, 0, .1}]]

enter image description here

The left hand edge of that graph makes sense because when t=0 your model becomes a Exp[0]+(1-a) Exp[0]=a+(1-a)=1.

But you seem to get a much better fit with

model2 = a Exp[-k1 t];
fit = FindFit[data, model2, {a, k1}, t]

which gives us {a -> 100.004, k1 -> 10.0033}

enter image description here

$\endgroup$
3
  • $\begingroup$ after normalization can't we put a+b=1?? $\endgroup$ Commented Jun 21, 2017 at 10:10
  • $\begingroup$ How to get best fit parameter after that?? like R^2 value etc. $\endgroup$ Commented Jun 21, 2017 at 10:30
  • $\begingroup$ @Anita : Use NonlinearModelFit instead of FindFit, then e.g. fit["RSquared"] to give properties of the fit. $\endgroup$ Commented Jun 21, 2017 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.