9.2.0.5

3 Examples🔗ℹ

Each example below is a literate program: the prose and the code you see are the same source that lives in the package’s "scs/examples/" directory and is exercised by the test suite, so the walkthroughs never drift from working code. Every example provides a run-example thunk; its companion harness in "scs/examples/test/" drives it and checks the result (run with raco test).

The examples build up in three arcs. The foundations (Linear program through Power cone) introduce one cone family at a time through the high-level solve interface: a linear program, then a quadratic objective, then the second-order, exponential, semidefinite, and power cones. The solver mechanics (Indirect solver, Warm starting and re-solving) cover choosing the indirect linear-system solver and reusing a workspace across re-solves. The applications (Lasso along a regularization path through Model predictive control) assemble those pieces into recognizable models — regression, classification, finance, and control.

    3.1 Linear program

    3.2 Quadratic program

      3.2.1 The objective matrix

      3.2.2 Constraints

    3.3 Second-order cone

      3.3.1 Encoding cone membership

    3.4 Exponential cone

    3.5 Semidefinite program

      3.5.1 The svec scaling

    3.6 Power cone

    3.7 Indirect solver

      3.7.1 Choosing the indirect solver

    3.8 Warm starting and re-solving

      3.8.1 Building the solver

      3.8.2 Solve, update, re-solve

    3.9 Lasso along a regularization path

      3.9.1 The fixed data: P, constraints, and c(λ)

      3.9.2 Sweeping the path

    3.10 Elastic net regression

      3.10.1 From the objective to a quadratic program

      3.10.2 Small matrix helpers

      3.10.3 Assembling and solving

    3.11 Maximum entropy

      3.11.1 Epigraph form via the exponential cone

    3.12 Support vector machine

      3.12.1 Variables and standard form

    3.13 Portfolio optimization

    3.14 Model predictive control

      3.14.1 Objective and dynamics

      3.14.2 The box cone for input bounds

      3.14.3 Receding horizon