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> # Make the Convex.jl module available
using Convex, SCS
julia> # Generate random problem data
m = 4; n = 5
5
julia> A = randn(m, n); b = randn(m, 1)
4×1 Array{Float64,2}:
-0.5982561974146283
1.8285635154246862
0.7473287766124718
1.9114497945229456
julia> # Create a (column vector) variable of size n x 1.
x = Variable(n)
Variable
size: (5, 1)
sign: real
vexity: affine
id: 140…713
julia> # The problem is to minimize ||Ax - b||^2 subject to x >= 0
# This can be done by: minimize(objective, constraints)
problem = minimize(sumsquares(A * x - b), [x >= 0])
minimize
└─ qol_elem (convex; positive)
├─ norm2 (convex; positive)
│ └─ + (affine; real)
│ ├─ …
│ └─ …
└─ [1.0]
subject to
└─ >= constraint (affine)
├─ 5-element real variable (id: 140…713)
└─ 0
status: `solve!` not called yet
julia> # Solve the problem by calling solve!
solve!(problem, () -> SCS.Optimizer(verbose=false))
julia> # Check the status of the problem
problem.status # :Optimal, :Infeasible, :Unbounded etc.
OPTIMAL::TerminationStatusCode = 1
julia> # Get the optimum value
problem.optval
7.7918849978570375