Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 1.17 KB

quick_tutorial.rst

File metadata and controls

47 lines (34 loc) · 1.17 KB

Quick Tutorial

Consider a constrained least squares problem

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

with variable x ∈ Rn, and problem data A ∈ Rm × n, b ∈ Rm.

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

# Make the Convex.jl module available
using Convex, SCS

# Generate random problem data
m = 4;  n = 5
A = randn(m, n); b = randn(m, 1)

# Create a (column vector) variable of size n x 1.
x = Variable(n)

# 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])

# Solve the problem by calling solve!
solve!(problem, SCSSolver())

# Check the status of the problem
problem.status # :Optimal, :Infeasible, :Unbounded etc.

# Get the optimum value
problem.optval