24小时热门版块排行榜    

查看: 3571  |  回复: 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的回帖

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的回帖
查看全部 6 个回答

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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 求调剂院校信息 +3 CX 330 2026-03-21 3/150 2026-03-21 22:35 by bingxueer79
[考研] 材料求调剂 +5 @taotao 2026-03-21 5/250 2026-03-21 20:55 by lbsjt
[考研] 333求调剂 +5 87639 2026-03-21 7/350 2026-03-21 19:31 by ColorlessPI
[考研] 0703化学调剂 +11 妮妮ninicgb 2026-03-15 15/750 2026-03-21 19:15 by ColorlessPI
[考研] 0703化学调剂 ,六级已过,有科研经历 +14 曦熙兮 2026-03-15 14/700 2026-03-21 19:12 by ColorlessPI
[考研] 本人考085602 化学工程 专硕 +20 不知道叫什么! 2026-03-15 22/1100 2026-03-21 19:03 by ColorlessPI
[考研] 26考研一志愿中国石油大学(华东)305分求调剂 +6 嘉年新程 2026-03-15 6/300 2026-03-21 17:07 by Dream007008
[考研] 0805材料320求调剂 +3 深海物语 2026-03-20 3/150 2026-03-21 15:46 by 无际的草原
[考研] 279分求调剂 一志愿211 +14 chaojifeixia 2026-03-19 15/750 2026-03-21 13:24 by zhukairuo
[考研] 08工科 320总分 求调剂 +6 梨花珞晚风 2026-03-17 6/300 2026-03-21 03:40 by JourneyLucky
[考研] 二本跨考郑大材料306英一数二 +3 z1z2z3879 2026-03-17 3/150 2026-03-21 02:29 by JourneyLucky
[考研] 295求调剂 +4 一志愿京区211 2026-03-18 6/300 2026-03-20 23:41 by JourneyLucky
[考研] 一志愿武汉理工材料工程专硕调剂 +9 Doleres 2026-03-19 9/450 2026-03-20 22:36 by JourneyLucky
[考研] 350求调剂 +5 weudhdk 2026-03-19 5/250 2026-03-20 22:04 by luoyongfeng
[考研] 261求B区调剂,科研经历丰富 +3 牛奶很忙 2026-03-20 4/200 2026-03-20 19:34 by JourneyLucky
[考研] 0703化学调剂 +4 18889395102 2026-03-18 4/200 2026-03-19 16:13 by 30660438
[考研] 328求调剂,英语六级551,有科研经历 +4 生物工程调剂 2026-03-16 12/600 2026-03-19 11:10 by 生物工程调剂
[考研] 277调剂 +5 自由煎饼果子 2026-03-16 6/300 2026-03-17 19:26 by 李leezz
[硕博家园] 湖北工业大学 生命科学与健康学院-课题组招收2026级食品/生物方向硕士 +3 1喜春8 2026-03-17 5/250 2026-03-17 17:18 by ber川cool子
[考研] 333求调剂 +3 文思客 2026-03-16 7/350 2026-03-16 18:21 by 文思客
信息提示
请填处理意见