MATLAB
After installing you can call
[x, y, s, info] = scs(data, cones, settings)
where data is a struct containing P, A, b, c, P, A must
be sparse matrices, settings is a struct containing solver
Settings (missing settings are set to the defaults), and cones is
a struct that contains the Cones information. The cone struct
contains members corresponding to the cone type and values corresponding to either
the cone length or the array that defines the cone (see the third column in
Cones for the keys and what the corresponding values represent). At
termination x, y, s contains the primal-dual solution or the certificate of infeasibility, and
info is a struct containing the solve Return information.
Warm-starting
Warm-starting SCS with a guess of the primal-dual solution can reduce the total
solve time. This is useful, for example, when solving several similar problems
sequentially. To do this add to the data struct passed to scs
the additional fields x, y, and s (or any subset
thereof) where x and s correspond to the primal solution guesses
and y corresponds to the dual solution guess.
Solver backends
By default SCS uses the sparse direct (LDL) solver. Alternative backends can be
selected via the settings struct:
settings.use_indirect = true; % conjugate gradient solver
settings.dense = true; % dense Cholesky (best for dense A)
settings.gpu = true; % GPU solver
Spectral cones
The MATLAB interface is compiled with spectral cone
support enabled by default. This includes log-determinant, nuclear norm,
\(\ell_1\) norm, and sum-of-largest-eigenvalues cones. Set the
corresponding fields in the cones struct (e.g., cones.d,
cones.nuc_m, cones.nuc_n, cones.ell1,
cones.sl_n, cones.sl_k) as described in the spectral
cones documentation.
Note
Spectral cones are experimental — the API may change in future releases.
Workspace reuse
When solving a sequence of problems where only b and/or c change
(e.g., MPC, parameter sweeps), you can avoid re-factorizing by using the
workspace API:
% Initialize workspace (factorizes A and P)
work = scs_init(data, cones, settings);
% Solve
[x, y, s, info] = scs_solve(work);
% Update b and/or c without re-factorizing (pass [] to leave unchanged)
scs_update(work, b_new, c_new);
% Re-solve with the updated data
[x, y, s, info] = scs_solve(work);
% Warm-start a re-solve
warm.x = x; warm.y = y; warm.s = s;
[x, y, s, info] = scs_solve(work, warm);
% Free workspace when done
scs_finish(work);
This corresponds to the C API functions scs_init, scs_solve,
scs_update, and scs_finish. The workspace handle work
records which solver backend was used, so calls to scs_solve,
scs_update, and scs_finish are automatically routed to the
correct backend.