On this page:
<require>
<provide>
3.2.1 The objective matrix
<P>
3.2.2 Constraints
<matrix>
<solve>
<run-example>
<*>

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 scs)

(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 — zero-cone rows first, then positive-orthant rows — matching the make-cone keywords:

(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 #: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))

(define (run-example)
  <P>
  <matrix>
  <solve>)

Running it.

(scs-result-x (run-example))      ; #(0.3 -0.7)
(scs-result-pobj (run-example))   ; the optimal objective value

<*> ::=