Why is this function not being graphed as expected?

75 Views Asked by At

I am interested in the Rastrigin function: https://en.wikipedia.org/wiki/Rastrigin_function.

I have read that the local minimums of this function occur at integer coordinates. However, when I plug this function into a grapher like Desmos, the local minimas are not showing up at integer locations (but close to them).

enter image description here

When I evaluate this in Wolfram Alpha, I get the same thing: the local minimas are not actually at integer coordinates, but somewhere close. Same in Python.

Why am I getting these results? Do the function's minimums not actually come at integer coordinates, am I evaluating it wrong, or could it be some sort of precision issue?

1

There are 1 best solutions below

0
On BEST ANSWER

It is not true that the minima are at integers because of the $x^2$ term. They are close to integers because the cosine term changes much faster than the $x^2$ term. If we take the derivative we get $$f'(x)=2x+20\pi \sin(2\pi x)$$ The second term is $0$ at $x=1$ but the first is not. We need to make the second term about $-2$ to get the derivative to be $0$, which does not happen at $x=1$ A first approximation for the derivative comes from $$2+20\pi \sin(2\pi x)=0\\ \sin (2\pi x)=\frac {-1}{10\pi}\\ x=1+\frac{-1}{20\pi^2}\\ x \approx 0.995$$ in agreement with your plot