# I encounter some problems when using using the Dinkelbach method

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!

help inv_pos

inv_pos Reciprocal of a positive quantity.
inv_pos(X) returns 1./X if X is positive, and +Inf otherwise.
X must be real.

`````` For matrices and N-D arrays, the function is applied to each element.

Disciplined convex programming information:
inv_pos is convex and nonincreasing; therefore, when used in CVX
specifications, its argument must be concave (or affine).
``````

Thanks for your answer, the question about “{real affine}” seems to have been solved, but I’ve run into a new problem, The error message is as follows:

Error using formal_test (line 22)
Your objective function is not a scalar.

I’ve tried setting the variables x1 and y1 to a one row and one column matrix (setting them as scalars), but still can’t solve it, can you please explain how to solve this problem?
Thanks!

If you insert the objective function in the program just before the maximize statement, what does it say? I.e., type the objective function, but without `maximize`. if that is not a real scalar, you will get an error message, because objective function needs to evaluate to a real scalar.

Perhaps you are missing one or more levels of sum, or need an inner product to produce a scalar, or incorrectly declared variables, or incorrectly produced input data. It is your problem, not mine, so I have no idea what the correct resolution is. I don’t even know what program and input data you ran which produced this error message.