Skip to content

Instantly share code, notes, and snippets.

@jschwinger233
Created April 29, 2014 05:09
Show Gist options
  • Select an option

  • Save jschwinger233/11391090 to your computer and use it in GitHub Desktop.

Select an option

Save jschwinger233/11391090 to your computer and use it in GitHub Desktop.
fun = {@(x)sum(-x.*sin(sqrt(abs(x))), 2),
@(x)sum(x.^2-10*cos(2*pi*x)+10,2),
@(x)-20*exp(-0.2*sqrt(sum(x.^2,2)/30))-exp(sum(cos(2*pi*x),2)/30)+20+exp(1),
@(x)sum(x.^4-16*x.^2+x,2)/100,
@(x)sum((1-x(:,1:end-1)).^2 + 100*(x(:,2:end)-x(:,1:end-1).^2).^2,2),
@(x)sum(x.^2,2),
@(x)sum(x.^4,2)+rand(size(x, 1),1),
@(x)sum(abs(x),2)+prod(abs(x),2),
@(x)max(abs(x), [], 2)};
lb = {-500*ones(1, 30),
-5.12*ones(1,30),
-32*ones(1,30),
-5*ones(1,100),
-5*ones(1,100),
-100*ones(1,30),
-1.28*ones(1,30),
-10*ones(1,30),
-100*ones(1,30)};
ub = {500*ones(1, 30),
5.12*ones(1,30),
32*ones(1,30),
5*ones(1,100),
10*ones(1,100),
100*ones(1,30),
1.28*ones(1,30),
10*ones(1,30),
100*ones(1,30)};
for i = 8:length(fun)-1
fval = inf;
for j = 1:10
fval0 = gaunc(fun{i}, lb{i}, ub{i});
if fval0 < fval
fval = fval0;
end
end
fprintf('第%d个函数的最小值为%f\n', i, fval)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment