MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   求助 怎么总是这个界面啊 (https://www.labfans.com/bbs/showthread.php?t=4193)

shunyu 2008-08-22 16:24

求助 怎么总是这个界面啊
 
function y = my_fun(x)
y = {cos(2*x(1)+1)+2*cos(3*x(1)+2)+3*cos(4*X(1)+3)+4*cos(5*x(1)+4)+5*cos(6*x(1)+5)}*{cos(2*x(2)+1)+2*cos(3*x(2)+2)+3*cos(4*x(2)+3)+4*cos(5*x(2)+4)+5*cos(6*x(2)+5)};

FitnessFunction = @my_fun;
numberOfVariables=2;
x0=[-10 -10];
LB=[-10 -10];
UB=[10 10];
range = [LB(1) UB(1); LB(2) UB(2)];
[x,fval] = ga(FitnessFunction,numberOfVariables,LB,UB)
??? Error using ==> gads\private\aluform
The number of rows in A must be the same as the length of b.

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

Error in ==> ga at 254
[x,fval,exitFlag,output,population,scores] = galincon(FUN,GenomeLength,Aineq,Bineq,Aeq,Beq,LB,UB,options);
:cry: :cry: :cry: :cry: :cry:
怎么搞得啊?
题目是::试利用Matlab遗传算法工具箱求解下列最小值问题。

pslpsl 2008-08-23 10:40

回复: 求助 怎么总是这个界面啊
 
第3、4个参数是输入线性不等约束
第5、6个参数是输入线性等式约束
第7、8个参数才是限定范围

[CODE]
[x,fval] = ga(FitnessFunction,numberOfVariables,[],[],[],[],LB,UB)
[/CODE]

未注册 2008-08-25 14:26

回复: 求助 怎么总是这个界面啊
 
改过 还是不对嘛
??? Error using ==> gads\private\makeState
GA cannot continue because user supplied fitness function failed with the following error:
Error: File: g:\Program Files\MATLAB71\work\my_fun.m Line: 1 Column: 9
Unbalanced or misused parentheses or brackets.

Error in ==> gads\private\galincon at 141
state = makeState(GenomeLength,FitnessFcn,options);

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

Error in ==> F at 6
[x,fval] = ga(FitnessFunction,numberOfVariables,[],[],[],[],LB,UB)

pslpsl 2008-08-26 11:07

回复: 求助 怎么总是这个界面啊
 
这是完全调好后的代码,在MATLAB7.1通过:
[CODE]
function ga_solmy_fun
%EDIT BY [EMAIL="PSL@CSU"]PSL@CSU[/EMAIL]
%QQ:547423688
%Email:[EMAIL="[email protected]"][email protected][/EMAIL]
FitnessFunction = @my_fun;
numberOfVariables=2;
LB=[-10 -10];
UB=[10 10];
%没有额外约束 所以MutationFcn参数没有设定
%求解时会有警告 可以忽略该警告
options=gaoptimset('TolFun',1e-015);
[x,fval] = ga(FitnessFunction,numberOfVariables,[],[],[],[],LB,UB,[],options)
function y = my_fun(x)
y = (cos(2*x(1)+1)+2*cos(3*x(1)+2)+3*cos(4*x(1)+3)+4*cos(5*x(1)+4)+...
5*cos(6*x(1)+5))*(cos(2*x(2)+1)+2*cos(3*x(2)+2)+3*cos(4*x(2)+3)+...
4*cos(5*x(2)+4)+5*cos(6*x(2)+5));
%EDIT BY [EMAIL="PSL@CSU"]PSL@CSU[/EMAIL]
%QQ:547423688
%Email:[EMAIL="[email protected]"][email protected][/EMAIL]
[/CODE]

求得函数最小值为-186.7左右


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

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