I have the following example where I would like to minimize x+y where x in [0,1] and y in [0, 1]. If I use minimize(z) where an expression z is assigned as z =x+y, I get an output which says ``Status: Solved, Optimal value (cvx_optval): +0" but the returned values are x=0.5, y=0.5, z=1.0. Please see the below code for the example. Since z is an expression and not (necessarily) an optimization variable, the documentation suggests one should use “=” instead of “==”, so I chose to use z=x+y instead of z==x+y. (http://cvxr.com/cvx/doc/basics.html#assignment-and-expression-holders)
If I use “minimize(x+y)” as the objective, I obtain the expected results where x and y are zero (up to reasonable numerical accuracy). If I define “z==x+y” and “minimize(z)”, I again obtain the correct results.
In this simple example, it is of course possible to fix this issue easily. But for more complicated problem instances with multiple intermediate calculations, this is not convenient and the above issue creates a quite confusing situation where one seems to obtain wrong results. Hence, I am wondering whether I violated a rule about what not to do with ``expressions" in the below formulation or this is a bug.
x_bound=1; y_bound=1; cvx_begin variable x variable y expression z minimize(z) subject to x <= x_bound; y <= y_bound; z=x+y; x>=0; y>=0; cvx_end