24小时热门版块排行榜    

Znn3bq.jpeg
查看: 3593  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 急需调剂 +5 绝不放弃22 2026-04-15 5/250 2026-04-15 23:11 by Tide man
[考研] 322求调剂 +7 123安康 2026-04-12 14/700 2026-04-15 21:48 by noqvsozv
[考研] 本科211,报考085601-310分 +16 ararak 2026-04-13 16/800 2026-04-14 14:55 by Delta2012
[考研] 求调剂 +16 雪逢冬 2026-04-10 16/800 2026-04-14 14:27 by 逆水乘风
[考研] 考研求调剂 +12 子木呐 2026-04-12 13/650 2026-04-14 01:19 by 王珺璞
[考研] 考研英一数一338分 +9 长江大学东校区 2026-04-13 10/500 2026-04-14 00:41 by 王珺璞
[考研] B区0809 ,数一英一,290 求调剂 +3 泠潍1111 2026-04-12 4/200 2026-04-13 20:35 by 学员JpLReM
[考研] 302求调剂 +10 易!? 2026-04-13 10/500 2026-04-13 19:04 by lbsjt
[考研] 一志愿鲁东大学071000生物学学硕初试分数276求调剂 +8 慕绝cc 2026-04-09 8/400 2026-04-13 14:08 by 张zhihao
[考研] 考研二轮调剂 +10 故人?? 2026-04-09 10/500 2026-04-13 09:55 by szhize
[教师之家] 山东双非院校考核超级无底线,领导幸灾乐祸,教师遭殃恐 +3 qut2026 2026-04-11 7/350 2026-04-12 20:24 by qut2026
[硕博家园] 新一代电子信息294求调剂 不挑学校 +7 Ytyt11 2026-04-09 8/400 2026-04-12 16:57 by ajpv风雷
[考研] 电气专硕320求调剂 +6 小麻子111 2026-04-10 6/300 2026-04-12 10:54 by lemon6009
[考研] 0854调剂 +12 长弓傲 2026-04-09 13/650 2026-04-12 09:56 by 逆水乘风
[考研] 22408调剂315分 +3 zhuangyan123 2026-04-09 3/150 2026-04-12 00:25 by 蓝云思雨
[考研] 343求调剂 +9 王国帅 2026-04-10 9/450 2026-04-11 20:31 by dongdian1
[考研] 085501机械专硕 302分 不挑专业求调剂 +7 汪某. 2026-04-09 7/350 2026-04-11 14:37 by luhong1990
[考研] 083200 305分 求二轮调剂 不接受跨专业 +9 Claireyyyy 2026-04-09 10/500 2026-04-10 21:21 by Claireyyyy
[考研] 284求调剂 +9 让我上岸吧阿西 2026-04-09 11/550 2026-04-10 19:18 by 靖jing
[考研] 求调剂 材料与工程 324分 专硕 +19 翩翩一书生 2026-04-10 21/1050 2026-04-10 11:41 by wp06
信息提示
请填处理意见