24小时热门版块排行榜    

查看: 2791  |  回复: 7
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

ronghengyidu

木虫 (小有名气)

[求助] matlab拟合反应动力学参数 已有1人参与

本人是matlab大白,最近仿照黄华江编著的“实用化工计算机模拟”例题7-5拟合动力学参数,
           动力学方程为dc1/dt=k1*c1/(k2+k3*c1+k4*c2+k5*c1*c2),拟合k1,k2,k3,k4,k5,
           matlab程序和动力学数据见附件,运行出现如下错误,请各位大拿帮助。
                  

Error: File: KineticsEst.m Line: 47 Column: 60
Unbalanced or unexpected parenthesis or bracket.

Error in run (line 64)
evalin('caller', [script ';']);

Error: File: KineticsEst.m Line: 47 Column: 60
Unbalanced or unexpected parenthesis or bracket.

Error in run (line 64)
evalin('caller', [script ';']);
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : KineticsEst.m
  • 2016-10-03 16:39:52, 1.98 K
  • 附件 2 : KineticsData.m
  • 2016-10-03 16:40:16, 365 bytes

» 收录本帖的淘帖专辑推荐

程序

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ronghengyidu

木虫 (小有名气)

送红花一朵
引用回帖:
4楼: Originally posted by lu_yu_lan at 2016-10-04 08:37:24
是不是还有一个微分方程,dc2/dt=... ...。
否则应该怎样使用c2数据呢?...

C2初始值是C1初始值的十倍,但是反应过程中C1消耗值与C2消耗值一样
5楼2016-10-04 19:30:02
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 8 个回答

lu_yu_lan

新虫 (初入文坛)

【答案】应助回帖

★ ★
感谢参与,应助指数 +1
月只蓝: 金币+2, 感谢应助! 2016-10-04 21:59:50
楼主的问题,没有看明白,找到了 黄华江编著的“实用化工计算机模拟”例题7-5拟合动力学参数

7个微分方程,5个拟合参数k1,k2,k3,k4,k5,初值t=0时,x为0.1883,  0.2507,  0.0467,  0.0899,  0.1804,  0.1394,  0.1046

  q = 8.75 + k5,
  dx1/t=  k5-q*x1- k1*x1*x2-k4*x1*x6*sqrt(0.9),
  dx2/t=  7.0-q*x2 - k1*x1*x2-2*k2*x2*x3,
  dx3/t=  1.75 -q*x3 - k2*x2*x3,
  dx4/t=  -q*x4 + 2*k1*x1*x2-k3*x4*x5,
  dx5/t=  -q*x5 + 3*k2*x2*x3-k3*x4*x5,
  dx6/t=  -q*x6 + 2*k3*x4*x5-k4*x1*x6*sqrt(0.9),
  dx7/t=  -q*x7 + 2*k4*x1*x6*sqrt(0.9)

数据:t,x1,x4,x5,x6
    0         0.1883        0.0899    0.1804         0.1394
    0.0100    0.2047    0.0866    0.1729    0.1297
    0.0200    0.2181    0.0856    0.1680    0.1205
    0.0300    0.2291    0.0863    0.1647    0.1123
    0.0400    0.2382    0.0878    0.1623    0.1053
    0.0500    0.2459    0.0899    0.1604    0.0995
    0.0600    0.2523    0.0921    0.1588    0.0948
    0.0700    0.2576    0.0945    0.1574    0.0911
    0.0800    0.2622    0.0968    0.1561    0.0882
    0.0900    0.2660    0.0989    0.1548    0.0859
    0.1000    0.2692    0.1010    0.1537    0.0842
    0.1100    0.2719    0.1028    0.1525    0.0830
    0.1200    0.2742    0.1045    0.1515    0.0821
    0.1300    0.2761    0.1060    0.1505    0.0814
    0.1400    0.2777    0.1074    0.1495    0.0810
    0.1500    0.2790    0.1086    0.1487    0.0807
    0.1600    0.2801    0.1096    0.1479    0.0805
    0.1700    0.2811    0.1106    0.1471    0.0803
    0.1800    0.2819    0.1114    0.1465    0.0803
    0.1900    0.2825    0.1121    0.1458    0.0803
    0.2000    0.2830    0.1127    0.1453    0.0803

用OpenLu求解:
CODE:
!!!using["IMSL","luopt","math"]; //使用命名空间
f(t,x1,x2,x3,x4,x5,x6,x7,dx1,dx2,dx3,dx4,dx5,dx6,dx7 : q : k1,k2,k3,k4,k5)=
{
  q = 8.75 + k5,
  dx1=  k5-q*x1- k1*x1*x2-k4*x1*x6*sqrt(0.9),
  dx2=  7.0-q*x2 - k1*x1*x2-2*k2*x2*x3,
  dx3=  1.75 -q*x3 - k2*x2*x3,
  dx4=  -q*x4 + 2*k1*x1*x2-k3*x4*x5,
  dx5=  -q*x5 + 3*k2*x2*x3-k3*x4*x5,
  dx6=  -q*x6 + 2*k3*x4*x5-k4*x1*x6*sqrt(0.9),
  dx7=  -q*x7 + 2*k4*x1*x6*sqrt(0.9)
};
目标函数(_k1,_k2,_k3,_k4,_k5 : i,s,tyz,tyy : tyArray,tA,k1,k2,k3,k4,k5)=
{
  k1=_k1, k2=_k2, k3=_k3, k4=_k4, k5=_k5,   //传递优化变量,函数f中要用到k1,k2,k3,k4,k5
  tyz=ode[@f,tA,ra1(0.1883,  0.2507,  0.0467,  0.0899,  0.1804,  0.1394,  0.1046)],
  tyy=tyArray(zeros), tyy(all:0,1)=subg(tyz,all:0,1), tyy(all:2,4)=subg(tyz,all:4,6),
  sum[(tyy-tyArray).^2.0,0]
};
main(::tyArray,tA)=
{
      tyArray=matrix{   //存放实验数据t,x1,x4,x5,x6
"
    0                0.1883        0.0899    0.1804          0.1394
    0.0100    0.2047    0.0866    0.1729    0.1297
    0.0200    0.2181    0.0856    0.1680    0.1205
    0.0300    0.2291    0.0863    0.1647    0.1123
    0.0400    0.2382    0.0878    0.1623    0.1053
    0.0500    0.2459    0.0899    0.1604    0.0995
    0.0600    0.2523    0.0921    0.1588    0.0948
    0.0700    0.2576    0.0945    0.1574    0.0911
    0.0800    0.2622    0.0968    0.1561    0.0882
    0.0900    0.2660    0.0989    0.1548    0.0859
    0.1000    0.2692    0.1010    0.1537    0.0842
    0.1100    0.2719    0.1028    0.1525    0.0830
    0.1200    0.2742    0.1045    0.1515    0.0821
    0.1300    0.2761    0.1060    0.1505    0.0814
    0.1400    0.2777    0.1074    0.1495    0.0810
    0.1500    0.2790    0.1086    0.1487    0.0807
    0.1600    0.2801    0.1096    0.1479    0.0805
    0.1700    0.2811    0.1106    0.1471    0.0803
    0.1800    0.2819    0.1114    0.1465    0.0803
    0.1900    0.2825    0.1121    0.1458    0.0803
    0.2000    0.2830    0.1127    0.1453    0.0803
"
    },
    tA=tyArray(all:0), //tA取矩阵的列
    ClearImslErr(),    //清空IMSL错误输出
    ERSET(0,0,0),      //关闭IMSL所有警告
    Opt[@目标函数],    //Opt函数全局优化
    ERSET(0,2,2), ERSET(0,1,0)   //恢复IMSL警告
};

结果(k1,k2,k3,k4,k5,目标函数值):
17.60849027475542         73.06467445464085         51.32551162517818         23.02494410245102         6.001239504989786         6.794401934343191e-008

优于原书matlab结果:
17.49,  72.2996,  50.9086,  22.5339,  5.9799, 3.614535245714516e-007

» 本帖已获得的红花(最新10朵)

2楼2016-10-03 21:21:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ronghengyidu

木虫 (小有名气)

送红花一朵
引用回帖:
2楼: Originally posted by lu_yu_lan at 2016-10-03 21:21:39
楼主的问题,没有看明白,找到了 黄华江编著的“实用化工计算机模拟”例题7-5拟合动力学参数

7个微分方程,5个拟合参数k1,k2,k3,k4,k5,初值t=0时,x为0.1883,  0.2507,  0.0467,  0.0899,  0.1804,  0.1394,  0 ...

非常感谢您的回复,我只有一个微分方程,dc1/dt=k1*c1/(k2++k3*c1+k4*c2+k5*c1*c2), 拟合5个参数k1,k2,k3,k4,k5。我的t,c1,c2数据在附件中,matlab程序也在附件中,这两个文件都可以用记事本打开。在这里我把程序和实验数据再贴出来。

function KineticsEst
% 动力学ODE方程模型的参数估计


clear all
clc

k0 = [0.5  0.5  0.5  0.5  0.5];         % 参数初值
lb = [0  0  0  0  0];                   % 参数下限
ub = [+inf  +inf  +inf  +inf  +inf];    % 参数上限
x0 = [150  1500];
KineticsData;
yexp = ExpData(:,2:3);                  % yexp: 实验数据[x1        x2]

% 使用函数fmincon()进行参数估计
[k,fval,flag] = fmincon(@ObjFunc4Fmincon,k0,[],[],[],[],lb,ub,[],[],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('\tk5 = %.4f\n',k(5))
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 = ExpData(:,1);
[t x] = ode45(@KineticEqs,tspan,x0,[],k);   
y(:,1:2) = x(:,1:2);
f = sum((y(:,1)-yexp(:,1)).^2) + sum((y(:,2)-yexp(:,2)).^2));

% ------------------------------------------------------------------
function f = ObjFunc4LNL(k,x0,yexp)
tspan = = ExpData(:,1);
[t x] = ode45(@KineticEqs,tspan,x0,[],k);   
y(:,1:2) = x(:,1:2);
f1 = y(:,1) - yexp(:,1);
f2 = y(:,2) - yexp(:,2);
f = [f1; f2];

% ------------------------------------------------------------------
function dxdt = KineticEqs(t,x,k)
dxdt =  ...
k(1)*x(1)./(k(2)+k(3)*x(1)+k(4)*x(2)+k(5)*x(1).*x(2));



实验数据如下:

动力学数据:
    t      c1         c2   
    0      150              1500          
    10    137.3    1487.3   
    30    107.7    1457.7   
    60    72.8     1422.8  
    90    48.8     1398.8   
    120   22.9     1372.9   
    150   11.8     1361.8   
    180   5.4      1355.4   
    220   1.9      1351.9  
    240   0.9      1350.9  


期望楼上能够指点,如果您能够给出openLU程序,我也非常感谢,因为我第一次听说这个程序,怕仿照编程又要出错。非常感谢您在节假日能够回答我的问题。
3楼2016-10-04 05:01:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lu_yu_lan

新虫 (初入文坛)

引用回帖:
3楼: Originally posted by ronghengyidu at 2016-10-04 05:01:01
非常感谢您的回复,我只有一个微分方程,dc1/dt=k1*c1/(k2++k3*c1+k4*c2+k5*c1*c2), 拟合5个参数k1,k2,k3,k4,k5。我的t,c1,c2数据在附件中,matlab程序也在附件中,这两个文件都可以用记事本打开。在这里我把程序 ...

是不是还有一个微分方程,dc2/dt=... ...。
否则应该怎样使用c2数据呢?

» 本帖已获得的红花(最新10朵)

4楼2016-10-04 08:37:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见