Fitting Monod Equation with ODE45 to data using lsqcurvefit function
Mostra commenti meno recenti
Hello!
I am fitting Monod equation to a data containing substrate (s), biomass (x), and ethanol (p) concentration against time. The objective is to get the parameters: 1) umax, 2) ks, 3) Yxs, and 4)Yps that will best represent the data. The differential equations are:



Here is my initial code using assumed values of the four parameters:
umax = 0.5;
ks = 6.5;
Yxs = 0.2;
Yps = 1.2;
%a(1) = x
%a(2) = s
%a(3) = p
f = @(t,a) [umax*a(1)*a(2)/(ks + a(2)); -(1/Yxs)*umax*a(1)*a(2)/(ks + a(2)); (1/Yps)*umax*a(1)*a(2)/(ks + a(2))];
xt0 = [0.0904,9.0115,0.0151];
[tspan,a] = ode45(f,[0 25],xt0);
figure
plot(tspan,a(:,1),tspan,a(:,2),tspan,a(:,3))
Here is the code for trying to fit it into the actual data (script file):
function pos = paramfun1(x,tspan)
umax = x(1);
ks = x(2);
Yxs = x(3);
Yps = x(4);
xt0 = x(5:7);
f = @(t,a) [umax*a(1)*a(2)/(ks + a(2)); -(1/Yxs)*umax*a(1)*a(2)/(ks + a(2)); (1/Yps)*umax*a(1)*a(2)/(ks + a(2))];
[~,pos] = ode45(f,tspan,xt0);
Here is my call function (in the command window):
xt0 = zeros(1,7);
xt0(1) = umax;
xt0(2) = ks;
xt0(3) = Yxs;
xt0(4) = Yps;
data =[0 3 5 8 9.5 11.5 14 16 18 20 25 27, 0.0904 0.1503 0.2407 0.3864 0.5201 0.6667 0.8159 0.9979 1.0673 1.1224 1.1512 1.2093; 0 3 5 8 9.5 11.5 14 16 18 20 25 27, 9.0115 8.8088 7.9229 7.2668 5.3347 4.911 3.5354 1.4041 0 0 0 0; 0 3 5 8 9.5 11.5 14 16 18 20 25 27, 0.0151 0.0328 0.0621 0.1259 0.2949 0.3715 0.4199 0.522 0.5345 0.6081 0.07662 0.7869];
%time =[0 3 5 8 9.5 11.5 14 16 18 20 25 27];
[pbest,exitflag,output] = lsqcurvefit(@paramfun,xt0,tspan,data);
fprintf('New parameters: %f, %f, %f, %f',pbest(1:4));
The error is function value not equal to YDATA. Btw, this code was based from an example in MATLAB. (https://www.mathworks.com/help/optim/ug/fit-differential-equation-ode.html)
My data is:
time = [0 3 5 8 9.5 11.5 14 16 18 20 25 27]
x = 0.0904 0.1503 0.2407 0.3864 0.5201 0.6667 0.8159 0.9979 1.0673 1.1224 1.1512 1.2093
s = 9.0115 8.8088 7.9229 7.2668 5.3347 4.911 3.5354 1.4041 0 0 0 0
p = 0.0151 0.0328 0.0621 0.1259 0.2949 0.3715 0.4199 0.522 0.5345 0.6081 0.07662 0.7869
Please help! I do not know how to input my data into the lsqcurvefit function.
Thanks in advance!
Risposta accettata
Più risposte (2)
Alex Sha
il 21 Ott 2019
The follow results obtained from 1stOpt may be used for comparison:
Code:
Variable t,x,s,p;
ODEFunction x'=umax*s*x/(ks + s);
s'=-(1/Yxs)*umax*s*x/(ks + s);
p'=(1/Yps)*umax*s*x/(ks + s);
Data;
t = [0 2 4 6 8 10 12 14 16];
x = [0.06 0.11 0.46 0.78 1.42 2.36 2.49 2.49 2.54];
s = [9.54 9.33 9.52 9.06 8.05 7.27 6.03 5.80 5.51];
p = [0.00 0.00 0.00 0.01 0.18 0.35 0.49 0.53 0.55];
Results:
Root of Mean Square Error (RMSE): 0.250520910244571
Sum of Squared Residual: 1.50625743527444
Correlation Coef. (R): 0.981509121545543
R-Square: 0.963360155677103
Adjusted R-Square: 0.914727231437843
Determination Coef. (DC): 0.942399473562309
F-Statistic: 14.7361249635671
Parameter Best Estimate
-------------------- -------------
umax 0.117013263727751
ks -5.83263810513223
yxs 0.699511367324087
yps 5.01252941213249



2 Commenti
Vinoj Liyanaarachchi
il 21 Ott 2019
Rifat Hasan
il 2 Nov 2022
Hi ! I have tried to run the code by David welson. I am getting an error.
Solver stopped prematurely.
lsqcurvefit stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 7.000000e+02.
How can I solve this issue?
Alex Sha
il 21 Ott 2019
0 voti
Hi, Vinoj Liyanaarachchi, the code have been provided above alreadly, but note, that code is not for Matlab, but for another package called 1stOpt. In Matlab, no matter lsqcurvefit or fminsearch functions, are all to adopt local optimization algorithms, it is why those functions depended haveily on initial start-values. Global optimization toolbox in Matlab (like GA) is not good enough to ensure the global solution.
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


