随便编了一下,拟合结果有点问题,估计是k的初值k0取得有问题或者数据太少或者实验数据有问题。。。
程序如下,其中k0是我随便设的初值,k1=k1,k2=k1',k3=k8,k4=k4*[O],k5=k5,k6=f
function piadatfit2
clear all;clc
tspan=[0 1 2 3 4 5 6 8 10];
cexp=[8.32016 0;7.37673 0.21115;
6.74433 0.7379;5.92613 1.10562;5.68806 1.29586;
5.01584 1.58327;6.09249 1.36404;5.34827 1.84065;4.9961 2.00986];
k0=[-0.1 1 -2.3 13 0.2 0.4];
c0=[8.32016 0];
LB=[0 0 0 0 0 0];
UB=[+inf +inf +inf +inf +inf +inf];
[k,resnorm,residual]=lsqnonlin(@objpia,k0,LB,UB,[],cexp,tspan,c0)
[tplot cplot]=ode45(@piakin,tspan,c0,[],k);
plot(tspan,cexp(:,1),'bx',tplot,cplot(:,1),'b-',tspan,cexp(:,2),'ko',tplot,cplot(:,2),'k-')
function f=objpia(k,cexp,tspan,c0)
[t c]=ode45(@piakin,tspan,c0,[],k);
f1=c(:,1)-cexp(:,1);
f2=c(:,2)-cexp(:,2);
f=[f1;f2];
function dcdt=piakin(t,c,k)
dc1dt=-(k(4)*k(5)*c(1)*sqrt(k(1)*c(2)/k(3))/(k(4)+k(5)*c(1))+2*k(6)*k(2)*c(2));
dc2dt=(k(4)*k(5)*c(1)*sqrt(k(1)*c(2)/k(3))/(k(4)+k(5)*c(1))+2*k(6)*k(2)*c(2));
dcdt=[dc1dt dc2dt]'; |