# fmincon

Find the constrained minimum of a real function.

## Syntax

x = fmincon(@func,x0)

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

x = fmincon(@func,x0,A,b,Aeq,beq)

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

x = fmincon(@func,x0,A,b,Aeq,beq,lb,ub,nonlcon)

x = fmincon(@func,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

[x,fval,info,output] = fmincon(...)

## Inputs

`func`- The function to minimize. See the optimset option GradObj for details.
`x0`- An estimate of the location of the minimum.
`A`- A matrix used to compute
`A*x`

for inequality constraints. `b`- The upper bound of the inequality constraints
`A*x<=b.`

`Aeq`- A matrix used to compute
`Aeq*x`

for equality constraints. `beq`- The upper bound of the equality constraints
`Aeq*x=beq`

. `lb`- The design variable lower bounds.
`ub`- The design variable upper bounds.
`nonlcon`- The non-linear constraints function.
`options`- A struct containing option settings.

## Outputs

- x
- The location of the function minimum.
- fval
- The minimum of the function.
- info
- The convergence status flag.
- info = 3:
- Converged with a constraint violation within TolCon.
- info = 1
- Function value converged to within TolX or TolKKT.
- info = 0
- Reached maximum number of iterations or function calls, or the algorithm aborted because it was not converging.
- info = -2
- The function did not converge.

- output
- A struct containing iteration details. The members are as follows:
- iterations
- The number of iterations.
- nfev
- The number of function evaluations.
- xiter
- The candidate solution at each iteration.
- fvaliter
- The objective function value at each iteration.
- coniter
- The constraint values at each iteration. The columns contain the constraint function values in the following order: linear inequality contraints, linear equality constraints, nonlinear inequality contraints, nonlinear equality constraints.

## Examples

Minimize the function ObjFunc, subject to the linear inequality constraint: x1 + 4*x2 > 27.

```
function obj = ObjFunc(x)
obj = 2*(x(1)-3)^2 - 5*(x(1)-3)*(x(2)-2) + 4*(x(2)-2)^2 + 6;
end
init = [8, 6]; % initial estimate
A = [-1, -4]; % inequality contraint matrix
b = [-27]; % inequality contraint bound
lb = [-10, -10]; % lower variable bounds
ub = [10, 10]; % upper variable bounds
[x,fval] = fmincon(@ObjFunc,init,A,b,[],[],lb,ub)
```

```
x = [Matrix] 1 x 2
7.00244 4.99939
fval = 14.0000209
```

```
function obj = ObjFunc(x,offset)
obj = 2*(x(1)-3)^2 - 5*(x(1)-3)*(x(2)-2) + 4*(x(2)-2)^2 + offset;
end
handle = @(x) ObjFunc(x,7);
[x,fval] = fmincon(handle,init,A,b,[],[],lb,ub)
```

```
x = [Matrix] 1 x 2
7.00244 4.99939
fval = 15.0000209
```

## Comments

fmincon uses a Sequential Quadratic Programming algorithm and a line search method.

Options for convergence tolerance controls and analytical derivatives are specified with optimset.

If large `lb` and `ub` values are specified, then it is
essential to use option TolX in optimset. The default
TolX will likely be too large, since it is applied relative to the
interval size.

The unbounded `lb` and `ub` options are not fully
supported due to their relationship to the TolX. The unbounded options are
set to -1000 and 1000, respectively.

To pass additional parameters to a function argument, use an anonymous function.

See the optimization tutorial for an example with nonlinear constraints.

- MaxIter: 400
- MaxFunEvals: 1,000,000
- MaxFail: 20,000
- TolX: 1.0e-3
- TolCon: 0.5%
- TolKKT: 1.0e-4
- GradObj: 'off'
- GradConstr: 'off'
- Display: 'off'