Here is my CVX code, but it failed with the error: Illegal operation: log( {convex} ).

M = 10;
v = [18;6];
cvx_begin quiet
variables a2
variables p(2,1)
maximize a2
subject to
a2 <= sum( log(sqrt(p.*v.*(1-p+v)))/log(2) + log((p-1).^2)/log(2) );
sum(p) <= 10;
p >= 0.001;
p <= v;
cvx_end

log(sqrt(p.*v.*(1-p+v))) is a concave function and log((p-1).^2) is also concave, whose second derivative is -2/(-1 + p)^2. However, my code failed with the error “Illegal operation: log( {convex} )”.

I deleted the log((p-1).^2) part, and the optimization problem can be solved. In addition, I transformed the log((p-1).^2) part into 2*log(p-1), it also works with p>1. But p is greater than 0 in the original problem. When I let M=1, it failed again.

So how to express the problem or rewrite log((p-1).^2) properly in CVX?
I really appreciate your generous help.

Thanks for your reply! But p is a two-dimensional variable in my problem. Sorry for misleading you with my inaccurate description above. In some situations, such as v=[1000,0.3], the optimal p obtained by exhaustive searching is p=[9.7,0.3], which can not be solved by my code with 2*log(p-1) or 2*log(1-p) . I don’t know how to deal with it. Thanks again for your help.

You could still use basically the same idea, except there would be 4 separate problems, one for each combination of each of the 2 elements of p being >= 1 or <= 1. You can write out the terms explicitly, rather than using sum, in order to accommodate the mixed cases of one element of p being >= 1 while the other element of p is <= 1.