哪位帮忙看下这个程序能不能运行,如果不可以的话怎么修改?

来源:百度知道 编辑:UC知道 时间:2024/05/07 16:44:50
M文件1:
function[c,ceq]=confuneq(x)
c=[];
ceq=[1.01*x(1)+1.02*x(2)+1.045*x(3)+1.065*x(4)+x(5)-1];
M文件2:
function f=myfun(x)
f(1)=0.025*x(1); f(2)=0.015*x(2);
f(3)=0.055*x(3); f(4)=0.026*x(4);
%f(5)=x(5);
M文件3:
clear
j=1;
a=[];
x0=zeros(1,5);
lb=[0;0;0;0;0];
ub=[1;1;1;1;1];
for h=0.05:0.005:0.27
% 为 的初值 lb=[0,0,0,0]; lb为 的下限,ub为 的上限
Aeq=[1.01 1.02 1.045 1.065 1;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0];
beq=[1;0;0;0;0];
A=[-0.27 -0.19 -0.185 -0.185 -0.05;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0];
b=[-h;0;0;0;0];
options=optimset('largescale','off','display','iter');
options=optimset(options,'tolx',1e-10);
options=optimset(options,'tolfun',1e-10);
[x(j,:),fval,exitflag(j),output]=fminimax(@myfun,x0,A,b,Aeq,beq,lb,ub,'confuneq',options);
j=j+1;
end
a(:,1)=exitflag'

这下程序倒是通了,可就是找不到最有解。

function hahah
%M文件3:
clear
j=1;a=[]; x0=zeros(1,5);
lb=[0;0;0;0;0];
ub=[1;1;1;1;1];
% 为 的初值 lb=[0,0,0,0]; lb为 的下限,ub为 的上限
Aeq=[1.01 1.02 1.045 1.065 1;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0];
beq=[1;0;0;0;0];
A=[-0.27 -0.19 -0.185 -0.185 -0.05;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0;0 0 0 0 0];
options=optimset('largescale','off','display','iter');
options=optimset(options,'tolx',1e-10);
options=optimset(options,'tolfun',1e-10);

for h=0.05:0.005:0.27
b=[-h;0;0;0;0];
[x(j,:),fval,exitflag(j),output]=fminimax(@myfun,x0,A,b,Aeq,beq,lb,ub,@confuneq,options);
j=j+1;
end
a(:,1)=exitflag';
a(:,2:6)=x;
a

function[c,ceq]=confuneq(x)
c=[];
ceq=[1.01*x(1)+1.02*x(2)+1.045*x(3)+1.065*x(4)+x(5)-1];
%M文件2:
function f=myfun(x)
f(1)=0.025*x(1); f(2)=0.015*x(2);