Find a minimum of a constrained nonlinear multivariable function
where 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.
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(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options,P1,P2, ...) [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(...)
fmincon finds 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)
x0 and finds a minimum
x to 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)
fun subject to the linear equalities
Aeq*x = beq as well as
A*x <= b. Set
b= if no inequalities exist.
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
defines a set of lower and upper bounds on the design variables,
x, so that the solution is always in the range
lb <= x <= ub. Set
beq= if no equalities exist.
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
fmincon optimizes such that
c(x) <= 0 and
ceq(x) = 0. Set
ub= if no bounds exist.
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
minimizes with the optimization parameters specified in the structure
optimset to set these parameters.
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options,P1,P2,...)
passes the problem-dependent parameters
P2, etc., directly to the functions
nonlcon. Pass empty matrices as placeholders for
options if these arguments are not needed.
[x,fval] = fmincon(...)
returns the value of the objective function
fun at the solution
[x,fval,exitflag] = fmincon(...)
returns a value
exitflag that describes the exit condition of
[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,fval,exitflag,output,lambda,grad] = fmincon(...)
returns the value of the gradient of
fun at the solution
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(...)
returns the value of the Hessian of
fun at the solution
Function Arguments contains general descriptions of arguments passed in to
fmincon. This "Arguments" section provides function-specific details for
||The function to be minimized.
If the gradient of
then the function
If the Hessian matrix can also be computed and the
||The function that computes the nonlinear inequality constraints
||Options provides the function-specific details for the
Function Arguments contains general descriptions of arguments returned by
fmincon. This section provides function-specific details for
||Describes the exit condition:|
||The function converged to a solution
||The maximum number of function evaluations or iterations was exceeded.
||The function did not converge to a solution.
||Structure containing the Lagrange multipliers at the solution |
||Structure containing information about the optimization. The fields of the structure are:|
||Number of iterations taken.
||Number of function evaluations.
||Number of PCG iterations (large-scale algorithm only).
||Final step size taken (medium-scale algorithm only).
||Measure of first-order optimality (large-scale algorithm only).
For large-scale bound constrained problems, the first-order optimality is the infinity norm of
For large-scale problems with only linear equalities, the first-order optimality is the infinity norm of the projected gradient (i.e. the gradient projected onto the nullspace of
Optimization options parameters used by
fmincon. Some parameters apply to all algorithms, some are only relevant when using the large-scale algorithm, and others are only relevant when using the medium-scale algorithm.You can use
optimset to set or change the values of these fields in the parameters structure,
options. See Optimization Parameters, for detailed information.
We start by describing the
LargeScale option since it states a preference for which algorithm to use. It is only a preference since certain conditions must be met to use the large-scale algorithm. For
fmincon, you must provide the gradient (see the description of
fun above to see how) or else the medium-scale algorithm is used:
||Use large-scale algorithm if possible when set to
Medium-Scale and Large-Scale Algorithms. These parameters are used by both the medium-scale and large-scale algorithms:
||Print diagnostic information about the function to be minimized.
||Level of display.
||Gradient for the objective function defined by user. See the description of
||Maximum number of function evaluations allowed.
||Maximum number of iterations allowed.
||Termination tolerance on the function value.
||Termination tolerance on the constraint violation.
||Termination tolerance on
Large-Scale Algorithm Only. These parameters are used only by the large-scale algorithm:
||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
[f,g,Hinfo] = fun(x,p1,p2,...)
See Nonlinear Minimization with a Dense but Structured Hessian and Equality Constraints for an example.
||Sparsity pattern of the Hessian for finite-differencing. If it is not convenient to compute the sparse Hessian matrix
||Maximum number of PCG (preconditioned conjugate gradient) iterations (see the Algorithm section below).
||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.
||Termination tolerance on the PCG iteration.
Medium-Scale Algorithm Only. These parameters are used only by the medium-scale algorithm:
||Compare user-supplied derivatives (gradients of the objective and constraints) to finite-differencing derivatives.
||Maximum change in variables for finite-difference gradients.
||Minimum change in variables for finite-difference gradients.
Find values of x that minimize , starting at the point
x = [10; 10; 10] and subject to the constraints
First, write an M-file that returns a scalar value
f of the function evaluated at
Then rewrite the constraints as both less than or equal to a constant,
Since both constraints are linear, formulate them as the matrix inequality where
Next, supply a starting point and invoke an optimization routine.
After 66 function evaluations, the solution is
where the function value is
and linear inequality constraints evaluate to be
Large-Scale Optimization. To use the large-scale method, the gradient must be provided in
fun (and the
GradObj parameter is set to
'on'). A warning is given if no gradient is provided and the
LargeScale parameter is not
'off'. The function
fmincon permits g(x) to be an approximate gradient but this option is not recommended; the numerical behavior of most optimization codes is considerably more robust when the true gradient is used.
The large-scale method in
fmincon is 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 parameter in
fmincon computes a sparse finite-difference approximation to H(x).
x0 is not strictly feasible,
fmincon chooses a new strictly feasible (centered) starting point.
If components of x have no upper (or lower) bounds, then
fmincon prefers that the corresponding components of
lb) be set to
lb) as opposed to an arbitrary but very large positive (or negative in the case of lower bounds) number.
Several aspects of linearly constrained minimization should be noted:
Aeqcan result in considerable fill and computational cost.
fminconremoves (numerically) linearly dependent rows in
Aeq; however, this process involves repeated matrix factorizations and therefore can be costly if there are many dependencies.
Medium-Scale Optimization. Better numerical results are likely if you specify equalities explicitly using
beq, instead of implicitly using
If equality constraints are present and dependent equalities are detected and removed in the quadratic subproblem,
'dependent' is printed under the
Procedures heading (when you ask for output by setting the
Display parameter 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' is printed under the
Large-Scale Optimization. By default
fmincon will choose the large-scale algorithm if the user supplies the gradient in
options) and if only upper and lower bounds exist or only linear equality constraints exist. This algorithm is a subspace trust region method and is based on the interior-reflective Newton method described in , . 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 the Large-Scale Algorithms chapter.
fmincon uses a Sequential Quadratic Programming (SQP) method. In this method, a Quadratic Programming (QP) subproblem is solved at each iteration. An estimate of the Hessian of the Lagrangian is updated at each iteration using the BFGS formula (see
fminunc, references , ).
A line search is performed using a merit function similar to that proposed by , , and . The QP subproblem is solved using an active set strategy similar to that described in . A full description of this algorithm is found in Constrained Optimization in "Introduction to Algorithms."
See also SQP Implementation in "Introduction to Algorithms" for more details on the algorithm used.
Large-Scale Optimization. The large-scale code does not allow equal upper and lower bounds. For example if
fmincon gives the error
If you only have equality constraints you can still use the large-scale method. But if you have both equalities and bounds, you must use the medium-scale method.
The function to be minimized and the constraints must both be continuous.
fmincon may only give local solutions.
When the problem is infeasible,
fmincon attempts to minimize the maximum constraint value.
The objective function and constraint function must be real-valued, that is they cannot return complex values.
Large-Scale Optimization. To use the large-scale algorithm, the user must supply the gradient in
GradObj must be set
options) , and only upper and lower bounds constraints may be specified, or only linear equality constraints must exist and
Aeq cannot have more rows than columns.
Aeq is typically sparse. See Table 2-4, Large-Scale Problem Coverage and Requirements,, for more information on what problem formulations are covered and what information must be provided.
Currently, if the analytical gradient is provided in
DerivativeCheck cannot be used with the large-scale method to compare the analytic gradient to the finite-difference gradient. Instead, use the medium-scale method to check the derivative with
MaxIter set to 0 iterations. Then run the problem with the large-scale method.
 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.
 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.
 Gill, P.E., W. Murray, and M.H. Wright, Practical Optimization, Academic Press, London, 1981.
 Han, S.P., "A Globally Convergent Method for Nonlinear Programming," Journal of Optimization Theory and Applications, Vol. 22, p. 297, 1977.
 Powell, M.J.D., "A Fast Algorithm for Nonlineary Constrained Optimization Calculations," Numerical Analysis, ed. G.A. Watson, Lecture Notes in Mathematics, Springer Verlag, Vol. 630, 1978.
 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.