约束优化的matlab程序,Matlab多约束最优化问题请高手求助,我编的程序

问题补充,这是我自己编的,

我刚学matlab没有多长时间,请大家帮忙看下程序有什么不对的地方!

x1==csvread('x1.txt');    %x1  是300*10的矩阵

[x1,y,z,v]=GME(x1);

[X,FVAL,REASON,OUTPUT,POPULATION,SCORES] =  untitled(x1,y,z,v);

%处理数据

function [x1,y,z,v]=GME(x)

Y=x(:,10);

miny=min(Y);maxy=max(Y);

y=(Y-mean(Y))/std(Y);  %因变量数据标准化

xdat=x(:,1:9);  %因子数据

xstd=std(xdat);

xmean=mean(xdat);

for j=1:9

for i=1:length(xdat)

xdat(i,j)=(xdat(i,j)-xmean(j))/xstd(j); %因子数据标准化

end

end

x1=xdat;

for j=1:9

z(j,(j-1)*2+1)=-1;

z(j,(j-1)*2+2)=1;

end

for i=1:length(x1)

v(i,(i-1)*3+1)=-3;

v(i,(i-1)*3+2)=0;

v(i,(i-1)*3+3)=3;

end

%调用ga函数

function [X,FVAL,REASON,OUTPUT,POPULATION,SCORES] =  untitled(x1,y,z,v)

%%   This is an auto generated M file to do optimization with the Genetic Algorithm and

%    Direct Search Toolbox. Use GAOPTIMSET for default GA options structure.

%%Fitness function;

fitnessFunction = @gme1;

%%Number of Variables

nvars =length(x1)*3+18;

%Linear inequality constraints

Aineq = [];

Bineq = [];

%Linear equality constraints

Aeq = [];

Beq =[];

%Bounds

LB = 0;

UB = 1;

%Nonlinear constraints

nonlconFunction = @myconstr;

%Start with default options

options = gaoptimset;

%%Modify some parameters

options = gaoptimset(options,'PopulationSize' ,100);

options = gaoptimset(options,'MutationFcn' ,{ @mutationgaussian 1  1  });

options = gaoptimset(options,'Display' ,'off');

%%Run GA

[X,FVAL,REASON,OUTPUT,POPULATION,SCORES] = ga(@(x)fitnessFunction,nvars,Aineq,Bineq,Aeq,Beq,LB,UB,nonlconFunction,options);

%目标函数

function  f=gme1

for i=1:(length(x1)*3+18)

y1=0;

y1(i,1)=y1(i,1)+x(i,1)*log(x(i,1));

end

f=y1;

end

%约束条件

function  [c,ceq] =myconstr

c = [];

for i=1:length(x1)

for j=1:9

ceq(i)=y(i)-x1(i,j)*z(j,(j-1)*2+1)*x((j-1)*2+1,1)-x1(i,j)*z(j,(j-1)*2+2)*x((j-1)*2+2,1)-v(i,(i-1)*3+1)*x((i-1)*3+19,1)-v(i,(i-1)*3+2)*x((i-1)*3+20,1)-v(i,(i-1)*3+3)*x((i-1)*3+21,1);

ceq(length(x1)+1)=x((j-1)*2+1,1)+x((j-1)*2+2,1)-1;

ceq(length(x1)+2)=x((i-1)*3+19,1)+x((i-1)*3+20,1)+x((i-1)*3+21,1)-1;

end

end

%错误提示

??? Error using ==> gads\private\aluform

Cannot continue because user supplied constraint function failed with the following error:

Error using ==> myconstr

Too many input arguments.

请问大家怎么解决啊?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值