DCP compliance in constraint specification


I included the line below in my code to express a constraint in my CVX specification:

(1-tau)* log2(1 + h(k) * p(k) / ((1-tau)*sigma2)) >= R

When my code ran, the error " Cannot perform the operation: {real affine} ./ {real affine}" was returned.

So I looked up this website and used the suggestion made by @mcg to use the rel_entr function, I changed the constraint to

-rel_entr(tau,tau + 100,000*h(k)*p(k))>= R; (the 100000 there is because sigma2 = 0.00001)

Where R and tau are the unknowns in this expression. h(k) and p(k) are vectors whose values had been specified in the body of the MATLAB code.

The constraint error I got this time with the “rel_entr” function expression was “Too many input arguments.”

Does anyone know a better way to formulate this expression in CVX for it to be accepted?


Your error message is as a result of having a comma in 100000. Therefore, MATLAB thinks you have provided 3 arguments, when it is expecting only 2. Never put a comma in a number in MATLAB.

However, even though after this fix your code might now wotk without error message, it doesn’t seem to match what you wrote above. I’ll let you figure out what you really meant.

If your constraint above is correct, I think you need something more like
-rel_entr(1-tau,1-tau + 100000*h(k)*p(k))/log(2)

See my answer at Writing a constraint in DCP complient format (note that mcg’s typo was fixed subsequent to that post).

Because I’m tired, I may have made a mistake, and you should check if this is correct.

1 Like

Thanks a bunch @Mark_L_Stone, my code did work thereafter. I’ll also look at the link you recommended. Cheers!