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

Hello, I would like to ask about the expression of v_2[n] in my question. Only w_k[n] is a variable, and all other letters can be considered constants. How can the content of the log function be expressed using the rel_entr function instead?
image

Make suitable adjustments to the solution at How to express log(1+ sum ( 1./x ) ) in CVX? - #2 by Mark_L_Stone , which uses the modeling of log-sum-inv provided in section 5.2.7 `log-sum-inv of the Mosek Modeling Cookbook