| 查看: 1746 | 回复: 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)) ]; |
» 猜你喜欢
26申博推荐:南京航空航天大学国际前沿院光学方向招收博士生!
已经有1人回复
如何从铁电相到顺电相。
已经有1人回复
物理学I论文润色/翻译怎么收费?
已经有181人回复
各位大佬,求一份最新Wien2k版本作为学习用途
已经有0人回复
南科大活性流体和软物质课题组诚招2027级博士、硕士研究生和博后
已经有33人回复
瑞典林雪平大学博士后招聘|PEC Water Splitting 方向
已经有24人回复
PRB投稿,Acknowledgment sent to author状态十天了
已经有3人回复
PVA溶解
已经有1人回复
基金申请
已经有40人回复
【答案】应助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
_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











回复此楼