24小时热门版块排行榜    

查看: 3568  |  回复: 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

金虫 (小有名气)

你好,你可以把修改后的程序发给我看一下吗?
3楼2017-02-19 15:44:27
已阅   回复此楼   关注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

金虫 (小有名气)

引用回帖:
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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 333求调剂 +5 87639 2026-03-21 7/350 2026-03-21 19:31 by ColorlessPI
[考研] 26考研一志愿中国石油大学(华东)305分求调剂 +6 嘉年新程 2026-03-15 6/300 2026-03-21 17:07 by Dream007008
[考研] 266求调剂 +3 哇呼哼呼哼 2026-03-20 3/150 2026-03-21 16:46 by barlinike
[考研] 286分人工智能专业请求调剂愿意跨考! +4 lemonzzn 2026-03-17 7/350 2026-03-21 16:09 by lemonzzn
[考研] 22 350 本科985求调剂,求老登收留 +3 李轶男003 2026-03-20 3/150 2026-03-21 13:28 by 搏击518
[考研] 一志愿天津大学化学工艺专业(081702)315分求调剂 +12 yangfz 2026-03-17 12/600 2026-03-21 03:30 by JourneyLucky
[考研] 一志愿华中科技大学,080502,354分求调剂 +5 守候夕阳CF 2026-03-18 5/250 2026-03-21 01:06 by JourneyLucky
[考研] 一志愿南昌大学,327分,材料与化工085600 +9 Ncdx123456 2026-03-19 9/450 2026-03-20 23:41 by lovewei0727
[考研] 考研调剂求学校推荐 +3 伯乐29 2026-03-18 5/250 2026-03-20 22:59 by JourneyLucky
[考研] 北科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 丁丁*
[考研] 环境工程调剂 +9 大可digkids 2026-03-16 9/450 2026-03-20 17:38 by 醉在风里
[考研] 085600材料与化工调剂 324分 +10 llllkkkhh 2026-03-18 12/600 2026-03-19 14:33 by llllkkkhh
[考研] 材料考研调剂 +3 xwt。 2026-03-19 3/150 2026-03-19 11:22 by w沐阳w
[考研] 【同济软件】软件(085405)考研求调剂 +3 2026eternal 2026-03-18 3/150 2026-03-18 19:09 by 搏击518
[考研] 301求调剂 +4 A_JiXing 2026-03-16 4/200 2026-03-17 17:32 by ruiyingmiao
[考研] 326求调剂 +5 上岸的小葡 2026-03-15 6/300 2026-03-17 17:26 by ruiyingmiao
[考研] 材料专硕326求调剂 +6 墨煜姒莘 2026-03-15 7/350 2026-03-17 17:10 by ruiyingmiao
[考研] 一志愿南京大学,080500材料科学与工程,调剂 +4 Jy? 2026-03-16 4/200 2026-03-17 11:02 by gaoqiong
[考研] 机械专硕325,寻找调剂院校 +3 y9999 2026-03-15 5/250 2026-03-16 19:58 by y9999
信息提示
请填处理意见