声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2182|回复: 2

[编程技巧] Missing operator, comma, or semicolon 出错求助

[复制链接]
发表于 2007-11-25 04:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
看了所有关于Missing operator, comma, or semicolon
的帖子。。还是不会修改自己的帖子啊。。高手帮帮忙啊。
老是出现Missing operator, comma, or semicolon.

那个大虾帮下啊。。

function f=zong(x)     %主程序
global t
t=1:4;
global i
i=1:2;
L=[100,130,170,140]
global X=x(i,t)
global U=u(i,t)
u(i,t)=any(x(i,t));
A=[0,-0.6667;
    0,0.667;
    0,-0.3333;
    0,0.3333;
    0,0.3333;
    0,-0.3333;
    1,0;
    0,1];
b=[-0.3333L(t)+200;0.3333L(t)+200;-0.6667L(t)+100;0.6667L(t)+100;-0.3333L(t)+200;
0.3333L(t)+200;200;100];
lb=zeros(2,1);
ub=[300,300];
Aeq=x(1,t)+x(2,t)-L(t);
beq=0;
for t=1:4
[x,fval,exitflag,output,lambda]=fmincon(@fun,[],A,b(t),Aeq,beq,lb,ub,@mycon1)
end
function f=cheng(x(i,t))             %空载成本和增量成本                                                                                                                                                                                                                                                                                                                                                                   function f=x(i,t)
if (0<x(1,t))&(x(1,t)<100)
f=10*x(1,t)+100;
if (100<x(1,t))&(x(1,t)<200)
f=14*x(1,t)-300;
end
end
if (0<x(2,t))&(x(2,t)<60)
f=12*x(2,t)+200;
if (60<x(2,t))&(x(2,t)<100)
f=15*x(2,t)+70;
end
end
   
function f=fun(x)           %目标函数
i=[1,2]
sum=0;
fq(i)=[350;100];
global x(2,4)
for i=1:2
    for t=1:4
        f=cheng(x(i,t))*u(i,t)+fq(i)*u(i,t).*(1-u(i,t-1))
     sum=sum+f
end
end
function [c,ceq]=mycon1(x)   %约束条件
c(1)=100+20-200any(x(1,1)-100any(x(2,1))
c(2)=30+130-200any(x(1,2))-100any(x(2,2))
c(3)=50+170-200any(x(1,3))-100any(x(2,3))
c(4)=40+140-200any(x(1,4))-100any(x(2,4))
c(11)=x(1,t)-200
c(12)=x(2,t)-100
c(13)=x(1,t+1)-x(1,t)-30
c(14)=x(2,t+1)-x(2,t)-40
c(15)=-x(1,t+1)+x(1,t)-50
c(16)=-x(2,t+1)+x(2,t)-60
ceq=0

[ 本帖最后由 eight 于 2007-11-25 09:59 编辑 ]

x.m

618 Bytes, 下载次数: 4

fun.m

181 Bytes, 下载次数: 4

mycon1.m

390 Bytes, 下载次数: 4

zong.m

439 Bytes, 下载次数: 4

回复
分享到:

使用道具 举报

发表于 2007-11-25 09:41 | 显示全部楼层
改了一个晚上并不算什么,有时候解决一个问题需要更长时间。不在乎你做了多久,而在乎你发现了多少问题。matlab出错的时候,提示会精确到函数、子函数及具体的语句。因此找到出错的地方对症下药,只是一个简单的操作数出错,多为函数的用法不对或者参数不全导致,并不是大问题
发表于 2007-11-25 09:59 | 显示全部楼层
新手的话,建议安装 2006a 版本以上的matlab,节省很多时间
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 15:51 , Processed in 0.061941 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表