The issue I want to solve is as follows:
max (log2(2-2/(x+2))+log2(2-2/(y+2)))/(x+y)
s.t. x>=0, y>=0, x+y<=50
And I’m trying to solve it with the Dinkelbach alghorithm, my code is as follows:
clc,clear;
close all;
eps=0.000001; %Convergence condition
iter_max = 30; %itewration steps
x = zeros(1,iter_max+1);
y = zeros(1,iter_max+1);
r = zeros(1,iter_max+1); %initialize
x(1) = 0;
y(1) = 0; %Set the value of the first step to 0
r(1) = rand(1); %Set the initial value of the function to a random value
for iter=1:iter_max %start
% update x&y
cvx_begin quiet
variables x1 y1
maximize (((log(2-2/(x1+2))/log(2))+(log(2-2/(y1+2)/log(2))))-r*(x1+y1)) %function after the Dinkelbach transformation
subject to
x1>=0;
y1>=0;
x1+y1<=50;
cvx_end
x(iter+1)=x1;
y(iter+1)=y1;
% Judgment of convergence & upadte r
if cvx_optval <= eps %stop if it converges
break
else
r(iter+1) = (((log(2-2/(x(iter+1)+2)))/log(2))+(log(2-2/(y(iter+1)+2)/log(2))))/(x(iter+1)+y(iter+1)); %update r if not convergence
end
end
figure
plot(r(1:iter),‘b-o’,‘linewidth’,1.5);
grid on
xlabel(‘iteration number’)
grid on
box on
ylabel(‘objective value’);
I keep getting an error when I run the code, and it says like this:
Error using ./ (line 42)
Disciplined convex programming error:
Invalid operation: {2} / {real affine}
Error in / (line 17)
Error in formal_test (line 17)
maximize (((log(2-2/(x1+2))/log(2))+(log(2-2/(y1+2)/log(2))))-r*(x1+y1)) %function after the Dinkelbach transformation
I’m a beginner in CVX and don’t know how to fix this, can you please explain how to solve this problem?
Thanks!