Mathematical Definition


Rastrigin Function

Rastrigin Function

Rastrigin Function

Rastrigin Function

Rastrigin Function

The contour of the function is as presented below:

Rastrigin Function

Description and Features

  • The function is continuous.
  • The function is convex.
  • The function is defined on n-dimensional space.
  • The function is multimodal.
  • The function is differentiable.
  • The function is separable.
  • The function is .

Input Domain

The function can be defined on any input domain but it is usually evaluated on $x_i \in [-5.12, 5.12]$ for $i = 1, …, n$ .

Global Minima

The function has one global minimum $f(\textbf{x}^{\ast})=0 at $\textbf{x}^{\ast} = (0, 0)$.


An implementation of the Rastrigin Function with MATLAB is provided below.

% Computes the value of Rastrigin benchmark function.
% SCORES = RASTRIGINFCN(X) computes the value of the Rastrigin function at 
% point X. RASTRIGINFCN accepts a matrix of size M-by-N and returns a vetor 
% SCORES of size M-by-1 in which each row contains the function value for
% the corresponding row of X.
% For more information please visit: 
% Author: Mazhar Ansari Ardeh
% Please forward any comments or bug reports to mazhar.ansari.ardeh at
% Google's e-mail service or feel free to kindly modify the repository.
function f = rastriginfcn(x)
    n = size(x, 2);
    A = 10;
    f = (A * n) + (sum(x .^2 - A * cos(2 * pi * x), 2));

The function can be represented in Latex as follows:

f(x, y)=10n + \sum_{i=1}^{n}(x_i^2 - 10cos(2\pi x_i))