curve fitting using lsqcurvefit on kinetic data for parameter estimation
54 views (last 30 days)
Show older comments
federico drudi
on 5 Nov 2024 at 5:29
Commented: Star Strider
on 6 Nov 2024 at 3:54
Hello,
I am fitting some experimental data (protein digestion kinetics) to the following model y = ymax+(ymax-y0)*exp(-k*t) using lsqcurvefit, were t is time (independent variable), y is concentration (dependent variable), and k, ymax and y0 are coefficient representing, respectively, the rate of the reaction, the maximum final concentration and the initial concentration.
The fitting seems to work well but the issue I cannot understand is why I get values of ymax higher than y0 when it should be the opposite.
Below you can find the code I'm using, do you have any idea/suggestion on where the issue could be?
Thanks a lot in advance for the hepl!!
xdata=[0; 30; 60; 90; 120; 180; 240];
ydata=[1.607; 2.346; 2.621; 2.967; 3.238; 3.479; 3.566];
coef = ["ymax","y0","k","R2","R2adj","RMSE"];
fun = @(x,xdata) x(1)+(x(1)-x(2))*exp(-x(3)*xdata)
x0 = [1,1,0.01];
lb = [0,0,0];
ub = [10,10,0.5];
[x,resnorm,residual,exitflag,output] = lsqcurvefit(fun,x0,xdata,ydata,lb,ub);
figure(1);
plot(xdata,ydata,'o',xdata,fun(x,xdata),'-');
SSresid = sum(residual.^2);
SStotal = (numel(ydata)-1) * var(ydata);
R = 1 - SSresid/SStotal;
Radj = 1 - (SSresid/SStotal) * ((numel(ydata)-1)/(numel(ydata)-1-1));
RMSE = rmse(fun(x,xdata),ydata);
r = [x R Radj RMSE];
coef = [coef;r];
figure(2);
scatter(xdata,residual);
coef
0 Comments
Accepted Answer
Star Strider
on 5 Nov 2024 at 13:33
The model itself is a bit misleading.
A better option might be:
That produces an equivalent fit with parameters that make sense.
xdata=[0; 30; 60; 90; 120; 180; 240];
ydata=[1.607; 2.346; 2.621; 2.967; 3.238; 3.479; 3.566];
coef = ["ymax","y0","k","R2","R2adj","RMSE"];
% fun = @(x,xdata) x(1)+(x(1)-x(2))*exp(-x(3)*xdata)
fun = @(x,xdata) x(2)+(x(1)-x(2))*(1-exp(-x(3)*xdata));
x0 = [1,1,0.01];
lb = [0,0,0];
ub = [10,10,0.5];
[x,resnorm,residual,exitflag,output] = lsqcurvefit(fun,x0,xdata,ydata,lb,ub);
x
figure(1);
plot(xdata,ydata,'o',xdata,fun(x,xdata),'-');
SSresid = sum(residual.^2);
SStotal = (numel(ydata)-1) * var(ydata);
R = 1 - SSresid/SStotal;
Radj = 1 - (SSresid/SStotal) * ((numel(ydata)-1)/(numel(ydata)-1-1));
RMSE = rmse(fun(x,xdata),ydata);
r = [x R Radj RMSE];
coef = [coef;r];
figure(2);
scatter(xdata,residual);
coef
.
2 Comments
More Answers (1)
Umang Pandey
on 5 Nov 2024 at 6:51
Hi Federico,
Looking at your xdata and ydata, your ydata is increasing with increase in xdata, but the delta for each consecutive increase decreases, implying it is fitting "y = a - bexp(-kx)" where a,b,k are > 0. Since you are expecting "ymax > y0", your ydata should have been decreasing with increase in xdata, with the delta also decreasing for each consecutive decrease.
I have attached the following curves for your reference:
Case 1 : y = 4 - 3*exp(-2x) ; Assumptions : ymax = 4, y0 = 7, k = 2
Case 2 : y = 4 + 3*exp(-2x) ; Assumptions : ymax = 4, y0 = 1, k = 2
As you can see from the curve, your data/curve you obtained fits the first case.
Hope this helps!
Best,
Umang
0 Comments
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!