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


version predcorr gam expon scale_data
NT 1 0.000 1 0
it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime

0|0.000|0.000|6.7e-01|6.7e+00|2.0e+02| 1.000000e+01 0.000000e+00| 0:0:00| chol 1 1
1|1.000|1.000|9.3e-08|7.1e-02|1.1e+01| 7.950084e+00 -7.599994e-01| 0:0:00| chol 1 1
2|0.941|1.000|9.0e-08|7.1e-03|7.0e-01| 7.950084e-02 -6.034994e-01| 0:0:00| chol 1 1
3|1.000|0.951|2.8e-08|1.0e-03|3.8e-02| 1.515619e-02 -1.974860e-02| 0:0:00| chol 1 1
4|0.988|0.988|8.3e-09|8.2e-05|4.6e-04| 1.827344e-04 -4.050789e-05| 0:0:00| chol 1 1
5|0.989|0.989|1.5e-10|7.9e-06|5.0e-06| 2.008423e-06 1.933464e-05| 0:0:00| chol 1 1
6|0.989|0.989|8.3e-12|8.7e-08|5.5e-08| 2.207041e-08 2.124340e-07| 0:0:00| chol 1 1
7|1.000|0.998|5.6e-14|1.6e-10|6.7e-10| 3.031304e-10 8.998885e-11| 0:0:00|
stop: max(relative gap, infeasibilities) < 1.49e-08

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