# Logical constraint problem

Please, help me. I would like to write this constraint in cvx, how can I rewrite it correctly? x is my variable

My constraint is:
sum(x(x<=0))<=0.5

It is showing this error:
??? Error using ==> cvx.subsref at 13
Function ‘subsindex’ is not defined for values of class ‘cvxcnst’.

The rest of my cvx problem is (portfolio optimization):
cvx_begin
variable x(n)
minimize (x’Sx)
subject to
pbar’*x==x_unif’*pbar;
sum(x)==1;
cvx_end

Thank you very much!

Something doesn’t make sense here. First of all, `sum(x(x<=0))` is the same as `sum(min(x,0))`. But that is a concave expression so the DCP rules forbid it from the left-hand side of a `<=` constraint.

However: that expression is also guaranteed to be zero or negative. So why would you try to bound it above by 0.5? That makes it trivially feasible.

Sorry, I have made a mistake, I want sum(abs(x(x<=0)))<=0, so it is not trivial. It is an example from Boyd and Vandenberghe book Additional Exercises for Convex Optimization, so it should work somehow. Thank you for your help, mcg.

Sorry, I have made a mistake, I want sum(abs(x(x<=0)))<=0.5, so it is not trivial. It is an example from Boyd and Vandenberghe book Additional Exercises for Convex Optimization, so it should work somehow. Thank you for your help, mcg.

Great! I have used max(-x,0) instead of abs(x(x<=0)) and it worked.