The Rastrigin Function is a fairly complicated mathematical function often used as a test problem for numerical optimization algorithms. There are actually several variations of the function. A common version is:
f(x,y) = 20 + (x^2 – 10*cos(2*pi*x)) + (y^2 – 10*cos(2*pi*y))
where x and y can be between -5.12 and +5.12.
The Rastrigin function has an interesting shape when plotted in 3D. See the image below. The function has a minimum value of 0.0 when x = 0.0 and y = 0.0.
A very common way to plot math functions is by using the MatLab program but I wanted to use SciLab, a close-but-not-exact clone of the MatLab program (which can be a bit pricey). Here are SciLab commands that generated the nice visualization of the Rastrigin function:
x1 = linspace(-5.12,5.12,100);
x2 = linspace(-5.12,5.12,100);
[XX1,XX2]=meshgrid(x1,x2);
Z = (XX1.^2 – 10*cos(2*%pi*XX1)) + (XX2.^2 – 10*cos(2*%pi*XX2)) + 20; f=scf();
f.color_map = jetcolormap(64);
plot3d1(x1,x2,Z’);

.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2026 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2026 G2E Conference
2026 iSC West Conference
You must be logged in to post a comment.