clc
clear all
global K
Y0=[0 0 0
293.3 2.141445291 3.688379481
462.8 2.536287882 4.200913729
966.2 2.352145581 6.525317012
1920 2.454642817 11.40142937
];
K=[1 2 1];
dt=0.001;
x=[0:dt:0.02]';
Cin=[0;200;500;1000;2000];
yy=[0 0 0
208.0886316 33.822843 78.56152111
376.5730526 31.98339108 168.7154254
802.9630526 29.05423171 204.8119954
1770 35.44630378 295.906807
];
[kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@objfun,K,Cin,yy)
function [C]=objfun(K,Y0,x)
for i=1:5
Z=Y0(i,:);
[tSol,YSol]=ode15s(@diffeq,x,Z);
C(i,:)=YSol(end,:)
end
end
function dYdt = diffeq(x,Y)
global K
k1=K(1);
k2=K(2);
k3=K(3);
dadt=-k1*Y(1)/(1+k1*Y(1));
dbdt=k1*Y(1)/(1+k1*Y(1))-k2*Y(2);
dcdt=k2*Y(2)-k3*Y(3);
dYdt=[dadt;dbdt;dcdt];
end