The way of expression

(zhangQK) #1

abs(x)*exp(-0.0856*x), x<=0; 0.00536*x, x>=0.
I want to know how to express it so that cvx can accept it?
Thank you.

(Mark L. Stone) #3

This does appear to be convex.

If there were just the negative x branch, this could be handled using gp mode, with the variable negative_x being the negative of your x, so you would have to make the appropriate adjustments elsewhere in your program and in interpreting the results.

cvx_begin gp
variable negative_x

% If your expression is the objective
minimize(max(negative_x,0)*exp(0.0856*negative_x) 

% If your expression is the left-hand side of a constraint
max(negative_x,0)*exp(0.0856*negative_x)  <= valid_right_hand_side

Because all variables in gp mode are constrained to be nonnegative, In order to also handle the other branch, perhaps it can be done with Big M logic using binary variable9s). I leave the details to you as well as determining whether the Big M logic can be correctly implemented in gp mode,.

I don’t rule out that there is some clever approach which does not require introduction of binary variables. Nor am I saying for sure that it can be done even with binary variables.

(zhangQK) #4

Hi,Mark.
My expression is the objective.But x is a expression,for example,

cvx_begin
variable y(N+1);
expression x(N);
x=y(2:N+1)-y(1:N);
minimize(sum(that expression));
subject to

cvx_end