Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
one question about function "Rastrigin"

Subject: one question about function "Rastrigin"

From: Yi

Date: 30 May, 2009 19:52:01

Message: 1 of 5

Hi: I just brought the Matlab 2009 and try to learn GA toolbox. When I read the user's guide, I was confused about created m.file as shown below.

Below is the function called Rastrigin, which I copied from GA toolbox user guide.

Rastrigin’s Function
This section presents an example that shows how to find the minimum of
Rastrigin’s function, a function that is often used to test the genetic algorithm.
For two independent variables, Rastrigin’s function is defined as
Ras(x)=20+x1+x −10(cos2 x +cos2 x).

Genetic Algorithm and Direct Search Toolbox software contains an M-file,
rastriginsfcn.m, that computes the values of Rastrigin’s function. The
following figure shows a plot of Rastrigin’s function.

However, when I open this M.file. It seems a different function as shown below.

function scores = rastriginsfcn(pop)
%RASTRIGINSFCN Compute the "Rastrigin" function.

% Copyright 2003-2004 The MathWorks, Inc.
% $Revision: 1.3.4.1 $ $Date: 2004/08/20 19:50:22 $


    % pop = max(-5.12,min(5.12,pop));
    scores = 10.0 * size(pop,2) + sum(pop .^2 - 10.0 * cos(2 * pi .* pop),2);

Could anybody tell me what's wrong? Thanks

All the best

Yi

Subject: one question about function "Rastrigin"

From: Darren Rowland

Date: 1 Jun, 2009 03:29:02

Message: 2 of 5

Yi,
There is nothing wrong actually. The rastriginsfcn function is written to allow a vector of any length as input. The calculation follows from there. If you compare to this page about the function
http://www.cs.rtu.lv/dssg/en/staff/rastrigin/rastr-function.html
you can see that the Matlab function uses A=10 (instead of allowing this value as input).
Hope that clears things up.
Darren

Subject: one question about function "Rastrigin"

From: Yi

Date: 2 Jun, 2009 02:19:02

Message: 3 of 5

Thank you so much, Darren. How to get these beautiful pictures by matlab? Shoudl use the command "contour"? Thank you so much!

Yi

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <gvvhtu$k4d$1@fred.mathworks.com>...
> Yi,
> There is nothing wrong actually. The rastriginsfcn function is written to allow a vector of any length as input. The calculation follows from there. If you compare to this page about the function
> http://www.cs.rtu.lv/dssg/en/staff/rastrigin/rastr-function.html
> you can see that the Matlab function uses A=10 (instead of allowing this value as input).
> Hope that clears things up.
> Darren

Subject: one question about function "Rastrigin"

From: Yi

Date: 2 Jun, 2009 02:19:02

Message: 4 of 5

Thank you so much, Darren. How to get these beautiful pictures by matlab? Shoudl use the command "contour"? Thank you so much!

Yi

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <gvvhtu$k4d$1@fred.mathworks.com>...
> Yi,
> There is nothing wrong actually. The rastriginsfcn function is written to allow a vector of any length as input. The calculation follows from there. If you compare to this page about the function
> http://www.cs.rtu.lv/dssg/en/staff/rastrigin/rastr-function.html
> you can see that the Matlab function uses A=10 (instead of allowing this value as input).
> Hope that clears things up.
> Darren

Subject: one question about function "Rastrigin"

From: Yi

Date: 2 Jun, 2009 02:19:02

Message: 5 of 5

Thank you so much, Darren. How to get these beautiful pictures by matlab? Shoudl use the command "contour"? Thank you so much!

Yi

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <gvvhtu$k4d$1@fred.mathworks.com>...
> Yi,
> There is nothing wrong actually. The rastriginsfcn function is written to allow a vector of any length as input. The calculation follows from there. If you compare to this page about the function
> http://www.cs.rtu.lv/dssg/en/staff/rastrigin/rastr-function.html
> you can see that the Matlab function uses A=10 (instead of allowing this value as input).
> Hope that clears things up.
> Darren

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us