| 查看: 1577 | 回复: 1 | ||
_romantic_镇木虫 (著名写手)
|
[求助]
初学者求助,matlab模仿程序 已有1人参与
|
|
function KineticsEst5 % 动力学ODE方程模型的参数估计 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)) ]; |
» 猜你喜欢
【复旦大学】二维材料方向招收2026年博士研究生1名
已经有0人回复
北京纳米能源与系统研究所 王中林院士/曹南颖研究员课题组2026级硕/博/博后招生
已经有10人回复
物理学I论文润色/翻译怎么收费?
已经有235人回复
荷兰Utrecht University超快太赫兹光谱王海教授课题招收2026 CSC博士生
已经有23人回复
反铁磁体中的磁性切换:两种不同的机制已成功可视化
已经有0人回复
求标准粉末衍射卡号 ICDD 01-076-1802
已经有0人回复
新西兰Robinson研究所招收全奖PhD
已经有0人回复
石墨烯转移--二氧化硅衬底石墨烯
已经有0人回复
hzlhm
至尊木虫 (著名写手)
- 应助: 387 (硕士)
- 金币: 18111.5
- 红花: 53
- 帖子: 2879
- 在线: 603.7小时
- 虫号: 1517335
- 注册: 2011-11-30
- 性别: GG
- 专业: 常微分方程与动力系统
【答案】应助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
_romantic_镇: 金币+50, ★有帮助 2022-03-15 11:07:58
_romantic_镇: 金币+50, ★有帮助 2022-03-15 11:07:58
|
程序中的问题: 1、tspan = [0.00 : 0.01 : 0.44]与tspan=[0 0.222 0.333 0.444]没有对应 2、f = sum((y(:,1)-yexp(:,1)).^2) + sum((y(:,2)-yexp(:,2)).^2) + sum((y(:,3)-yexp(:,3)).^2) 后面的代码是多余的,计算的结果不使用 执行结果: 使用函数fmincon()估计得到的参数值为: k1 = -0.6403 k2 = 1.8125 k3 = 3.6968 k4 = 1.9950 The sum of the squares is: 4.0 |

2楼2021-12-27 22:26:21













回复此楼