function KineticsEst5
% ¶¯Á¦Ñ§ODE·½³ÌÄ£Ð͵IJÎÊý¹À¼Æ
clear all
clc
k0 = [0 0 0 0]; % ²ÎÊý³õÖµ
lb = [ -inf -inf -inf -inf ]; % ²ÎÊýÏÂÏÞ
ub = [+inf +inf +inf +inf ]; % ²ÎÊýÉÏÏÞ
x0 = [8.5 28.8 27.6];
tspan=[0 0.222 0.333 0.444];
yexp = [8.5000 28.8000 27.6000
4.8000 23.2000 35.3000
4.2000 21.6000 36.5000
4.0000 21.2000 37.3000]; % yexp: ʵÑéÊý¾Ý[x1 x2 x3]
% ʹÓú¯Êýfmincon()½øÐвÎÊý¹À¼Æ
[k,fval,flag] = fmincon(@ObjFunc4Fmincon,k0,[],[],[],[],lb,ub,[],[],x0,yexp);
fprintf('\nʹÓú¯Êýfmincon()¹À¼ÆµÃµ½µÄ²ÎÊýֵΪ:\n')
fprintf('\tk1 = %.4f\n',k(1))
fprintf('\tk2 = %.4f\n',k(2))
fprintf('\tk3 = %.4f\n',k(3))
fprintf('\tk4 = %.4f\n',k(4))
fprintf(' The sum of the squares is: %.1e\n\n',fval)
k_fmincon = k;
% ʹÓú¯Êýlsqnonlin()½øÐвÎÊý¹À¼Æ
[k,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(@ObjFunc4LNL,k0,lb,ub,[],x0,yexp);
ci = nlparci(k,residual,jacobian);
fprintf('\n\nʹÓú¯Êýlsqnonlin()¹À¼ÆµÃµ½µÄ²ÎÊýֵΪ:\n')
Output
% ÒÔº¯Êýfmincon()¹À¼ÆµÃµ½µÄ½á¹ûΪ³õÖµ£¬Ê¹Óú¯Êýlsqnonlin()½øÐвÎÊý¹À¼Æ
k0 = k_fmincon;
[k,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(@ObjFunc4LNL,k0,lb,ub,[],x0,yexp);
ci = nlparci(k,residual,jacobian);
fprintf('\n\nÒÔfmincon()µÄ½á¹ûΪ³õÖµ£¬Ê¹Óú¯Êýlsqnonlin()¹À¼ÆµÃµ½µÄ²ÎÊýֵΪ:\n')
Output
% ------------------------------------------------------------------
function f = ObjFunc4Fmincon(k,x0,yexp)
tspan = [0.00 : 0.01 : 0.44];
[t x] = ode45(@KineticEqs,tspan,x0,[],k);
y(:,1:3) = x(:,1:3);
f = sum((y(:,1)-yexp(:,1)).^2) + sum((y(:,2)-yexp(:,2)).^2) ...
+ sum((y(:,3)-yexp(:,3)).^2) ;
% ÒÔº¯Êýfmincon()¹À¼ÆµÃµ½µÄ½á¹ûΪ³õÖµ£¬Ê¹Óú¯Êýlsqnonlin()½øÐвÎÊý¹À¼Æ
k0 = k_fmincon;
[k,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(@ObjFunc4LNL,k0,lb,ub,[],x0,yexp);
ci = nlparci(k,residual,jacobian);
fprintf('\n\nÒÔfmincon()µÄ½á¹ûΪ³õÖµ£¬Ê¹Óú¯Êýlsqnonlin()¹À¼ÆµÃµ½µÄ²ÎÊýֵΪ:\n')
Output
% ------------------------------------------------------------------
function f = ObjFunc4LNL(k,x0,yexp)
tspan = [0.00 : 0.01 : 0.44];
[t x] = ode45(@KineticEqs,tspan,x0,[],k);
y(:,1:3) = x(:,1:3);
f1 = y(:,1) - yexp(:,1);
f2 = y(:,2) - yexp(:,2);
f3 = y(:,3) - yexp(:,3);
f = [f1; f2; f3];
% ------------------------------------------------------------------
function dxdt = KineticEqs(t,x,k)
dxdt = ...
[ (k(1)*x(2)- k(1)*x(1))
(k(1)*x(2)+(k(3)-k(2)-k(4))*x(3))
(k(3)*x(2)-k(4)*x(3))
]; |