How to handle log(x/y) in CVX

Optimization problem is in png. And this is my matlab code.

The error is “Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {real affine}”

I think the error occurs in log term. I don’t know how to deal with this.

N=10;

cvx_clear
cvx_begin
variables k(N)
variables z(N)

obj=0;
for i=1:N
    obj = obj + k(i)*log(1+z(i)/k(i)) -z(i);
end

maximize obj

subject to

k_sum=0;
for i=1:N
    k_sum = k_sum + k(i);
end

k_sum <= 1;

for i=1:N
    k(i)>=0;
    z(i)>=0;
end

cvx_end

image

I will address the optimization problem in your code. The optimization problem in the image is non-convex (maybe it’s a typo to not have z_i inside the log be divided by k_i?).

k(i)*log(1+z(i)/k(i)) can be reformulated as -rel_entr(k(i),k(i)+z(i)).
But rel_entr accepts vector arguments, producing vector result. So the for loop can be eliminated, and the objective written directly as
maximize(sum(-rel_entr(k,k+z)-z))

All the other for loops can also be eliminated.
Use

sum(k) <= 1
k >= 0
z >= 0

instead, which doesn’t have any for loops.

1 Like