Cannot perform the operation: {positive constant} ./ {real affine}


I am trying to run a very basic CVX prgram as follows:

variables s_B d_B s_A d_A;
minimize ( 0 + (10 / d_B) + (5 / d_A));
subject to
	s_B >= 0;
	d_B >= 10;
	s_A >= 0;
	d_A >= 5;
	s_B - s_B - d_B >= -1*11;
	s_A - s_B - d_B >= -0*11;
	s_A - s_A - d_A >= -1*11;
	s_B - s_A - d_A >= -2*11;

Can you please point out what I doing wrong here? I seem to be getting the following error:

Error using cvx/times (line 173)
Disciplined convex programming error:
Cannot perform the operation: {positive constant} ./ {real affine}

Error in cvx/rdivide (line 19)
z = times( x, y, ‘./’ );

Error in cvx/mtimes (line 36)
z = feval( oper, x, y );

Error in cvx/mrdivide (line 15)
z = mtimes( x, y, ‘rdivide’ );

Error in trial(line 3)
minimize ( 0 + (10 / d_B) + (5 / d_A));

Please let us know when you have read this documentation and this function reference. If you still need help after that I’m sure I or someone else will chime in. The FAQ isn’t bad either.

It may sound like I am being cute but it is vitally important to understand why CVX is doing what it is doing here if you’re going to be successful using it.

Yes, reading those links will show you a simple change (occurring twice) which you need to make to your objective function. Then the problem is accepted and solved. Also, although the semicolons at the end of CVX statements do no harm, they are not needed, and don’t serve to affect the output unlike with regular MATLAB statements.

Thank you for your response. The issue to understand here, quoting from the DCP ruleset, is that:

CVX does not consider a function to be convex or concave if it is so only over a portion of its domain, even if the argument is constrained to lie in one of these portions. As an example, consider the function 1/x. This function is convex for x>0, and concave for x<0. But you can never write 1/x in CVX (unless x is constant), even if you have imposed a constraint such as x>=1, which restricts x to lie in the convex portion of function 1/x. You can use the CVX function inv_pos(x), defined as 1/x for x>0 and ∞ otherwise, for the convex portion of 1/x; CVX recognizes this function as convex and nonincreasing. In CVX, you can express the concave portion of 1/x, where x is negative, using -inv_pos(-x), which will be correctly recognized as concave and nonincreasing.


Yes, use inv_pos. Change (10 / d_B) to (10 * inv_pos(dB)), and similarly with d_A.