I have a function, sum of three exponents:
F = f1*exp1 + f2*exp2 + f3*exp3
exactly:
F=1-((1-f(2)-f(3)).*(exp(-abs(data)./a(1)))+((1-f(1)-f(3)).*(exp(-abs(data)./a(2))))+((1-f(1)-f(2)).*(exp(-abs(data)./a(3)))));
where f1, f2, f3 is a fraction and each exp has one parameter, call it a1, a2 and a3.
So, fitting this function to experimental data gives six parameters (f1, f2, f3, a1, a2, a3).
Note, that
a1 > a2 > a3
and
f1 + f2 + f3 = 1
The fitting is done for several timelags (call it t1, t2, t3....). So for each timelag there is one set of six parameters.
Parameters a1, a2 and a3 are increasing with timelag in linear way ( a1(t1) < a1(t2) < a1(t3)... and so on). Fractions are the same for each timelag.
What I need is slope of a1(t), a2(t), a3(t) and fractions. The problem is, that when I am fitting the function for each timelag, I often have a situation that a1 and a2 are nicely going up (perfect linear fits) but a3 is going down. Also I have a problem with fractions - I can't take mean of each fraction because when I add f1(t) + f2(t) + f3(t) its never equal to 1.
Is there any (simple) way to fit it all 'at once'? How to do that? Thanks!
First, I would suggest to reduce the number of parameters:
That gives you two parameters for each ai(t), plus f1 and f2 for each time point, so a total of 6 + 2 * (# of timepoints) parameters. Depending on the number of timepoints, it may be possible to fit those with fmincon
, as suggested by Chris Taylor.
With fmincon
, you can add the parameter constraints in quite flexible ways. You probably want to add the constraint 0<=f1<=1 (and the same for f2) to the ones you already have.