Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Find minimum of function using genetic algorithm

`x = ga(fun,nvars)`

`x = ga(fun,nvars,A,b)`

`x = ga(fun,nvars,A,b,Aeq,beq)`

`x = ga(fun,nvars,A,b,Aeq,beq,lb,ub)`

`x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)`

`x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)`

`x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon)`

`x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,options)`

`x = ga(problem)`

```
[x,fval]
= ga(___)
```

```
[x,fval,exitflag,output]
= ga(___)
```

```
[x,fval,exitflag,output,population,scores]
= ga(___)
```

finds a local unconstrained minimum, `x`

= ga(`fun`

,`nvars`

)`x`

, to the objective
function, `fun`

. `nvars`

is the dimension (number
of design variables) of `fun`

.

Passing Extra Parameters (Optimization Toolbox) explains how to pass extra parameters to the objective function and nonlinear constraint functions, if necessary.

subjects the minimization to the constraints defined in `x`

= ga(`fun`

,`nvars`

,`A`

,`b`

,`Aeq`

,`beq`

,`lb`

,`ub`

,`nonlcon`

)`nonlcon`

.
The function `nonlcon`

accepts `x`

and returns
vectors `C`

and `Ceq`

, representing the nonlinear
inequalities and equalities respectively. `ga`

minimizes the
`fun`

such that
`C(x) `

≤` 0`

and
`Ceq(x) = 0`

. (Set `lb=[]`

and
`ub=[]`

if no bounds exist.)

or
`x`

= ga(`fun`

,`nvars`

,`A`

,`b`

,[],[],`lb`

,`ub`

,`nonlcon`

,`IntCon`

)

requires that the variables listed in `x`

= ga(`fun`

,`nvars`

,`A`

,`b`

,[],[],`lb`

,`ub`

,`nonlcon`

,`IntCon`

,`options`

)`IntCon`

take integer
values.

When there are integer constraints, `ga`

does not
accept linear or nonlinear equality constraints, only inequality
constraints.

To write a function with additional parameters to the independent variables that can be called by

`ga`

, see Passing Extra Parameters (Optimization Toolbox).For problems that use the population type

`Double Vector`

(the default),`ga`

does not accept functions whose inputs are of type`complex`

. To solve problems involving complex data, write your functions so that they accept real vectors, by separating the real and imaginary parts.

For a description of the genetic algorithm, see How the Genetic Algorithm Works.

For a description of the mixed integer programming algorithm, see Integer ga Algorithm.

For a description of the nonlinear constraint algorithms, see Nonlinear Constraint Solver Algorithms.

[1] Goldberg, David E., *Genetic Algorithms in Search, Optimization &
Machine Learning*, Addison-Wesley, 1989.

[2] A. R. Conn, N. I. M. Gould, and Ph. L. Toint. “A Globally Convergent
Augmented Lagrangian Algorithm for Optimization with General Constraints and Simple
Bounds”, *SIAM Journal on Numerical Analysis*, Volume 28,
Number 2, pages 545–572, 1991.

[3] A. R. Conn, N. I. M. Gould, and Ph. L. Toint. “A Globally Convergent
Augmented Lagrangian Barrier Algorithm for Optimization with General Inequality
Constraints and Simple Bounds”, *Mathematics of
Computation*, Volume 66, Number 217, pages 261–288, 1997.