| Contents | Index |
| On this page… |
|---|
Many Global Optimization Toolbox functions accept bounds, linear constraints, or nonlinear constraints. To see how to include these constraints in your problem, see Writing Constraints in the Optimization Toolbox documentation. Try consulting these pertinent links to sections:
Linear Inequality Constraints (linear equality constraints have the same form)
It is more important to set bounds for global solvers than for local solvers. Global solvers use bounds in a variety of ways:
GlobalSearch requires bounds for its scatter-search point generation. If you do not provide bounds, GlobalSearch bounds each component below by -9999 and above by 10001. However, these bounds can easily be inappropriate.
If you do not provide bounds and do not provide custom start points, MultiStart bounds each component below by -1000 and above by 1000. However, these bounds can easily be inappropriate.
ga uses bounds and linear constraints for its initial population generation. For unbounded problems, ga uses a default of 0 as the lower bound and 1 as the upper bound for each dimension for initial point generation. For bounded problems, and problems with linear constraints, ga uses the bounds and constraints to make the initial population.
simulannealbnd and patternsearch do not require bounds, although they can use bounds.
If you use GlobalSearch or MultiStart with fmincon, your nonlinear constraint functions can return derivatives (gradient or Hessian). For details, see Gradients and Hessians.
The ga and patternsearch solvers optionally compute the nonlinear constraint functions of a collection of vectors in one function call. This method can take less time than computing the objective functions of the vectors serially. This method is called a vectorized function call.
For the solver to compute in a vectorized manner, you must vectorize both your objective (fitness) function and nonlinear constraint function. For details, see Vectorizing the Objective and Constraint Functions.
As an example, suppose your nonlinear constraints for a three-dimensional problem are

The following code gives these nonlinear constraints in a vectorized fashion, assuming that the rows of your input matrix x are your population or input vectors:
function [c ceq] = nlinconst(x) c(:,1) = x(:,1).^2/4 + x(:,2).^2/9 + x(:,3).^2/25 - 6; c(:,2) = cosh(x(:,1) + x(:,2)) - x(:,3); ceq = x(:,1).*x(:,2).*x(:,3) - 2;
For example, minimize the vectorized quadratic function
function y = vfun(x) y = -x(:,1).^2 - x(:,2).^2 - x(:,3).^2;
over the region with constraints nlinconst using patternsearch:
options = psoptimset('CompletePoll','on','Vectorized','on');
[x fval] = patternsearch(@vfun,[1,1,2],[],[],[],[],[],[],...
@nlinconst,options)
Optimization terminated: mesh size less than options.TolMesh
and constraint violation is less than options.TolCon.
x =
0.2191 0.7500 12.1712
fval =
-148.7480Using ga:
options = gaoptimset('Vectorized','on');
[x fval] = ga(@vfun,3,[],[],[],[],[],[],@nlinconst,options)
Optimization terminated: maximum number of generations exceeded.
x =
-1.4098 -0.1216 11.6664
fval =
-138.1066For this problem patternsearch computes the solution far more quickly and accurately.
![]() | Computing Objective Functions | User's Guide | ![]() |

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 |