| 查看: 1301 | 回复: 4 | |||
| 当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖 | |||
zhiping780木虫 (著名写手)
天鹰帮帮主
|
[求助]
matlab程序运行出错,求指点修改
|
||
|
我仿写了一个Matlab的化学反应动力学计算程序,可是运行时有问题,那位大侠帮忙指导下,谢谢 function fourlump clear all clc global theta yexp V21 V23 V24 A xx0 M MH x0 k0 = [1.0 5.0 0.5]; % 参数初值 lb = [0 0 0]; % 参数下限 ub = [+inf +inf +inf]; % 参数上限 xx0=[31.423 42.861 6.403 19.315]; M=[93.99229 83.27657 102.8053 116.2428]; NH=[0.2271 0.2271 0.2271 0.0852 0.0852 0.0852 0.1135 0.1135 .1419 0.1419 0.1419 0.1419 0.1703 0.1703 0.1703]; tspan=[0 1]; ExpData= ... [1 0.002553 0.002189 0.000629 0.001467 2 0.003354 0.000745 0.000684 0.001973 3 0.002758 0.002128 0.000585 0.001336 4 0.003226 0.003156 0.000672 0.001585 5 0.003495 0.002759 0.000707 0.001658 6 0.003105 0.002974 0.000678 0.001677 7 0.003571 0.001938 0.000791 0.001780 8 0.003073 0.002763 0.000675 0.001594 9 0.002857 0.002761 0.000630 0.001569 10 0.003621 0.001888 0.000679 0.001637 11 0.003228 0.002415 0.000629 0.001522 12 0.003121 0.001553 0.000734 0.001877 13 0.002850 0.002348 0.000636 0.001601 14 0.003406 0.001851 0.000648 0.001570 15 0.003142 0.001809 0.000677 0.001687]; yexp=ExpData(:,2:5); tspan=[0 1]; V21=[0.8837 1.0897 0.9285 0.8446 0.9119 0.8925 0.9612 0.8992 0.8601 0.9473 0.9115 0.9747 0.8795 0.9365 0.9162]'; V23=[0.8853 0.9914 0.8874 0.8228 0.8501 0.8609 0.9220 0.8669 0.8354 0.8654 0.8592 0.9637 0.8455 0.8638 0.9014]'; V24=[0.7570 0.8668 0.7843 0.7332 0.7551 0.7666 0.7936 0.7678 0.7411 0.7644 0.7638 0.8576 0.7503 0.7658 0.8033]'; theta=[166.8411 250.2616 286.0133 155.4816 248.7706 266.5399 169.4721 593.1523 80.9890 377.9487 566.9230 566.9229 180.9717 361.9435 434.3321]; A=[0.1562 0.1562 0.1562 0.0728 0.0728 0.0728 0.0925 0.0925 0.1106 0.1106 0.1106 0.1106 0.1270 0.1270 0.1270]'; yexp=ExpData(:,2:5); [k,resnorm,residual,exitflag,output,lambda,jacobian] = ... lsqnonlin(@ObjFunclump,k0,lb,ub,[],tspan,xx0,x0,theta,V21,V23,V24,yexp) ci = nlparci(k,resid,jacobian) function f = ObjFunclump(k,tspan,x0,theta,V21,V23,V24,A,yexp) for i=1:length(theta) x0(1)=xx0(1)/((1+2*NH(i))*M(1)); x0(2)=xx0(2)/((1+2*NH(i))*M(2)); x0(3)=xx0(3)/((1+2*NH(i))*M(3)); x0(4)=xx0(4)/((1+2*NH(i))*M(4)); [t x] = ode45(@FCClump,tspan,x0,[],k,theta(i),V21(i),V23(i),V24(i),A(i)); y(i,1) = x(end,1); y(i,2:4) = x(end,2:4); end 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=FCClump(t,x,k,theta,V21,V23,V24,A) dxdt = ... [ theta*k(1)*V21*x(2)/(x(1)+x(2)+x(3)+x(4)+A) -1*theta*(k(1)+k(2)+k(3))*x(2)/(x(1)+x(2)+x(3)+x(4)+A) theta*k(2)*V23*x(2)/(x(1)+x(2)+x(3)+x(4)+A) theta*k(3)*V24*x(2)/(x(1)+x(2)+x(3)+x(4)+A) ]; 运行后: ??? Error using ==> optim\private\lsqncommon User supplied function failed with the following error: Undefined function or variable "y". Error in ==> lsqnonlin at 147 [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ... Error in ==> fourlump360 at 39 [k,resnorm,residual,exitflag,output,lambda,jacobian] = ... |
» 猜你喜欢
上海工程技术大学【激光智能制造】课题组招收硕士
已经有6人回复
带资进组求博导收留
已经有11人回复
自荐读博
已经有5人回复
求个博导看看
已经有16人回复
上海工程技术大学张培磊教授团队招收博士生
已经有4人回复
求助院士们,这个如何合成呀
已经有4人回复
临港实验室与上科大联培博士招生1名
已经有9人回复
写了一篇“相变储能技术在冷库中应用”的论文,论文内容以实验为主,投什么期刊合适?
已经有6人回复
最近几年招的学生写论文不引自己组发的文章
已经有11人回复
中科院杭州医学所招收博士生一名(生物分析化学、药物递送)
已经有3人回复
» 本主题相关价值贴推荐,对您同样有帮助:
关于Matlab中for循环的问题,求达人指点,谢谢了
已经有7人回复
用Matlab求一个二阶微分方程,出错了,求指导(求助)
已经有13人回复
高手指点:如何使用matlab使数据行与行间空一行
已经有6人回复
求高手指点 :如何使用matlab 在数据间产生空格?
已经有9人回复
matlab 运行ode45出错,不知道什么原因
已经有4人回复
matlab求函数积分出错
已经有12人回复
matlab一运行就出现的问题
已经有7人回复
请大侠指教matlab的这个错误提示到底是个神马意思?
已经有12人回复
有个matlab程序,但是运行不下来,求高手
已经有23人回复
关于matlab进行傅里叶变换和逆变换的程序,求大神指导!
已经有9人回复
运行matlab出现错误
已经有4人回复
matlab的m文件关联问题
已经有17人回复
大家爱帮我看看这段MATLAB程序为啥出错了
已经有5人回复
MATLAB运行错误
已经有5人回复
matlab程序问题,总是出错,麻烦大家看看问题在那里?
已经有6人回复
MATLAB初学者,这样的式子怎么就是画不了图,总是出错!求指导!!!!!!!!!!!!!
已经有8人回复
求助matlab-simulink运行时报错问题
已经有3人回复
同样的MATLAB程序,为何在别人的电脑上运行不了
已经有21人回复
【求助】用matlab编程,需要将数据自检分类(高手进来指点下)
已经有5人回复

zhiping780
木虫 (著名写手)
天鹰帮帮主
- 应助: 0 (幼儿园)
- 贵宾: 0.007
- 金币: 1584.7
- 散金: 20
- 沙发: 2
- 帖子: 1396
- 在线: 9.7小时
- 虫号: 589991
- 注册: 2008-08-30
- 性别: GG
- 专业: 工业催化
|
运行后: Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be global before you use that variable. > In fourlump>ObjFunclump at 45 In sfdnls at 90 In optim\private\snls at 404 In optim\private\lsqncommon at 213 In lsqnonlin at 147 In fourlump at 39 。。。。。。反复出现。。。。。 出结果后:Optimization terminated: relative function value changing by less than OPTIONS.TolFun. k = 0.0000 5.8729 4.9600 resnorm = 2.9233 residual = 0.2273 0.2265 0.2271 0.2824 0.2821 0.2825 0.2689 0.2694 0.2576 0.2568 0.2572 0.2573 0.2465 0.2460 0.2462 -0.0022 -0.0007 -0.0021 -0.0032 -0.0028 -0.0030 -0.0019 -0.0028 -0.0028 -0.0019 -0.0024 -0.0016 -0.0023 -0.0019 -0.0018 0.2121 0.2324 0.2125 0.2487 0.2552 0.2578 0.2596 0.2472 0.2295 0.2359 0.2346 0.2572 0.2218 0.2256 0.2334 0.2355 0.2528 0.2400 0.2880 0.2923 0.2946 0.2861 0.2813 0.2639 0.2681 0.2681 0.2850 0.2542 0.2570 0.2635 exitflag = 3 output = firstorderopt: 3.9262e-004 iterations: 12 funcCount: 52 cgiterations: 6 algorithm: 'large-scale: trust-region reflective Newton' message: [1x87 char] lambda = lower: [3x1 double] upper: [3x1 double] jacobian = (1,1) 0.0289 (2,1) 0.0356 (3,1) 0.0303 (4,1) 0.0343 (5,1) 0.0370 (6,1) 0.0362 (7,1) 0.0372 (8,1) 0.0348 (9,1) 0.0318 (10,1) 0.0351 (11,1) 0.0337 (12,1) 0.0361 (13,1) 0.0312 (14,1) 0.0332 (15,1) 0.0325 (16,1) 0.0001 (17,1) -0.0000 (18,1) -0.0000 (19,1) -0.0000 (20,1) -0.0000 (21,1) -0.0000 (22,1) -0.0001 (23,1) 0.0002 (24,1) -0.0000 (25,1) 0.0004 (26,1) -0.0002 (27,1) 0.0011 (28,1) -0.0000 (29,1) -0.0002 (30,1) 0.0000 (31,1) -0.0157 (32,1) -0.0176 (33,1) -0.0157 (34,1) -0.0181 (35,1) -0.0187 (36,1) -0.0189 (37,1) -0.0193 (38,1) -0.0183 (39,1) -0.0168 (40,1) -0.0175 (41,1) -0.0171 (42,1) -0.0199 (43,1) -0.0162 (44,1) -0.0165 (45,1) -0.0173 (46,1) -0.0114 (47,1) -0.0130 (48,1) -0.0117 (49,1) -0.0136 (50,1) -0.0140 (51,1) -0.0142 (52,1) -0.0140 (53,1) -0.0137 (54,1) -0.0126 (55,1) -0.0131 (56,1) -0.0129 (57,1) -0.0149 (58,1) -0.0122 (59,1) -0.0124 (60,1) -0.0130 (1,2) -0.0000 (2,2) -0.0000 (3,2) -0.0000 (4,2) -0.0000 (5,2) -0.0000 (6,2) -0.0000 (7,2) -0.0000 (8,2) -0.0000 (9,2) -0.0000 (10,2) -0.0000 (11,2) -0.0000 (12,2) -0.0000 (13,2) -0.0000 (14,2) -0.0000 (15,2) -0.0000 (16,2) 0.0001 (17,2) -0.0000 (18,2) -0.0000 (19,2) -0.0000 (20,2) -0.0000 (21,2) -0.0000 (22,2) -0.0001 (23,2) 0.0002 (24,2) -0.0000 (25,2) 0.0004 (26,2) -0.0002 (27,2) 0.0011 (28,2) -0.0000 (29,2) -0.0002 (30,2) 0.0000 (31,2) 0.0132 (32,2) 0.0148 (33,2) 0.0133 (34,2) 0.0153 (35,2) 0.0158 (36,2) 0.0160 (37,2) 0.0164 (38,2) 0.0153 (39,2) 0.0142 (40,2) 0.0145 (41,2) 0.0147 (42,2) 0.0158 (43,2) 0.0137 (44,2) 0.0141 (45,2) 0.0146 (46,2) -0.0114 (47,2) -0.0130 (48,2) -0.0117 (49,2) -0.0136 (50,2) -0.0140 (51,2) -0.0142 (52,2) -0.0140 (53,2) -0.0137 (54,2) -0.0126 (55,2) -0.0131 (56,2) -0.0129 (57,2) -0.0150 (58,2) -0.0122 (59,2) -0.0124 (60,2) -0.0130 (1,3) -0.0000 (2,3) -0.0000 (3,3) -0.0000 (4,3) -0.0000 (5,3) -0.0000 (6,3) -0.0000 (7,3) -0.0000 (8,3) -0.0000 (9,3) -0.0000 (10,3) -0.0000 (11,3) -0.0000 (12,3) -0.0000 (13,3) -0.0000 (14,3) -0.0000 (15,3) -0.0000 (16,3) 0.0001 (17,3) -0.0000 (18,3) -0.0000 (19,3) -0.0000 (20,3) -0.0000 (21,3) -0.0000 (22,3) -0.0001 (23,3) 0.0002 (24,3) -0.0000 (25,3) 0.0004 (26,3) -0.0002 (27,3) 0.0011 (28,3) -0.0000 (29,3) -0.0002 (30,3) 0.0000 (31,3) -0.0158 (32,3) -0.0176 (33,3) -0.0157 (34,3) -0.0181 (35,3) -0.0187 (36,3) -0.0189 (37,3) -0.0193 (38,3) -0.0183 (39,3) -0.0168 (40,3) -0.0175 (41,3) -0.0171 (42,3) -0.0199 (43,3) -0.0162 (44,3) -0.0165 (45,3) -0.0173 (46,3) 0.0134 (47,3) 0.0154 (48,3) 0.0139 (49,3) 0.0161 (50,3) 0.0166 (51,3) 0.0169 (52,3) 0.0167 (53,3) 0.0160 (54,3) 0.0149 (55,3) 0.0152 (56,3) 0.0154 (57,3) 0.0168 (58,3) 0.0144 (59,3) 0.0148 (60,3) 0.0154 Usage: RESID(DATA,MODEL) E = RESID(DATA,MODEL,No_OF_LAGS,MAXSIZE) ??? One or more output arguments not assigned during call to 'C:\MATLAB701\toolbox\ident\idobsolete\resid.m (resid)'. Error in ==> fourlump at 41 ci = nlparci(k,resid,jacobian) |

5楼2012-03-17 12:12:13

2楼2012-03-16 17:00:13
|
按你说的,运行后出现新的问题 Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be global before you use that variable. > In fourlump>ObjFunclump at 45 In optim\private\lsqncommon at 88 In lsqnonlin at 147 In fourlump at 39 Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be global before you use that variable. > In fourlump>ObjFunclump at 45 In optim\private\lsqncommon at 88 In lsqnonlin at 147 In fourlump at 39 ??? Error using ==> optim\private\lsqncommon User supplied function failed with the following error: Undefined command/function 'xx0'. Error in ==> lsqnonlin at 147 [x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ... Error in ==> fourlump at 39 [k,resnorm,residual,exitflag,output,lambda,jacobian] = ... |
3楼2012-03-16 18:17:06
【答案】应助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ...
zhiping780: 金币+100, 谢谢,你能说明或者帮忙修改一下如何用参数方式传递数据么?我对这些一窍不通 2012-03-17 12:05:35
zhiping780: 金币+100, 谢谢,你能说明或者帮忙修改一下如何用参数方式传递数据么?我对这些一窍不通 2012-03-17 12:05:35
|
目的函数ObjFunclump中少了个xx0,加上就没错误。 global theta yexp M NH xx0 x0 至于警告,看英文应该能明白意思。 尽量不采用全局变量,建议用参数方式传递数据。 |

4楼2012-03-16 20:35:46







回复此楼