|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
function allcost=Q(z)
clear
a=unifrnd(1000,2000,1,4);
for i=1:4
for j=4:-1:i+1
if a(j)<a(j-1)
m=a(j);a(j)=a(j-1);a(j-1)=m;
end
end
end
b=a;
t=z
k1=0;k2=0;
amin=a(1);bmin=b(1);
while amin<t
r=a(1)+1;a(1)=a(2)+1;a(2)=a(3)+1;a(3)=a(4)+1;
a(4)=r+unifrnd(1000,2000);
for i=1:4
for j=4:-1:i+1
if a(j)<a(j-1)
n=a(j);a(j)=a(j-1);a(j-1)=n;
end
end
end
amin=a(1);
k1=k1+1;
end
while bmin<t
b(1)=bmin+unifrnd(1000,2000)+2;
b(2)=bmin+unifrnd(1000,2000)+2;
b(3)=bmin+unifrnd(1000,2000)+2;
b(4)=bmin+unifrnd(1000,2000)+2;
bmin=min(b);
k2=k2+1;
end
x1=k1*30;
x2=k2*80;
allcost=[x1,x2]
调用该函数无法运行,显示“Reference to a cleared variable z.”
不明白请高手指教,谢谢 |
|