Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#4 |
普通会员
注册日期: 2008-08-17
年龄: 36
帖子: 70
声望力: 20 ![]() ![]() |
![]()
这是完全调好后的代码,在MATLAB7.1通过:
代码:
function ga_solmy_fun %EDIT BY PSL@CSU %QQ:547423688 %Email:[email protected] 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 PSL@CSU %QQ:547423688 %Email:[email protected] |
![]() |
![]() |