function ackley(x)
d = length(xx);
c = 2pi;
b = 0.2;
a = 20;
for ii in 1:d
xi = xx(ii);
sum1 = sum1 + xi^2;
sum2 = sum2 + cos(cxi);
end
sum1 = sum1 + x1^2;
sum2 = sum2 + cos(cx2);
term1 = -a * exp(-bsqrt(sum1/d));
term2 = -exp(sum2/d);
y = term1 + term2 + a + exp(1);
end
I guess you tried to translate the code from R or Matlab implementation. Here is how you can do it in Julia with minimal changes to your idea:
function ackley(x)
d = length(x)
c = 2*pi
b = 0.2
a = 20
sum1 = 0
sum2 = 0
for i in 1:d
xi = x[i]
sum1 += xi^2
sum2 += cos(c*xi)
end
sum1 += x[1]^2
sum2 += cos(c*x[2])
term1 = -a * exp(-b*sqrt(sum1/d))
term2 = -exp(sum2/d)
y = term1 + term2 + a + exp(1)
end