quadprog

Syntax

quadprog(H, f, [A], [b], [Aeq], [beq])

Arguments

A is the coefficient matrix of linear inequality constraints.

b is the the right-hand-side vector of the linear inequality constraint.

Aeq is a linear equality constraint coefficient matrix.

beq is the the right-hand-side vector of the linear equality constraint.

H, A and Aeq must be matrices with the same number of columns.

f, b and beq are vectors.

Details

Solve the following optimization problem with a quadratic objective function and a set of linear constraints.

\(\min_x\dfrac{1}{2}x^THx + f^T x\text{ such that}\begin{cases}A\cdot x\le b\\Aeq \cdot x=beq\end{cases}\)

The result is a 2-element tuple. The first element is the minimum value of the objective function. The second element is the value of x where the value of the objective function is minimized.

Examples

Example 1: Find the minimum of

\(x_1^2 + 3x_2^2 - 2x_1x_2 - 5x_1 + 4x_2\)

$ H=matrix([2 -2,-2 6])
$ f=[-5,4]
$ x=quadprog(H,f);

$ x[0];
-6.375

$ x[1];
[2.75,0.25]

Example 2: Find the minimum of

\(x_1^2 + 3x_2^2 - 2x_1x_2 - 5x_1 + 4x_2\)

subject to the constraints of

\(x_1 + x_2\le 10\)

\(-x_1 + 3x_2\le 8\)

\(6x_1 + x_2\le 5\)

$ H=matrix([2 -2,-2 6])
$ f=[-5,4]
$ A=matrix([1 -1 6, 1 3 1])
$ b=[10, 8, 5]
$ x=quadprog(H,f,A,b);

$ x[0];
-4.092975

$ x[1];
[0.904959, -0.429752]

Example 3: Find the minimum of

\(x_1^2 + 3x_2^2 - 2x_1x_2 - 5x_1 + 4x_2\)

subject to the constraints of

\(x_1 + x_2\le 10\)

\(-x_1 + 3x_2\le 8\)

\(6x_1 + x_2\le 5\)

\(x_1 + 2x_2=1\)

$ H=matrix([2 -2,-2 6])
$ f=[-5,4]
$ A=matrix([1 -1 6, 1 3 1])
$ b=[10, 8, 5]
$ Aeq=matrix([1],[2])
$ beq=[1]
$ x=quadprog(H,f,A,b,Aeq,beq);

$ x[0];
-3.181818

$ x[1];
[0.818182,0.090909]

The 3 examples above share the same objective function. Example 1 has no constaints and achieves the lowest minimum value. Example 3 has more constaints than example 2 and therefore can only achieve a higher minimum value than both example 2 and example 1.