| 查看: 1340 | 回复: 0 | ||
| 【悬赏金币】回答本帖问题,作者757272131将赠送您 10 个金币 | ||
[求助]
使用matlab最小二乘法拟合求解常微分方程组未知参数
|
||
|
function k1k2k32 format long clear all clc tspan = [0 6 24 44 68 72 74 92 104 116]';%%这是时间 yexp= [3.111,3.639,3.887,4.289,4.658,5.531,6.218,6.979,7.111,7.114]';%%%这是菌落总数 x0 = [3.111]; k0 = [0.1 3 45 4 37 8.1]; lb = [0 0 0 0 0 0]; ub = [100 100 100 100 100 100]; % % % opts = statset('nlinfit'); % % opts.RobustWgtFun = 'bisquare'; % % mdll = fitnlm(tspan,yexp,ObjFunc,b0,'Options') % mdll = fitnlm(tspan,yexp,ObjFunc,b0,'Options',opts) options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective'); [k,resnorm,residual,exitflag,output,lambda,jacobian] = ... lsqnonlin(@ObjFunc,k0,lb,ub,[],tspan,x0,yexp); ci = nlparci(k,residual,jacobian); fprintf('\n\n使用函数lsqnonlin()估计得到的参数值为:\n') fprintf('\tk1 = %.9f ± %.9f\n',k(1),ci(1,2)-k(1)) fprintf('\tk2 = %.9f ± %.9f\n',k(2),ci(2,2)-k(2)) fprintf('\tk3 = %.9f ± %.9f\n',k(3),ci(3,2)-k(3)) fprintf('\tk4 = %.9f ± %.9f\n',k(4),ci(4,2)-k(4)) fprintf('\tk5 = %.9f ± %.9f\n',k(5),ci(5,2)-k(5)) fprintf('\tk6 = %.9f ± %.9f\n',k(6),ci(6,2)-k(6)) fprintf(' The sum of the squares is: %.9e\n\n',resnorm) tsa=0:0.01:max(tspan); [tsa ysa]=ode45(@KineticsEqs,tsa,x0,[],k); figure(1), plot(tsa,ysa(:,1),'b',tspan,yexp,'or'),legend('计算值','实验值','Location','best'); function f = ObjFunc(k,tspan,x0,yexp) % 目标函数 [tspan y] = ode45(@KineticsEqs,tspan,x0,[],k); f = (y-yexp); function dCdt = KineticsEqs(tspan ,C,k) T=4*(tspan >=0 & tspan <=30)+10*(tspan >31 & tspan <=90)+4*(tspan >90 ); % 假设这是我写的温度关于时间的分段函数 umax=((k(2)*(T-k(3))*(T-k(4))*(T-k(4)))/(((k(5)-k(4))*(T-k(5))-(k(5)-k(3))*(k(5)+k(4)-2*T))*(k(5)-k(4)))); dCdt=(1/(1+exp(-4*(tspan -k(1)))))*umax*(1-exp(C-k(6))); 这是根据他人的代码更改的,得到的结果是置信区间过大?想有什么办法解决?以及想用fitnlm函数进行拟合,达到一些参数评价t值p值等,但用fitnlm运行不起来。 @beefly |
» 猜你喜欢
【急招】合肥工大核聚变材料计算方向2026级工程博士生
已经有4人回复
大豆异黄酮分离
已经有0人回复
物理学I论文润色/翻译怎么收费?
已经有158人回复
湖南大学材料学院急招2026年博士生,临时增加一名博士联培指标
已经有10人回复
天津理工大学晶体材料全国重点实验室刘红军教授课题组招收博士生1-2名
已经有1人回复
中国科学院物理研究所谌志国研究员团队招收2027年博士研究生
已经有4人回复
2026年中德博士后交流项目 - 新型量子和磁性材料:材料制备表征和中子散射研究
已经有12人回复
26申博推荐:南京航空航天大学国际前沿院光学方向招收博士生!
已经有1人回复











回复此楼