3.2 Quadratic program
A quadratic program adds a quadratic term to the objective. We solve
minimize ½ xᵀP x + cᵀx
subject to −x₀ + x₁ = −1
x₀ ≤ 0.3, x₁ ≤ −0.5
with P = [[3 −1] [−1 2]] and c = (−1, −1); the optimum is x = (0.3, −0.7). This is the linear program of Linear program plus a #:P matrix and one equality (zero cone) row.
<require> ::=
(require scs)
<provide> ::=
(provide run-example)
3.2.1 The objective matrix
SCS reads P as a symmetric matrix but only needs its upper triangle, which scs:sparse-matrix takes as (row col value) triples. Here that is P₀₀ = 3, P₀₁ = −1, P₁₁ = 2:
<P> ::=
(define P (scs:sparse-matrix 2 2 '(0 0 3) '(0 1 -1) '(1 1 2)))
3.2.2 Constraints
The first row is the equality −x₀ + x₁ = −1; the next two are the upper
bounds x₀ ≤ 0.3 and x₁ ≤ −0.5. The rows must appear in cone order —
<matrix> ::=
(define A (scs:matrix 3 2 -1 1 ; -x0 + x1 = -1 (zero cone) 1 0 ; x0 <= 0.3 (positive) 0 1)) ; x1 <= -0.5 (positive)
<solve> ::=
(solve #:A A #:b #(-1.0 0.3 -0.5) #:c #(-1.0 -1.0) #:P P #:cone (make-cone #:zero 1 #:positive 2) #:settings (make-settings #:eps-abs 1e-9 #:eps-rel 1e-9))
<run-example> ::=
Running it.
(scs-result-x (run-example)) ; #(0.3 -0.7) (scs-result-pobj (run-example)) ; the optimal objective value
<*> ::=