作业帮 > 综合 > 作业

请问你可以帮我编一下下面的函数吗,

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/05/08 02:34:09
请问你可以帮我编一下下面的函数吗,
请问你可以帮我编一下下面的函数吗,
function y=optm(Xij)
options = optimset('Algorithm','interior-point');
X=Xij;
LB=zeros(1,31);
UB=960000*ones(1,31);
X0=10000*rand(1,31);
[y,FVAL,EXITFLAG] = FMINCON(@(x)obfun(x,X),X0,[],[],[],[],LB,UB,@(x)con(x,X),options)
function GG=obfun(x,X)
W=[0.1440 0.1380 0.1440 0.1440 0.1440 0.1420 0.1440];
Sx=sum(x);
for i=1:31
Y(i)=x(i)/Sx;
end
for j=1:7
SG=0;
for i=2:31
SG=SG+(X(j,i)-X(j,i-1))*(Y(i)+Y(i-1));
end
G(j)=1-SG;
end
GG=sum(W.*G);
function [c,ceq]=con(x,X)
Gu=[0.3160 0.5960 0.5310 0.3060 0.4850 0.4550 0.4020];
Sx=sum(x);
for i=1:31
Y(i)=x(i)/Sx;
end
for j=1:7
SG=0;
for i=2:31
SG=SG+(X(j,i)-X(j,i-1))*(Y(i)+Y(i-1));
end
G(j)=1-SG;
end
for i=1:7
c(i)=G(i)-Gu(i);
end
for i=8:14
c(i)=-G(i-7);
end
c(15)=-Sx+120000;
c(16)=Sx-960000;
ceq=[];