ackley.m

% Ackley函数

function [y] = ackley(xx)

d = length(xx);

sum1 = 0;

sum2 = 0;

for ii = 1:d

xi = xx(ii);

sum1 = sum1 + xi^2;

sum2 = sum2 + cos(2*pi*xi);

end

term1 = -20 * exp(-0.2*sqrt(sum1/d));

term2 = -exp(sum2/d);

y = term1 + term2 + 22.71282;

end