# Why doesn't CVX accept log2

My purpose is to find the optimal value of the function,
subject to \sum_{i=1}^{10}x_i+y_i=2, which is concave on the defined domain. so I want to maximize it as an objective function in CVX. but the code doesn’t work (dcp error). Is it possible to write this function in a way that CVX will recognize its concavity?

n=10;
cvx_begin
variable X(n)
variable Y(n)
maximize( sum(log2(1+((X.*Y)./(X+Y)))))
subject to
min(X)>=0;
 min(Y)>=0;
sum(X+Y)==2;
cvx_end

“Why doesn’t CVX accept log2”?

Because the CVX developer did not include support for log2.

However, you can formulate as log2(x) = log(x)/log(2), which CVX will accept if x is a concave expression following CVX’;s rules. Or if it is the only term in the objective, you can just leave out the /log(2), and the argmax will be the same.

But in your case, additional reformulation is needed to deal with the argument of log, which is basically 1 + the harmonic mean There are solutions in Harmonic mean in cvx and How can I express this concave function in CVX, the latter of which reference https://docs.mosek.com/modeling-cookbook/cqo.html#harmonic-mean .