Quick Tutorial

Consider a constrained least squares problem

\[\begin{aligned} \begin{array}{ll} \text{minimize} & \|Ax - b\|_2^2 \\ \text{subject to} & x \geq 0 \end{array} \end{aligned}\]

with variable $x\in \mathbf{R}^{n}$, and problem data $A \in \mathbf{R}^{m \times n}$, $b \in \mathbf{R}^{m}$.

This problem can be solved in Convex.jl as follows:

julia> using Convex, SCS
julia> m = 4; n = 55
julia> A = randn(m, n); b = randn(m)4-element Vector{Float64}: -0.5927610152342344 0.5173544393784156 -0.21310982928576944 -0.72107968299556
julia> x = Variable(n)Variable size: (5, 1) sign: real vexity: affine id: 786…978
julia> problem = minimize(sumsquares(A * x - b), [x >= 0])Problem statistics problem is DCP : true number of variables : 1 (5 scalar elements) number of constraints : 1 (5 scalar elements) number of coefficients : 31 number of atoms : 6 Solution summary termination status : OPTIMIZE_NOT_CALLED primal status : NO_SOLUTION dual status : NO_SOLUTION Expression graph minimize └─ qol (convex; positive) ├─ + (affine; real) │ ├─ * (affine; real) │ │ ├─ … │ │ └─ … │ └─ 4×1 Matrix{Float64} └─ [1;;] subject to └─ ≥ constraint (affine) └─ + (affine; real) ├─ 5-element real variable (id: 786…978) └─ Convex.NegateAtom (constant; negative) └─ …
julia> solve!(problem, SCS.Optimizer; silent = true)Problem statistics problem is DCP : true number of variables : 1 (5 scalar elements) number of constraints : 1 (5 scalar elements) number of coefficients : 31 number of atoms : 6 Solution summary termination status : OPTIMAL primal status : FEASIBLE_POINT dual status : FEASIBLE_POINT objective value : 0.0 Expression graph minimize └─ qol (convex; positive) ├─ + (affine; real) │ ├─ * (affine; real) │ │ ├─ … │ │ └─ … │ └─ 4×1 Matrix{Float64} └─ [1;;] subject to └─ ≥ constraint (affine) └─ + (affine; real) ├─ 5-element real variable (id: 786…978) └─ Convex.NegateAtom (constant; negative) └─ …
julia> problem.statusOPTIMAL::TerminationStatusCode = 1
julia> problem.optval4.101528223800368e-7
julia> x.value5×1 Matrix{Float64}: 0.41358470955079846 0.245090958084477 0.4111181215831069 0.8509570025155792 0.18183695552228096