## Copyright (C) 2009 Christian Fischer <fischer@itm.uni-stuttgart.de>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see <http://www.gnu.org/licenses/>.

## Rastrigin function - used to create example obj. fns.
##
## The minimiser is at the vector (0,0,..,0),
## and the minimized value is 0.
##
## Rastrigin's function is based on a quadratic function with the addition
## of cosine modulation to produce many local minima.
## Thus the test function is highly multimodal.
## However, the locations of the minima are regularly distributed.

function result = rastrigin(x)

result = 10 * length (x) + sum ( x.^2 -10 * cos (2 * pi * x) );

endfunction

