问题补充,这是我自己编的,
我刚学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.
请问大家怎么解决啊?