Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 人工智能 > 进化计算
进化计算 A discussion board for Evolutionary Computation.
回复
 
主题工具 显示模式
旧 2009-05-13, 13:22   #1
上善若水zm
初级会员
 
注册日期: 2009-05-13
帖子: 1
声望力: 0
上善若水zm 正向着好的方向发展
默认 matlab7.1用ga函数求解约束最优化问题时出错

myfun9.m是目标函数文件,如下:
function y=myfun9(x)
fai0=asin(x(4)*sin(x(6))/x(3));
fai1=asin(x(4)*sin(x(5)+x(6))/x(3));
beta1=asin(x(2)*sin(x(5)));
sm=x(1)*(1-cos(x(5))+(1-sqrt(1-x(2)^2*(sin(x(5)))^2))/x(2));
sg=x(4)*(sin(fai1+x(5)+x(6))/sin(fai1)-sin(fai0+x(6))/sin(fai0));
w=sm/sg;
m_min=x(4)*sin(x(5)+x(6)+fai1)*cos(beta1)/(x(1)*sin(x(5)+beta1)*cos(fai1));
pm_max=3200;
p0_max=pm_max/m_min;
y=p0_max-w;
(其中x(1)—x(6)为目标变量)

mycon9.m是约束函数文件,如下:
function [c,ce]=mycon9(x)
ce=[];
c=[sin(10/180*pi)-x(4)*sin(x(5)+x(6))/x(3);...
0.5-x(2)*sin(x(5));...
x(2)*sin(x(5))-sqrt(2)/2;...
0.5*x(1)*(1-cos(x(5))+(1-sqrt(1-x(2)^2*(sin(x(5)))^2))/x(2))-x(1);...
sqrt(2*x(1)*x(4)*cos(x(6))-x(1)^2-x(4)^2)-5-5;...
sin(80/180*pi)-x(4)*sin(x(6))/x(3);...
x(4)*sin(x(6))/x(3)-1;...
500-x(1)*(1-cos(x(5))+(1-sqrt(1-x(2)^2*(sin(x(5)))^2))/x(2));...
abs(x(4)*sin(x(5)+x(6))/x(3))-1;...
abs(x(4)*sin(x(6))/x(3))-1];
(10个约束条件)

在matlab7.1命令行输入:
>> xm=[250;0.7;300;150;60/180*pi;90/180*pi];
>> xM=[300;0.9;400;250;80/180*pi;110/180*pi];
>> [x,fval]=ga(@myfun9,6,[],[],[],[],xm,xM,@mycon9)

结果出现:
??? Error using ==> gads\private\aluform
Constraint function must return real value.

Error in ==> gads\private\gacon at 103
[Iterate,A,L,U,nineqcstr,neqcstr,ncstr,IndIneqcstr,IndEqcstr,msg,EXITFLAG] = ...

Error in ==> ga at 251
[x,fval,exitFlag,output,population,scores] = gacon(FUN,GenomeLength,Aineq,Bineq,Aeq,Beq,LB,UB,nonlcon,options);

问题出在哪??

附上错误行:
% Make A, L, U as L <= A*X <= U
>> 103[Iterate,A,L,U,nineqcstr,neqcstr,ncstr,IndIneqcstr,IndEqcstr,msg,EXITFLAG] = ...
aluform(Iterate.x,Aineq,Bineq,Aeq,Beq,LB,UB,GenomeLength,subtype,verbosity, ...
constr,X,conFcnArg);
if EXITFLAG < 0
FVAL = [];
X( = Iterate.x;
REASON = msg;
OUTPUT.message = msg;
if verbosity > 0
fprintf('%s\n',msg)
end
return;
else
options.InitialPopulation(1, = Iterate.x';
end

>> 249 % If constraints/bounds then call constraint solver
if ~isempty(nonlcon)
>> 251 [x,fval,exitFlag,output,population,scores] = gacon(FUN,GenomeLength,Aineq,Bineq,Aeq,Beq,LB,UB,nonlcon,options);
% If Aeq or Aineq is not empty, then problem has linear constraints.
elseif ~isempty(Aeq) || ~isempty(Aineq)
[x,fval,exitFlag,output,population,scores] = galincon(FUN,GenomeLength,Aineq,Bineq,Aeq,Beq,LB,UB,options);
% This condition satisfies bound constraints
elseif (isempty(Aeq) && isempty(Aineq) && isempty(Bineq) && isempty(Beq)) && ( ~isempty(LB) || ~isempty(UB) )
[x,fval,exitFlag,output,population,scores] = galincon(FUN,GenomeLength,Aineq,Bineq,Aeq,Beq,LB,UB,options);
% Unconstrained problem
elseif (isempty(Aeq) && isempty(Aineq) && isempty(Bineq) && isempty(Beq) && isempty(LB) && isempty(UB))
[x,fval,exitFlag,output,population,scores] = gaunc(FUN,GenomeLength,options);
% Try nonlinear constrained solver
else
try
[x,fval,exitFlag,output,population,scores] = gacon(FUN,GenomeLength,Aineq,Bineq,Aeq,Beq,LB,UB,nonlcon,options);
catch
error('gads:GA:entryPoint','%s','Invalid input to GA');
end
end
上善若水zm 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 11:24


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.