| Genetic Algorithm and Direct Search Toolbox | ![]() |
Using the Genetic Algorithm at the Command Line
As an alternative to using the Genetic Algorithm Tool, you can run the genetic algorithm function ga from the command line. This section explains how to do so and covers the following topics.
Running the Genetic Algorithm with the Default Options
To run the genetic algorithm with the default options, call ga with the syntax
@fitnessfun -- A function handle to the M-file that computes the fitness function. Writing an M-File for the Function You Want to Optimize explains how to write this M-file.
nvars -- The number of independent variables for the fitness function.
For a description of additional output arguments, see the reference page for ga.
As an example, you can run the example described in Example: Rastrigin's Function from the command line by entering
Additional Output Arguments
To get more information about the performance of the genetic algorithm, you can call ga with the syntax
Besides x and fval, this returns the following additional output arguments:
reason -- Reason the algorithm terminated
output -- Structure containing information about the performance of the algorithm at each generation
population -- Final population
scores -- Final scores
See the reference page for ga for more information about these arguments.
| Generating an M-File | Setting Options at the Command Line | ![]() |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |