CVXMOD – Quick examples

Alert!

CVXMOD is discontinued!

Unfortunately CVXMOD has not been developed since 2008. It is incomplete, somewhat buggy and not supported. Please instead try the replacement package CVXPY. Or, try CVXOPT if you are prepared to work at a lower level, CVX if you are ok with Matlab, or CVXGEN if you want small (but super high speed) QP solvers.

Two examples of CVXMOD in action appear below.

Solving an analytic centering problem
from cvxmod import *
from cvxmod.atoms import log

A = randn(50, 8)
b = rand(50, 1)
x = optvar('x', 8)

p = problem(maximize(sum(log(b - A*x))))
p.solve()

print value(min(b - A*x))
printval(x)
Solving a constrained norm minimization problem
from cvxmod import *
from cvxmod.atoms import norm1
from cvxmod.sets import probsimp

A = randn(10, 5)
b = randn(10, 1)
x = optvar('x', 5)

p = problem(minimize(norm1(A*x - b)), [x >= -0.5])
p.constr.append(x |In| probsimp(5))
p.solve()

print "Optimal problem value is %.4f." % p.value
printval(x)