24小时热门版块排行榜    

查看: 3570  |  回复: 5

hustwzh

金虫 (小有名气)

[求助] 求大神帮忙解决一下,用MATLAB求解动力学数据总是出错~ 已有1人参与

如题,本人是个Matlab方面的小白,临时要用到,但自己纠结了好久还是没弄会,只好来向诸位大师求助了,代码及问题如下,多谢了
CODE:
function KineticsEst5 % 动力学ODE方程模型的参数估计
%
%
%
% The variables y here are y(1)=xB, y(2)=xoNB, y(3)=xmNB,y(4)=xpNB,y(5)=xDNB .
clear all
clc
k0 = [5 5 5 5 5]; % 参数初值
lb = [0 0 0 0 0]; % 参数下限
ub = [+inf +inf +inf +inf +inf]; % 参数上限
x0 = [0 0 0 0 0 0];
KineticsData;
yexp = ExpData(:,2:6); % yexp: 实验数据[x1 x4 x5 x6]
% 使用函数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('\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 = [0.00 : 5.03 : 15.09];
[t x] = ode45(@KineticEqs,tspan,x0,[],k);
y(:,1) = x(:,1);
y(:,2:4) = x(:,4:6);
f = sum((y(:,1)-yexp(:,1)).^2) + sum((y(:,2)-yexp(:,2)).^2) ...
     + sum((y(:,3)-yexp(:,3)).^2) + sum((y(:,4)-yexp(:,4)).^2);
% ------------------------------------------------------------------
function f = ObjFunc4LNL(k,x0,yexp)
tspan = [0.00 : 5.03 : 15.09];
[t x] = ode45(@KineticEqs,tspan,x0,[],k);
y(:,1) = x(:,1);
y(:,2:4) = x(:,4:6);
f1 = y(:,1) - yexp(:,1);
f2 = y(:,2) - yexp(:,2);
f3 = y(:,3) - yexp(:,3);
f4 = y(:,4) - yexp(:,4);
f = [f1; f2; f3; f4];
% ------------------------------------------------------------------
function dxdt = KineticEqs(t,x,k)
M=1.003;
dxdt = ...
   [ ( (k(1)+k(2)+k(3))*(1-x(1))*M*(1-x(2)-x(3)-x(4)-2*x(5)) )
     ( M*(1-x(2)-x(3)-x(4)-2*x(5))*(k(1)*(1-x(1))-k(4)*x(2)) )
     ( k(2)*(1-x(1))*M*(1-x(2)-x(3)-x(4)-2*x(5)) )
     ( M*(1-x(2)-x(3)-x(4)-2*x(5))*(k(3)*(1-x(1))-k(5)*x(4)) )
     ( M*(1-x(2)-x(3)-x(4)-2*x(5))*(k(4)*x(2)+k(5)*x(4)) )
];

错误使用 odearguments (line 92)
KINETICEQS 返回的矢量的长度为 5,但初始条件矢量的长度为 6。KINETICEQS 返回的矢量和初始条件矢量的元素数目必须相同。

出错 ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

出错 KineticsEst>ObjFunc4Fmincon (line 48)
[t x] = ode45(@KineticEqs,tspan,x0,[],k);

出错 fmincon (line 564)
      initVals.f = feval(funfcn{3},X,varargin{:});

出错 KineticsEst (line 19)
[k,fval,flag] = fmincon(@ObjFunc4Fmincon,k0,[],[],[],[],lb,ub,[],[],x0,yexp);

原因:
    Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : KineticsData.m
  • 2017-02-18 14:07:42, 498 bytes

» 猜你喜欢

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

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

chendequan

铁虫 (小有名气)

【答案】应助回帖

感谢参与,应助指数 +1
>> KineticsEst5

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current step is less than
the default value of the step size tolerance and constraints are
satisfied to within the default value of the constraint tolerance.

<stopping criteria details>


使用函数fmincon()估计得到的参数值为:
        k1 = 0.0358
        k2 = 0.0021
        k3 = 5.6484
        k4 = 22.7533
        k5 = 14.7665
The sum of the squares is: 1.5e+00


Local minimum possible.

lsqnonlin stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.

<stopping criteria details>



使用函数lsqnonlin()估计得到的参数值为:
        k1 = 0.8360
        k2 = 0.0128
        k3 = 3.0166
        k4 = 38.9765
        k5 = 7.6220

Local minimum possible.

lsqnonlin stopped because the size of the current step is less than
the default value of the step size tolerance.

<stopping criteria details>



以fmincon()的结果为初值,使用函数lsqnonlin()估计得到的参数值为:
        k1 = 0.0358
        k2 = 0.0021
        k3 = 5.6484
        k4 = 22.7533
        k5 = 14.7665
QQ:516477448,真心帮助解决MATLAB相关问题,提供详细资料,Word文档明确具体问题及要求,尽力而为!
2楼2017-02-19 10:02:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hustwzh

金虫 (小有名气)

你好,你可以把修改后的程序发给我看一下吗?
3楼2017-02-19 15:44:27
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hustwzh

金虫 (小有名气)

引用回帖:
2楼: Originally posted by chendequan at 2017-02-19 10:02:37
>> KineticsEst5

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current step is less than
the default value of the step size tolerance and constrai ...

你好,你可以把修改后的程序发给我看一下吗?
4楼2017-02-19 15:45:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

hustwzh

金虫 (小有名气)

引用回帖:
2楼: Originally posted by chendequan at 2017-02-19 10:02:37
>> KineticsEst5

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current step is less than
the default value of the step size tolerance and constrai ...

你好,你可以把修改后的程序发给我看一下吗?
5楼2017-02-19 15:45:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

chendequan

铁虫 (小有名气)

【答案】应助回帖

内容已删除
QQ:516477448,真心帮助解决MATLAB相关问题,提供详细资料,Word文档明确具体问题及要求,尽力而为!
6楼2017-02-19 19:55:58
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 hustwzh 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 326求调剂 +4 mlpqaz03 2026-03-15 4/200 2026-03-21 19:10 by ColorlessPI
[考研] 278求调剂 +9 烟火先于春 2026-03-17 9/450 2026-03-21 17:47 by 学员8dgXkO
[考研] 268求调剂 +9 简单点0 2026-03-17 9/450 2026-03-21 15:37 by lature00
[考研] 化学求调剂 +4 临泽境llllll 2026-03-17 5/250 2026-03-21 02:23 by JourneyLucky
[考研] 材料 336 求调剂 +3 An@. 2026-03-18 4/200 2026-03-21 01:39 by JourneyLucky
[考研] 一志愿南京理工大学085701资源与环境302分求调剂 +4 葵梓卫队 2026-03-18 6/300 2026-03-20 23:02 by JourneyLucky
[考研] 317求调剂 +5 申子申申 2026-03-19 9/450 2026-03-20 22:26 by JourneyLucky
[考研] 药学383 求调剂 +3 药学chy 2026-03-15 5/250 2026-03-20 22:11 by 云游重阳
[考研] 一志愿苏州大学材料求调剂,总分315(英一) +5 sbdksD 2026-03-19 5/250 2026-03-20 22:10 by luoyongfeng
[考研] 350求调剂 +5 weudhdk 2026-03-19 5/250 2026-03-20 22:04 by luoyongfeng
[考研] 北科281学硕材料求调剂 +5 tcxiaoxx 2026-03-20 5/250 2026-03-20 21:35 by laoshidan
[考研] 一志愿吉林大学材料学硕321求调剂 +11 Ymlll 2026-03-18 15/750 2026-03-20 19:40 by 丁丁*
[考研] 一志愿中国海洋大学,生物学,301分,求调剂 +5 1孙悟空 2026-03-17 6/300 2026-03-19 23:46 by zcl123
[考研] 288求调剂,一志愿华南理工大学071005 +5 ioodiiij 2026-03-17 5/250 2026-03-19 18:22 by zcl123
[考研] 085601材料工程专硕求调剂 +10 慕寒mio 2026-03-16 10/500 2026-03-19 15:26 by 丁丁*
[考研] 344求调剂 +6 knight344 2026-03-16 7/350 2026-03-18 20:13 by walc
[考研] 一志愿苏州大学材料工程(085601)专硕有科研经历三项国奖两个实用型专利一项省级立项 +6 大火山小火山 2026-03-16 8/400 2026-03-17 15:05 by 无懈可击111
[考研] 283求调剂 +3 听风就是雨; 2026-03-16 3/150 2026-03-17 07:41 by 热情沙漠
[考研] 一志愿211 0703方向310分求调剂 +3 努力奋斗112 2026-03-15 3/150 2026-03-16 16:44 by houyaoxu
[考研] 070300化学学硕求调剂 +6 太想进步了0608 2026-03-16 6/300 2026-03-16 16:13 by kykm678
信息提示
请填处理意见