fmincon - Find minimum of constrained nonlinear multivariable function

Equation

Finds the minimum of a problem specified by

x, b, beq, lb, and ub are vectors, A and Aeq are matrices, c(x) and ceq(x) are functions that return vectors, and f(x) is a function that returns a scalar. f(x), c(x), and ceq(x) can be nonlinear functions.

Syntax

x = fmincon(fun,x0,A,b)
x = fmincon(fun,x0,A,b,Aeq,beq)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
x = fmincon(problem)
[x,fval] = fmincon(...)
[x,fval,exitflag] = fmincon(...)
[x,fval,exitflag,output] = fmincon(...)
[x,fval,exitflag,output,lambda] = fmincon(...)
[x,fval,exitflag,output,lambda,grad] = fmincon(...)
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(...)

Description

fmincon attempts to find a constrained minimum of a scalar function of several variables starting at an initial estimate. This is generally referred to as constrained nonlinear optimization or nonlinear programming.

x = fmincon(fun,x0,A,b) starts at x0 and attempts to find a minimizer x of the function described in fun subject to the linear inequalities A*x ≤ b. x0 can be a scalar, vector, or matrix.

x = fmincon(fun,x0,A,b,Aeq,beq) minimizes fun subject to the linear equalities Aeq*x = beq and A*x ≤ b. If no inequalities exist, set A = [] and b = [].

x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables in x, so that the solution is always in the range lb ≤ x ≤ ub. If no equalities exist, set Aeq = [] and beq = []. If x(i) is unbounded below, set lb(i) = -Inf, and if x(i) is unbounded above, set ub(i) = Inf.

x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon) subjects the minimization to the nonlinear inequalities c(x) or equalities ceq(x) defined in nonlcon. fmincon optimizes such that c(x) ≤ 0 and ceq(x) = 0. If no bounds exist, set lb = [] and/or ub = [].

x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) minimizes with the optimization options specified in the structure options. Use optimset to set these options. If there are no nonlinear inequality or equality constraints, set nonlcon = [].

x = fmincon(problem) finds the minimum for problem, where problem is a structure described in Input Arguments.

Create the structure problem by exporting a problem from Optimization Tool, as described in Exporting to the MATLAB Workspace.

[x,fval] = fmincon(...) returns the value of the objective function fun at the solution x.

[x,fval,exitflag] = fmincon(...) returns a value exitflag that describes the exit condition of fmincon.

[x,fval,exitflag,output] = fmincon(...) returns a structure output with information about the optimization.

[x,fval,exitflag,output,lambda] = fmincon(...) returns a structure lambda whose fields contain the Lagrange multipliers at the solution x.

[x,fval,exitflag,output,lambda,grad] = fmincon(...) returns the value of the gradient of fun at the solution x.

[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(...) returns the value of the Hessian at the solution x. See Hessian.

Input Arguments

Function Arguments describes the arguments passed to fmincon. Options provides the function-specific details for the options values. This section provides function-specific details for fun, nonlcon, and problem.

fun

The function to be minimized. fun is a function that accepts a vector x and returns a scalar f, the objective function evaluated at x. fun can be specified as a function handle for an M-file function

x = fmincon(@myfun,x0,A,b)

where myfun is a MATLAB function such as

function f = myfun(x)
f = ...            % Compute function value at x

fun can also be a function handle for an anonymous function:

x = fmincon(@(x)norm(x)^2,x0,A,b);

If the gradient of fun can also be computed and the GradObj option is 'on', as set by

options = optimset('GradObj','on')

then fun must return the gradient vector g(x) in the second output argument.

If the Hessian matrix can also be computed and the Hessian option is 'on' via options = optimset('Hessian','user-supplied') and the Algorithm option is trust-region-reflective, fun must return the Hessian value H(x), a symmetric matrix, in a third output argument. See Writing Objective Functions for details.

If the Hessian matrix can be computed and the Algorithm option is interior-point, there are several ways to pass the Hessian to fmincon. For more information, see Hessian.

nonlcon

The function that computes the nonlinear inequality constraints c(x)≤ 0 and the nonlinear equality constraints ceq(x) = 0. nonlcon accepts a vector x and returns the two vectors c and ceq. c is a vector that contains the nonlinear inequalities evaluated at x, and ceq is a vector that contains the nonlinear equalities evaluated at x. nonlcon can be specified as a function handle:

x = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@mycon)
 
 
 
 
 
 

where mycon is a MATLAB function such as

function [c,ceq] = mycon(x)
c = ...     % Compute nonlinear inequalities at x.
ceq = ...   % Compute nonlinear equalities at x.

If the gradients of the constraints can also be computed and the GradConstr option is 'on', as set by

options = optimset('GradConstr','on')

then nonlcon must also return, in the third and fourth output arguments, GC, the gradient of c(x), and GCeq, the gradient of ceq(x). For more information, see Nonlinear Constraints.

    Note   Because Optimization Toolbox functions only accept inputs of type double, user-supplied objective and nonlinear constraint functions must return outputs of type double.

Passing Extra Parameters explains how to parameterize the nonlinear constraint function nonlcon, if necessary.

 
problem

objective

Objective function 

x0

Initial point for x 

Aineq

Matrix for linear inequality constraints 

bineq

Vector for linear inequality constraints 

Aeq

Matrix for linear equality constraints 

beq

Vector for linear equality constraints 
lbVector of lower bounds 
ubVector of upper bounds 

nonlcon

Nonlinear constraint function 

solver

'fmincon' 

options

Options structure created with optimset 

Output Arguments

Function Arguments describes arguments returned by fmincon. This section provides function-specific details for exitflag, lambda, and output:

exitflag

Integer identifying the reason the algorithm terminated. The following lists the values of exitflag and the corresponding reasons the algorithm terminated.

 

1

First-order optimality measure was less than options.TolFun, and maximum constraint violation was less than options.TolCon.

 

2

Change in x was less than options.TolX.

 

3

Change in the objective function value was less than options.TolFun.

 

4

Magnitude of the search direction was less than 2*options.TolX and constraint violation was less than options.TolCon.

 

5

Magnitude of directional derivative in search direction was less than 2*options.TolFun and maximum constraint violation was less than options.TolCon.

 

0

Number of iterations exceeded options.MaxIter or number of function evaluations exceeded options.FunEvals.

 

-1

The output function terminated the algorithm.

 

-2

No feasible point was found.

grad

Gradient at x

 

hessian

Hessian at x

 

lambda

Structure containing the Lagrange multipliers at the solution x (separated by constraint type). The fields of the structure are:

 lower

Lower bounds lb

 upper

Upper bounds ub

 ineqlin

Linear inequalities

 eqlin

Linear equalities

 ineqnonlin

Nonlinear inequalities

 eqnonlin

Nonlinear equalities

output

Structure containing information about the optimization. The fields of the structure are:

 iterations

Number of iterations taken

 funcCount

Number of function evaluations

 lssteplength

Size of line search step relative to search direction (active-set algorithm only)

 constrviolation

Maximum of constraint violations (active-set and interior-point algorithms)

 stepsize

Length of last displacement in x (active-set and interior-point algorithms)

 algorithm

Optimization algorithm used

 cgiterations

Total number of PCG iterations (trust-region-reflective and interior-point algorithms)

 firstorderopt

Measure of first-order optimality

 message

Exit message

Hessian

fmincon uses a Hessian, the second derivatives of the Lagrangian (see Equation 2-2), namely,

(9-1)

There are three algorithms used by fmincon, and each one handles Hessians differently:

The interior-point algorithm has several more options for Hessians:

The 'HessMult' option for the interior-point algorithm has a different syntax than that of the trust-region-reflective algorithm. The syntax for the interior-point algorithm is

W = HessMultFcn(x,lambda,v);

The result W should be the product H*v, where H is the Hessian at x, lambda is the Lagrange multiplier (computed by fmincon), and v is a vector. In contrast, the syntax for the trust-region-reflective algorithm does not involve lambda:

W = HessMultFcn(H,v);

Again, the result W = H*v. H is the function returned in the third output of the objective function (see Writing Objective Functions), and v is a vector. H does not have to be the Hessian; rather, it can be any function that enables you to calculate W = H*v.

Options

Optimization options used by fmincon. Some options apply to all algorithms, and others are relevant for particular algorithms. You can use optimset to set or change the values of these fields in the structure options. See Optimization Options for detailed information.

fmincon uses one of three algorithms: active-set, interior-point, or trust-region-reflective. You choose the algorithm at the command line with optimset. For example:

options=optimset('Algorithm','active-set');

The default trust-region-reflective (formerly called large-scale) requires:

If these conditions are not all satisfied, the 'active-set' algorithm (formerly called medium-scale) is the default.

The 'active-set' algorithm is not a large-scale algorithm.

All Algorithms

These options are used by all three algorithms:

Algorithm

Choose the optimization algorithm.

DerivativeCheck

Compare user-supplied derivatives (gradients of the objective and constraints) to finite-difference approximates.

Diagnostics

Display diagnostic information about the function to be minimized.

DiffMaxChange

Maximum change in variables for finite differencing.

DiffMinChange

Minimum change in variables for finite differencing.

Display

Level of display.

  • 'off' displays no output

  • 'iter' displays output at each iteration

  • 'notify' displays output only if the function does not converge

  • 'final' (default) displays just the final output

FunValCheck

Check whether objective function values are valid. 'on' displays an error when the objective function returns a value that is complex, Inf, or NaN. 'off' displays no error.

GradObj

Gradient for the objective function defined by the user. You must provide the gradient to use the trust-region-reflective method. This option is not required for the active-set and interior-point methods. See the preceding description of fun to see how to define the gradient in fun.

MaxFunEvals

Maximum number of function evaluations allowed.

MaxIter

Maximum number of iterations allowed.

OutputFcn

Specify one or more user-defined functions that an optimization function calls at each iteration. See Output Function.

PlotFcns

Plots various measures of progress while the algorithm executes, select from predefined plots or write your own.

  • @optimplotx plots the current point

  • @optimplotfunccount plots the function count

  • @optimplotfval plots the function value

  • @optimplotconstrviolation plots the maximum constraint violation

  • @optimplotstepsize plots the step size

  • @optimplotfirstorderopt plots the first-order of optimality

TolFun

Termination tolerance on the function value.

TolCon

Termination tolerance on the constraint violation.

TolX

Termination tolerance on x.

TypicalX

Typical x values.

Trust-Region-Reflective Algorithm

These options are used by the trust-region-reflective algorithm:

Hessian

If 'on', fmincon uses a user-defined Hessian (defined in fun), or Hessian information (when using HessMult), for the objective function. If 'off', fmincon approximates the Hessian using finite differences.

HessMult

Function handle for Hessian multiply function. For large-scale structured problems, this function computes the Hessian matrix product H*Y without actually forming H. The function is of the form

W = hmfun(Hinfo,Y)

where Hinfo contains a matrix used to compute H*Y.

The first argument must be the same as the third argument returned by the objective function fun, for example:

[f,g,Hinfo] = fun(x)

Y is a matrix that has the same number of rows as there are dimensions in the problem. W = H*Y, although H is not formed explicitly. fminunc uses Hinfo to compute the preconditioner. See Passing Extra Parameters for information on how to supply values for any additional parameters that hmfun needs.

    Note   'Hessian' must be set to 'on' for Hinfo to be passed from fun to hmfun.

See Example: Nonlinear Minimization with a Dense but Structured Hessian and Equality Constraints for an example.

 
HessPattern

Sparsity pattern of the Hessian for finite differencing. If it is not convenient to compute the sparse Hessian matrix H in fun, the trust-region-reflective method in fmincon can approximate H via sparse finite differences (of the gradient) provided that you supply the sparsity structure of H—i.e., locations of the nonzeros—as the value for HessPattern. In the worst case, if the structure is unknown, you can set HessPattern to be a dense matrix and a full finite-difference approximation is computed at each iteration (this is the default). This can be very expensive for large problems, so it is usually worth the effort to determine the sparsity structure.

 
MaxPCGIter

Maximum number of PCG (preconditioned conjugate gradient) iterations. For more information, see Preconditioned Conjugate Gradient Method.

 
PrecondBandWidth

Upper bandwidth of preconditioner for PCG. By default, diagonal preconditioning is used (upper bandwidth of 0). For some problems, increasing the bandwidth reduces the number of PCG iterations. Setting PrecondBandWidth to 'Inf' uses a direct factorization (Cholesky) rather than the conjugate gradients (CG). The direct factorization is computationally more expensive than CG, but produces a better quality step towards the solution.

 
TolPCG

Termination tolerance on the PCG iteration.

 

Active-Set Algorithm

These options are used only by the active-set algorithm:

FinDiffType

Finite differences, used to estimate gradients, are either 'forward' (the default), or 'central' (centered). 'central' takes twice as many function evaluations but should be more accurate.

The algorithm is careful to obey bounds when estimating both types of finite differences. So, for example, it may take a backward, rather than a forward, difference to avoid evaluating at a point outside bounds.

MaxSQPIter

Maximum number of SQP iterations allowed.

RelLineSrchBnd

Relative bound (a real nonnegative scalar value) on the line search step length such that the total displacement in x satisfies |Δx(i)| ≤ relLineSrchBnd· max(|x(i)|,|typicalx(i)|). This option provides control over the magnitude of the displacements in x for cases in which the solver takes steps that are considered too large.

RelLineSrchBndDuration

Number of iterations for which the bound specified in RelLineSrchBnd should be active (default is 1).

TolConSQP

Termination tolerance on inner iteration SQP constraint violation.

UseParallel

When 'always', estimate gradients in parallel. Disable by setting to 'never'.

Interior-Point Algorithm

These options are used by the interior-point algorithm:

AlwaysHonorConstraints

The default 'bounds' ensures that bound constraints are satisfied at every iteration. Disable by setting to 'none'.

FinDiffType

Finite differences, used to estimate gradients, are either 'forward' (the default), or 'central' (centered). 'central' takes twice as many function evaluations but should be more accurate.

The algorithm is careful to obey bounds when estimating both types of finite differences. So, for example, it may take a backward, rather than a forward, difference to avoid evaluating at a point outside bounds. However, 'central' differences might violate bounds during their evaluation if the AlwaysHonorConstraints option is set to 'none'.

HessFcn

Function handle to a user-supplied Hessian (see Hessian).

Hessian

Chooses how fmincon calculates the Hessian (see Hessian).

HessMult

Handle to a user-supplied function that gives a Hessian-times-vector product (see Hessian).

InitBarrierParam

Initial barrier value. Sometimes it might help to try a value above the default 0.1, especially if the objective or constraint functions are large.

InitTrustRegionRadius

Initial radius of the trust region. On badly scaled problems it might help to choose a value smaller than the default , where n is the number of variables.

MaxProjCGIter

A tolerance (stopping criterion) for the number of projected conjugate gradient iterations; this is an inner iteration, not the number of iterations of the algorithm.

ObjectiveLimit

A tolerance (stopping criterion). If the objective function value goes below ObjectiveLimit and the iterate is feasible, the iterations halt, since the problem is presumably unbounded.

ScaleProblem

The default obj-and-constr causes the algorithm to normalize all constraints and the objective function. Disable by setting to none.

SubproblemAlgorithm

Determines how the iteration step is calculated. The default ldl-factorization is usually faster than cg (conjugate gradient), though cg may be faster for large problems with dense Hessians.

TolProjCG

A relative tolerance (stopping criterion) for projected conjugate gradient algorithm; this is for an inner iteration, not the algorithm iteration.

TolProjCGAbs

Absolute tolerance (stopping criterion) for projected conjugate gradient algorithm; this is for an inner iteration, not the algorithm iteration.

Examples

Find values of x that minimize f(x) = –x1x2x3, starting at the point x = [10;10;10], subject to the constraints:

0 ≤ x1 + 2x2 + 2x3 ≤ 72.

  1. Write an M-file that returns a scalar value f of the objective function evaluated at x:

    function f = myfun(x)
    f = -x(1) * x(2) * x(3);
    
  2. Rewrite the constraints as both less than or equal to a constant,

    x1–2x2–2x3 ≤ 0
    x1 + 2x2 + 2x3≤ 72

  3. Since both constraints are linear, formulate them as the matrix inequality A·x ≤ b, where

  4. Supply a starting point and invoke an optimization routine:

    x0 = [10; 10; 10];    % Starting guess at the solution
    [x,fval] = fmincon(@myfun,x0,A,b)
    
  5. After 66 function evaluations, the solution is

    x =
        24.0000
        12.0000
        12.0000
    

    where the function value is

    fval =
        -3.4560e+03
    

    and linear inequality constraints evaluate to be less than or equal to 0:

    A*x-b= 
        -72
          0
    

Notes

Trust-Region-Reflective Optimization

To use the trust-region-reflective algorithm, you must

You cannot use inequality constraints with the trust-region-reflective algorithm. If the preceding conditions are not met, fmincon reverts to the active-set algorithm.

fmincon returns a warning if you do not provide a gradient and the Algorithm option is trust-region-reflective. fmincon permits an approximate gradient to be supplied, but this option is not recommended; the numerical behavior of most optimization methods is considerably more robust when the true gradient is used.

The trust-region-reflective method in fmincon is in general most effective when the matrix of second derivatives, i.e., the Hessian matrix H(x), is also computed. However, evaluation of the true Hessian matrix is not required. For example, if you can supply the Hessian sparsity structure (using the HessPattern option in options), fmincon computes a sparse finite-difference approximation to H(x).

If x0 is not strictly feasible, fmincon chooses a new strictly feasible (centered) starting point.

If components of x have no upper (or lower) bounds, fmincon prefers that the corresponding components of ub (or lb) be set to Inf (or -Inf for lb) as opposed to an arbitrary but very large positive (or negative in the case of lower bounds) number.

Take note of these characteristics of linearly constrained minimization:

Active-Set Optimization

If equality constraints are present and dependent equalities are detected and removed in the quadratic subproblem, 'dependent' appears under the Procedures heading (when you ask for output by setting the Display option to'iter'). The dependent equalities are only removed when the equalities are consistent. If the system of equalities is not consistent, the subproblem is infeasible and 'infeasible' appears under the Procedures heading.

Algorithm

Trust-Region-Reflective Optimization

The trust-region-reflective algorithm is a subspace trust-region method and is based on the interior-reflective Newton method described in [3] and [4]. Each iteration involves the approximate solution of a large linear system using the method of preconditioned conjugate gradients (PCG). See the trust-region and preconditioned conjugate gradient method descriptions in fmincon Trust Region Reflective Algorithm.

Active-Set Optimization

fmincon uses a sequential quadratic programming (SQP) method. In this method, the function solves a quadratic programming (QP) subproblem at each iteration. fmincon updates an estimate of the Hessian of the Lagrangian at each iteration using the BFGS formula (see fminunc and references [7] and [8]).

fmincon performs a line search using a merit function similar to that proposed by [6], [7], and [8]. The QP subproblem is solved using an active set strategy similar to that described in [5]. fmincon Active Set Algorithm describes this algorithm in detail.

See also SQP Implementation for more details on the algorithm used.

Interior-Point Optimization

This algorithm is described in [1], [41], and [9].

Limitations

fmincon is a gradient-based method that is designed to work on problems where the objective and constraint functions are both continuous and have continuous first derivatives.

When the problem is infeasible, fmincon attempts to minimize the maximum constraint value.

The trust-region-reflective algorithm does not allow equal upper and lower bounds. For example, if lb(2)==ub(2), fmincon gives this error:

Equal upper and lower bounds not permitted in this
large-scale method.
Use equality constraints and the medium-scale
method instead.

There are two different syntaxes for passing a Hessian, and there are two different syntaxes for passing a HessMult function; one for trust-region-reflective, and another for interior-point.

For trust-region-reflective, the Hessian of the Lagrangian is the same as the Hessian of the objective function. You pass that Hessian as the third output of the objective function.

For interior-point, the Hessian of the Lagrangian involves the Lagrange multipliers and the Hessians of the nonlinear constraint functions. You pass the Hessian as a separate function that takes into account both the position x and the Lagrange multiplier structure lambda.

Trust-Region-Reflective Coverage and Requirements

Additional Information NeededFor Large Problems

Must provide gradient for f(x) in fun.

  • Provide sparsity structure of the Hessian or compute the Hessian in fun.

  • The Hessian should be sparse.

  • Aeq should be sparse.

References

[1] Byrd, R.H., J. C. Gilbert, and J. Nocedal, "A Trust Region Method Based on Interior Point Techniques for Nonlinear Programming," Mathematical Programming, Vol 89, No. 1, pp. 149–185, 2000.

[2] Byrd, R.H., Mary E. Hribar, and Jorge Nocedal, "An Interior Point Algorithm for Large-Scale Nonlinear Programming, SIAM Journal on Optimization," SIAM Journal on Optimization, Vol 9, No. 4, pp. 877–900, 1999.

[3] Coleman, T.F. and Y. Li, "An Interior, Trust Region Approach for Nonlinear Minimization Subject to Bounds," SIAM Journal on Optimization, Vol. 6, pp. 418–445, 1996.

[4] Coleman, T.F. and Y. Li, "On the Convergence of Reflective Newton Methods for Large-Scale Nonlinear Minimization Subject to Bounds," Mathematical Programming, Vol. 67, Number 2, pp. 189–224, 1994.

[5] Gill, P.E., W. Murray, and M.H. Wright, Practical Optimization, London, Academic Press, 1981.

[6] Han, S.P., "A Globally Convergent Method for Nonlinear Programming," Vol. 22, Journal of Optimization Theory and Applications, p. 297, 1977.

[7] Powell, M.J.D., "A Fast Algorithm for Nonlinearly Constrained Optimization Calculations," Numerical Analysis, ed. G.A. Watson, Lecture Notes in Mathematics, Springer Verlag, Vol. 630, 1978.

[8] Powell, M.J.D., "The Convergence of Variable Metric Methods For Nonlinearly Constrained Optimization Calculations," Nonlinear Programming 3 (O.L. Mangasarian, R.R. Meyer, and S.M. Robinson, eds.), Academic Press, 1978.

[9] Waltz, R. A., J. L. Morales, J. Nocedal, and D. Orban, "An interior algorithm for nonlinear optimization that combines line search and trust region steps," Mathematical Programming, Vol 107, No. 3, pp. 391–408, 2006.

See Also

@ (function_handle), fminbnd, fminsearch, fminunc, optimset, optimtool

For more details about the fmincon algorithms, see Constrained Nonlinear Optimization. For more examples of nonlinear programming with constraints, see Constrained Nonlinear Optimization Examples.

  


 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS