quadprog

Find the constrained minimum of a real quadratic function.

Syntax

x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0)

x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0,options)

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

Inputs

H
A symmetrix matrix in the quadratic component of, 0.5*x'Hx + f'x.
f
A column vector in the linear component of, 0.5*x'Hx + f'x.
A
A matrix used to compute A*x for inequality constraints.
Use [ ] if unneeded.
b
The upper bound of the inequality constraints A*x<=b.
Use [ ] if unneeded.
Aeq
A matrix used to compute Aeq*x for equality constraints.
Use [ ] if unneeded.
beq
The upper bound of the equality constraints Aeq*x=beq.
Use [ ] if unneeded.
lb
The design variable lower bounds.
Use [ ] if unbounded. Support for this option is limited. See Comments.
ub
The design variable upper bounds.
Use [ ] if unbounded. Support for this option is limited. See Comments.
x0
An estimate of the location of the minimum.
options
A struct containing option settings.
See optimset for details.

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 constraints, linear equality constraints.

Examples

Minimize the function 0.5*x'Hx + f'x, subject to the linear inequality constraints: Ax < b.

H = [4 -5; -5 8];
f = [-2; -1];
A = [-1, -3; -1, -5];
b = [-22; -32];
lowerBound = [-10; -10];
upperBound = [10; 10];
init = [8; 6];
[x,fval,info] = quadprog(H,f,A,b,[],[],lowerBound,upperBound,init)
x = [Matrix] 2 x 1 7.00000 5.00000 fval = 4 info = 1 

The function is implemented through an SQP algorithm. A specific QP algorithm will be more efficient when available.

If large lb and ub values are specified then it is essential to use option TolX in optimset. The default TolX is likely 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 TolX. The unbounded options are defaulted to -1000 and 1000, respectively.

The optimset options and defaults are as follows:

  • MaxIter: 400
  • MaxFunEvals: 1,000,000
  • MaxFail: 20,000
  • TolX: 1.0e-7
  • TolCon: 0.5%
  • TolKKT: 1.0e-7
  • Display: 'off'