| Contents | Index |
x = ga(fitnessfcn,nvars)
x = ga(fitnessfcn,nvars,A,b)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon,options)
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon)
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon,options)
x = ga(problem)
[x,fval]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag,output]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag,output,population]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag,output,population,scores]
= ga(fitnessfcn,nvars,...)
x = ga(fitnessfcn,nvars) finds a local unconstrained minimum, x, to the objective function, fitnessfcn. nvars is the dimension (number of design variables) of fitnessfcn. The objective function, fitnessfcn, accepts a vector x of size 1-by-nvars, and returns a scalar evaluated at x.
x = ga(fitnessfcn,nvars,A,b) finds a local minimum x to fitnessfcn, subject to the linear inequalities A x ≤ b. fitnessfcn accepts input x and returns a scalar function value evaluated at x.
x = ga(fitnessfcn,nvars,A,b,Aeq,beq) finds a local minimum x to fitnessfcn, subject to the linear equalities Aeq x = beq as well as A x ≤ b. (Set A=[] and b=[] if no inequalities exist.)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB) defines a set of lower and upper bounds on the design variables, x, so that a solution is found in the range LB ≤ x ≤ UB. Use empty matrices for LB and UB if no bounds exist.
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon) subjects the minimization to the constraints defined in nonlcon. The function nonlcon accepts x and returns vectors C and Ceq, representing the nonlinear inequalities and equalities respectively. ga minimizes the fitnessfcn such that C(x) ≤ 0 and Ceq(x) = 0. (Set LB=[] and UB=[] if no bounds exist.)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon,options) minimizes with the default optimization parameters replaced by values in the structure options, which can be created using the gaoptimset function.
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon) requires that the variables listed in IntCon take integer values.
Note When there are integer constraints, ga does not accept linear or nonlinear equality constraints, only inequality constraints. |
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon,options) minimizes with integer constraints and with the default optimization parameters replaced by values in the options structure.
x = ga(problem) finds the minimum for problem, where problem is a structure.
[x,fval] = ga(fitnessfcn,nvars,...) returns fval, the value of the fitness function at x.
[x,fval,exitflag] = ga(fitnessfcn,nvars,...) returns exitflag, an integer identifying the reason the algorithm terminated.
[x,fval,exitflag,output] = ga(fitnessfcn,nvars,...) returns output, a structure that contains output from each generation and other information about the performance of the algorithm.
[x,fval,exitflag,output,population] = ga(fitnessfcn,nvars,...) returns the matrix, population, whose rows are the final population.
[x,fval,exitflag,output,population,scores] = ga(fitnessfcn,nvars,...) returns scores the scores of the final population.
To write a function with additional parameters to the independent variables that can be called by ga, see Passing Extra Parameters in the Optimization Toolbox documentation.
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.
fitnessfcn |
Handle to the fitness function. The fitness function should accept a row vector of length nvars and return a scalar value. When the 'Vectorized' option is 'on', fitnessfcn should accept a pop-by-nvars matrix, where pop is the current population size. In this case fitnessfcn should return a vector the same length as pop containing the fitness function values. fitnessfcn should not assume any particular size for pop, since ga can pass a single member of a population even in a vectorized calculation. | ||||||||||||||||||||||||||
nvars |
Positive integer representing the number of variables in the problem. | ||||||||||||||||||||||||||
A |
Matrix for linear inequality constraints of the form A x ≤ b. If the problem has m linear inequality constraints and nvars variables, then
| ||||||||||||||||||||||||||
b |
Vector for linear inequality constraints of the form A x ≤ b. If the problem has m linear inequality constraints and nvars variables, then
| ||||||||||||||||||||||||||
Aeq |
Matrix for linear equality constraints of the form Aeq x = beq. If the problem has m linear equality constraints and nvars variables, then
| ||||||||||||||||||||||||||
beq |
Vector for linear equality constraints of the form Aeq x = beq. If the problem has m linear equality constraints and nvars variables, then
| ||||||||||||||||||||||||||
LB |
Vector of lower bounds. ga enforces that iterations stay above LB. Set LB(i) = –Inf if x(i)is unbounded below. | ||||||||||||||||||||||||||
UB |
Vector of upper bounds. ga enforces that iterations stay below UB. Set UB(i) = Inf if x(i) is unbounded above. | ||||||||||||||||||||||||||
nonlcon |
Function handle that returns two outputs: [c,ceq] = nonlcon(x) ga attempts to achieve c ≤ 0 and ceq = 0. c and ceq are row vectors when there are multiple constraints. Set unused outputs to []. You can write nonlcon as a function handle to a file, such as nonlcon = @constraintfile where constraintfile.m is a file on your MATLAB path. To learn how to use vectorized constraints, see Vectorized Constraints.
| ||||||||||||||||||||||||||
options |
Structure containing optimization options. Create options using gaoptimset, or by exporting options from the Optimization Tool as described in Importing and Exporting Your Work in the Optimization Toolbox documentation. | ||||||||||||||||||||||||||
IntCon |
Vector of positive integers taking values from 1 to nvars. Each value in IntCon represents an x component that is integer-valued.
| ||||||||||||||||||||||||||
problem |
Structure containing the following fields:
Create problem by exporting a problem from the Optimization Tool, as described in Importing and Exporting Your Work in the Optimization Toolbox documentation. |
x |
Best point that ga located during its iterations. | |||||||||||||||||||||||
fval |
Fitness function evaluated at x. | |||||||||||||||||||||||
exitflag |
Integer giving the reason ga stopped iterating:
When there are integer constraints, ga uses the penalty fitness value instead of the fitness value for stopping criteria. | |||||||||||||||||||||||
output |
Structure containing output from each generation and other information about algorithm performance. The output structure contains the following fields:
| |||||||||||||||||||||||
population |
Matrix whose rows contain the members of the final population. | |||||||||||||||||||||||
scores |
Column vector of the fitness values (scores for integerconstraints problems) of the final population. |
In the nonlinear constraint solver, the complementarity measure is the norm of the vector whose elements are ciλi, where ci is the nonlinear inequality constraint violation, and λi is the corresponding Lagrange multiplier.
Given the following inequality constraints and lower bounds

use this code to find the minimum of the lincontest6 function, which is provided in your software:
A = [1 1; -1 2; 2 1];
b = [2; 2; 3];
lb = zeros(2,1);
[x,fval,exitflag] = ga(@lincontest6,...
2,A,b,[],[],lb)
Optimization terminated: average change in
the fitness value less than options.TolFun.
x =
0.6700 1.3310
fval =
-8.2218
exitflag =
1Optimize a function where some variables must be integers:
fun = @(x) (x(1) - 0.2)^2 + ...
(x(2) - 1.7)^2 + (x(3) - 5.1)^2;
x = ga(fun,3,[],[],[],[],[],[],[], ...
[2 3]) % variables 2 and 3 are integers
Optimization terminated: average change
in the penalty fitness value less
than options.TolFun and constraint violation
is less than options.TolCon.
x =
0.2000 2.0000 5.0000For 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 algorithm, see Description of the Nonlinear Constraint Solver.
For problems without integer constraints, consider using patternsearch instead of ga.
gamultiobj | gaoptimset | patternsearch

Learn how to use optimization to solve systems of equations, fit models to data, or optimize system performance.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |