x = fmincon(fun, x0, A, b)
x = fmincon(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options)
[x, fval, exitflag, output, lambda, grad, hessian] = fmincon(___)
x = fmincon(problem)
| Parameter | Description |
|---|---|
| fun | objective function returning a real scalar. |
| x0 | initial point. |
| A, b | linear inequalities A*x <= b. |
| Aeq, beq | linear equalities Aeq*x = beq. |
| lb, ub | lower and upper bounds. |
| nonlcon | nonlinear constraint function returning c and ceq. |
| options | solver options created with optimoptions or optimset. |
| Parameter | Description |
|---|---|
| x | computed minimizer. |
| fval | objective value at x. |
| exitflag | termination indicator. |
| output | diagnostic structure. |
| lambda | Lagrange multiplier structure. |
| grad | objective gradient at x. |
| hessian | approximate Hessian of the Lagrangian. |
fmincon solves constrained nonlinear minimization problems with linear constraints, bounds and nonlinear constraints.
The sqp path solves quadratic subproblems with active linearized constraints, BFGS Hessian updates and merit-function line search. Nonlinear constraints are handled directly in the SQP subproblem through finite-difference or user-supplied Jacobians.
The interior-point path builds an interior starting point with logarithmic barrier continuation before entering the nonlinear SQP phase. The active-set path keeps an explicit working set and reports active linear rows in output.activeconstraints. The sqp-legacy path uses a separate conservative SQP loop with active-set subproblems and stricter merit decrease.
For badly scaled problems, set ScaleProblem to obj-and-constr and provide TypicalX. Nelson scales SQP subproblems, initializes the Hessian with the variable scales and applies scaled merit decrease tests.
If nonlinear SQP cannot recover feasibility, Nelson runs a restoration phase based on penalty continuation and reports output.restoration when that phase supplies the returned point.
The trust-region-reflective path supports bound and linear-equality problems with user gradients, Hessian matrices, Hessian callbacks or Hessian multiply callbacks, projected truncated conjugate gradients, diagonal or band preconditioning, and trust-region radius updates. The output structure includes conjugate-gradient diagnostics such as pcgflag, pcgresidual and trustregionradius.
Accepted display modes include off, none, final, final-detailed, notify, notify-detailed, iter and iter-detailed. Setting Diagnostics to on prints a summary of variables, functions, constraints and selected algorithm before solving.
Default options depend on the algorithm: interior-point uses MaxIterations 1000, MaxFunctionEvaluations 3000, StepTolerance 1e-10 and SubproblemAlgorithm 'factorization'; the other algorithms use MaxIterations 400, MaxFunctionEvaluations '100*numberOfVariables' and StepTolerance 1e-6.
The exitflag output reports 1 (first-order optimality satisfied), 2 (step below StepTolerance), 3 (objective change below FunctionTolerance, trust-region-reflective), 0 (iteration or evaluation limit), -1 (stopped by output function), -2 (no feasible point found) or -3 (objective below ObjectiveLimit).
function [c, ceq] = unitdisk(x)
c = x(1)^2 + x(2)^2 - 1;
ceq = [];
end
fun = @(x) 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
opts = optimoptions('fmincon', 'Display', 'off', 'Algorithm', 'sqp');
[x, fval] = fmincon(fun, [0; 0], [], [], [], [], [], [], @unitdisk, opts)
fun = @(x) 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
A = [1 2];
b = 1;
[x, fval, exitflag] = fmincon(fun, [-1; 2], A, b)
function [f, g] = quadobj(x)
f = (x(1) - 1)^2 + (x(2) - 2)^2;
g = [2*(x(1) - 1); 2*(x(2) - 2)];
end
opts = optimoptions('fmincon', 'Display', 'off', 'Algorithm', 'trust-region-reflective', ...
'SpecifyObjectiveGradient', true, 'Hessian', 2*eye(2));
[x, fval] = fmincon(@quadobj, [0; 0], [], [], [], [], [0; 0], [3; 3], [], opts)
function [f, g] = quadobj(x)
f = (x(1) - 1)^2 + (x(2) - 2)^2;
g = [2*(x(1) - 1); 2*(x(2) - 2)];
end
function y = quadhessmult(x, v)
y = 2*v;
end
opts = optimoptions('fmincon', 'Display', 'off', 'Algorithm', 'trust-region-reflective', ...
'SpecifyObjectiveGradient', true, 'HessianMultiplyFcn', @quadhessmult);
[x, fval] = fmincon(@quadobj, [0; 0], [], [], [], [], [0; 0], [3; 3], [], opts)
| Version | Description |
|---|---|
| 2.0.0 | initial version |