# How to code max(a, 0) as objective function in cvx

(Jason Dou) #1

how to code max(a, 0) as objective function in cvx

(Mark L. Stone) #2

Presuming you want to minimize it, you can use max(a,0)

help cvx/max
Disciplined convex/geometric programming information:
max is convex, log-log-convex, and nondecreasing in its first
two arguments. Thus when used in disciplined convex programs,
both arguments must be convex (or affine). In disciplined
geometric programs, both arguments must be log-convex/affine.

cvx_begin
variable a
minimize(max(a,0))
a>=-2
cvx_end

## Calling SDPT3 4.0: 2 variables, 1 equality constraints

num. of constraints = 1
dim. of linear var = 2

SDPT3: Infeasible path-following algorithms

## number of iterations = 7 primal objective value = 3.03130444e-10 dual objective value = 8.99888493e-11 gap := trace(XZ) = 6.72e-10 relative gap = 6.72e-10 actual relative gap = 2.13e-10 rel. primal infeas (scaled problem) = 5.63e-14 rel. dual " " " = 1.62e-10 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 2.0e+00, 4.5e-11, 1.0e+00 norm(A), norm(b), normĀ© = 2.4e+00, 3.0e+00, 2.0e+00 Total CPU time (secs) = 0.10 CPU time per iteration = 0.01 termination code = 0 DIMACS: 5.6e-14 0.0e+00 1.6e-10 0.0e+00 2.1e-10 6.7e-10

Status: Solved
Optimal value (cvx_optval): +3.0313e-10

disp(a)
3.0313e-10