Quadratic programming
x = quadprog(H,f)
x = quadprog(H,f,A,b)
x = quadprog(H,f,A,b,Aeq,beq)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0,options)
x = quadprog(problem)
[x,fval]
= quadprog(H,f,...)
[x,fval,exitflag]
= quadprog(H,f,...)
[x,fval,exitflag,output]
= quadprog(H,f,...)
[x,fval,exitflag,output,lambda]
= quadprog(H,f,...)
Finds a minimum for a problem specified by
H, A, and Aeq are matrices, and f, b, beq, lb, ub, and x are vectors.
f, lb, and ub can be passed as vectors or matrices; see Matrix Arguments.
returns
a vector x
= quadprog(H
,f
)x
that minimizes 1/2*x'*H*x + f'*x
. H
must
be positive definite for the problem to have a finite minimum.
minimizes x
= quadprog(H
,f
,A
,b
)1/2*x'*H*x + f'*x
subject to the restrictions A*x
≤ b
. A
is
a matrix of doubles, and b
is a vector of doubles.
solves
the preceding problem subject to the additional restrictions x
= quadprog(H
,f
,A
,b
,Aeq
,beq
)Aeq*x = beq
. Aeq
is
a matrix of doubles, and beq
is a vector of doubles.
If no inequalities exist, set A = []
and b = []
.
solves
the preceding problem subject to the additional restrictions x
= quadprog(H
,f
,A
,b
,Aeq
,beq
,lb
,ub
)lb
≤ x
≤ ub
. lb
and ub
are
vectors of doubles, and the restrictions hold for each x
component.
If no equalities exist, set Aeq = []
and beq = []
.
Note:
If the specified input bounds for a problem are inconsistent,
the output
|
solves
the preceding problem starting from the vector x
= quadprog(H
,f
,A
,b
,Aeq
,beq
,lb
,ub
,x0
)x0
.
If no bounds exist, set lb = []
and ub = []
. Some quadprog
algorithms
ignore x0
, see Input Arguments.
solves
the preceding problem using the optimization options specified in x
= quadprog(H
,f
,A
,b
,Aeq
,beq
,lb
,ub
,x0
,options
)options
.
Use optimoptions
to create options
.
If you do not want to give an initial point, set x0 = []
.
returns
the minimum for x
= quadprog(problem
)problem
, where problem
is
a structure described in Input Arguments.
Create problem
by exporting a problem using the
Optimization app; see Exporting Your Work.
[
returns
the value of the objective function at x
,fval
]
= quadprog(H
,f
,...)x
:
fval = 0.5*x'*H*x + f'*x
[
x
,fval
,exitflag
]
= quadprog(H
,f
,...)exitflag
,
a scalar that describes the exit condition of quadprog
.
[
x
,fval
,exitflag
,output
]
= quadprog(H
,f
,...)output
,
a structure that contains information about the optimization.
[
x
,fval
,exitflag
,output
,lambda
]
= quadprog(H
,f
,...)lambda
,
a structure whose fields contain the Lagrange multipliers at the solution x
.
|
Symmetric matrix of doubles. Represents the quadratic in the
expression | ||||||||||||||||||||||||
|
Vector of doubles. Represents the linear term in the expression | ||||||||||||||||||||||||
|
Matrix of doubles. Represents the linear coefficients in the
constraints | ||||||||||||||||||||||||
|
Vector of doubles. Represents the constant vector in the constraints | ||||||||||||||||||||||||
|
Matrix of doubles. Represents the linear coefficients in the
constraints | ||||||||||||||||||||||||
|
Vector of doubles. Represents the constant vector in the constraints | ||||||||||||||||||||||||
|
Vector of doubles. Represents the lower bounds elementwise in | ||||||||||||||||||||||||
|
Vector of doubles. Represents the upper bounds elementwise in | ||||||||||||||||||||||||
|
Vector of doubles. Optional. The initial point for some
If you do not give | ||||||||||||||||||||||||
|
Options created using All Algorithms
All Algorithms Except active-set
trust-region-reflective Algorithm Only
interior-point-convex Algorithm Only
| ||||||||||||||||||||||||
|
Structure encapsulating the
|
|
Vector that minimizes | ||||||||||||||||||||||||||
|
Value of | ||||||||||||||||||||||||||
|
Integer identifying the reason the algorithm terminated. The
following lists the values of
| ||||||||||||||||||||||||||
|
Structure containing information about the optimization. The fields are:
| ||||||||||||||||||||||||||
|
Structure containing the Lagrange multipliers at the solution
For details, see Lagrange Multiplier Structures. |
Solve a simple quadratic programming problem: find values of x
that
minimize
subject to
x1 + x2 ≤
2
–x1 +
2x2 ≤ 2
2x1 + x2 ≤
3
0 ≤ x1,
0 ≤ x2.
In matrix notation this is
where
Enter the coefficient matrices:
H = [1 -1; -1 2]; f = [-2; -6]; A = [1 1; -1 2; 2 1]; b = [2; 2; 3]; lb = zeros(2,1);
Set the options to use the 'interior-point-convex'
algorithm
with no display:
options = optimoptions('quadprog',... 'Algorithm','interior-point-convex','Display','off');
Call quadprog
:
[x,fval,exitflag,output,lambda] = ... quadprog(H,f,A,b,[],[],lb,[],[],options);
Examine the final point, function value, and exit flag:
x,fval,exitflag x = 0.6667 1.3333 fval = -8.2222 exitflag = 1
An exit flag of 1
means the result
is a local minimum. Because H
is a positive definite
matrix, this problem is convex, so the minimum is a global minimum.
You can see H
is positive definite by noting all
its eigenvalues are positive:
eig(H) ans = 0.3820 2.6180
Use the 'interior-point-convex'
algorithm to solve
a sparse quadratic program.
Generate a sparse symmetric matrix for the quadratic form:
v = sparse([1,-.25,0,0,0,0,0,-.25]); H = gallery('circul',v);
Include the linear term for the problem:
f = -4:3;
Include the constraint that the sum of the terms in
the solution x
must be less than -2
:
A = ones(1,8);b = -2;
Set options to use the 'interior-point-convex'
algorithm
and iterative display:
opts = optimoptions('quadprog',... 'Algorithm','interior-point-convex','Display','iter');
Run the quadprog
solver and observe
the iterations:
[x fval eflag output lambda] = quadprog(H,f,A,b,[],[],[],[],[],opts); First-order Total relative Iter f(x) Feasibility optimality error 0 -2.000000e+000 1.000e+001 4.500e+000 1.200e+001 1 -2.630486e+001 0.000e+000 9.465e-002 9.465e-002 2 -2.639877e+001 0.000e+000 3.914e-005 3.914e-005 3 -2.639881e+001 0.000e+000 3.069e-015 6.883e-015 Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the default value of the function tolerance, and constraints are satisfied to within the default value of the constraint tolerance.
Examine the solution:
fval,eflag fval = -26.3988 eflag = 1
For the 'interior-point-convex'
algorithm, an exit
flag of 1
means the result is a global minimum.
You can use the Optimization app for quadratic programming.
Enter optimtool
at the MATLAB® command line,
and choose the quadprog - Quadratic programming
solver.
For more information, see Optimization App.
[1] Coleman, T.F. and Y. Li, "A Reflective Newton Method for Minimizing a Quadratic Function Subject to Bounds on Some of the Variables," SIAM Journal on Optimization, Vol. 6, Number 4, pp. 1040–1058, 1996.
[2] Gill, P. E., W. Murray, and M. H. Wright, Practical Optimization, Academic Press, London, UK, 1981.
[3] Gould, N. and P. L. Toint. "Preprocessing for quadratic programming." Math. Programming, Series B, Vol. 100, pp. 95–132, 2004.