"Disciplined convex programming error: Cannot perform the operation: {real affine} ./ {real affine}"

Hi there~Can anyone help me with this problem? I’ve read some of the same problem that had been asked before , however ,I still don’t know how to solve my problem with CVX.
I’d appreciate it if someone could help me!
My code is as following:

%CVX_opt_n --- solving the subproblem,using n* to make tags
function [cvx_optval,f,z,a] = CVX_opt_n( T , n ,B , h , n0 , c ,lamda ,P , num)
%SUM = n(1)+n(2)+n(3)+n(4)+n(5)+n(6) <= 1;
cvx_begin quiet;
cvx_solver sedumi;%sdpt3;%sedumi;
cvx_precision best;
%variables z(num) f(num) a
%variables f(num)
%variable a %Error:{positive constant} ./ {real affine}
variables z(num) f(num) a;
    maximize((((1-a)*T*n(1)*B*(-rel_entr(1,1+z(1)*h(1)/(1-a)/T/n0/n(1)/B)/log(2))+f(1)/c(1)*T)+((1-a)*T*n(2)*B*(-rel_entr(1,1+z(2)*h(2)/(1-a)/T/n0/n(2)/B)/log(2))+f(2)/c(2)*T)+((1-a)*T*n(3)*B*(-rel_entr(1,1+z(3)*h(3)/(1-a)/T/n0/n(3)/B)/log(2))+f(3)/c(3)*T)+((1-a)*T*n(4)*B*(-rel_entr(1,1+z(4)*h(4)/(1-a)/T/n0/n(4)/B)/log(2))+f(4)/c(4)*T)+((1-a)*T*n(5)*B*(-rel_entr(1,1+z(5)*h(5)/(1-a)/T/n0/n(5)/B)/log(2))+f(5)/c(5)*T)+((1-a)*T*n(6)*B*(-rel_entr(1,1+z(6)*h(6)/(1-a)/T/n0/n(6)/B)/log(2))+f(6)/c(6)*T))/(h(1)*P(1)*a*T+h(2)*P(2)*a*T+h(3)*P(3)*a*T+h(4)*P(4)*a*T+h(5)*P(5)*a*T+h(6)*P(6)*a*T))
    subject to
        z(1)+lamda*pow_pos(f(1),3)*T <= h(1)*P(1)*a*T;
        z(2)+lamda*pow_pos(f(2),3)*T <= h(2)*P(2)*a*T;
        z(3)+lamda*pow_pos(f(3),3)*T <= h(3)*P(3)*a*T;
        z(4)+lamda*pow_pos(f(4),3)*T <= h(4)*P(4)*a*T;
        z(5)+lamda*pow_pos(f(5),3)*T <= h(5)*P(5)*a*T;
        z(6)+lamda*pow_pos(f(6),3)*T <= h(6)*P(6)*a*T;
    
    z(1) >= 0;
    z(2) >= 0;
    z(3) >= 0;
    z(4) >= 0;
    z(5) >= 0;
    z(6) >= 0;
    
    n(1) >= 0 && n(1) <= 1;
    n(2) >= 0 && n(2) <= 1;
    n(3) >= 0 && n(3) <= 1;
    n(4) >= 0 && n(4) <= 1;
    n(5) >= 0 && n(5) <= 1;
    n(6) >= 0 && n(6) <= 1;
    0 <= a;
    a <= 1;
    
    f(1) >= 0
    f(1) <= 447
    %f_max could be found from related work,firstly set it as 447
    f(2) >= 0
    f(2) <= 447
    f(3) >= 0
    f(3) <= 447
    f(4) >= 0
    f(4) <= 447
    f(5) >= 0
    f(5) <= 447
    f(6) >= 0
    f(6) <= 447

cvx_end;
cvx_optval;
f;
z;
a;
end

I don’t know why some of the ‘*’ in my code could not be shown:
here is the screenshot of my code:




thank you for your patience to see it!

It looks like you have implemented `log(cvx_expression) = -rel_entr(1,cvx_expression), which is needed (only) if CVXQUAD is being used.

So first undo that. Then reformulate (1-a)*log(1+y/(1-a)) as -rel_entr(1-a,1-a+y). I’ll let you work out what the y needs to be to match this construct. I haven’t checked your code carefully enough to see whether this is sufficient to handle your problem.

Also, don’t use cvx_begin quiet until everything is working correctly. And never use cvx_precision best

1 Like

Thank you , Mark! Let me have a try!

Dear Mark,I stopped using the cvxquad and reformulated my code(during which I found that the paramater T could be omitted for it exists in both the numerater and denominator) , however ,the same error occured again :cry:
I don’t know whether it’s because that I didn’t reformulate the code properly as you said or the approach is not proper.
Thank you in advance for your kind-heartedly help!
my reformulated code is as following:
%CVX_opt_n — solving the subproblem,using n* to make tags
function [cvx_optval , f , z , a]= CVX_opt_n( T, n ,B , h , n0 , c ,lamda ,P , num)
%SUM = n(1)+n(2)+n(3)+n(4)+n(5)+n(6) <= 1;
cvx_begin; %quiet
cvx_solver sedumi; %sdpt3;%sedumi;
variables z(num) f(num) a;
maximize(((n(1)B(-rel_entr(1-a,1+z(1)*h(1)/(1-a)/T/n0/n(1)/B)/log(2))+f(1)/c(1))+…
(n(2)B(-rel_entr(1-a,1+z(2)*h(2)/(1-a)/T/n0/n(2)/B)/log(2))+f(2)/c(2))+…
(n(3)B(-rel_entr(1-a,1+z(3)*h(3)/(1-a)/T/n0/n(3)/B)/log(2))+f(3)/c(3))+…
(n(4)B(-rel_entr(1-a,1+z(4)*h(4)/(1-a)/T/n0/n(4)/B)/log(2))+f(4)/c(4))+…
(n(5)B(-rel_entr(1-a,1+z(5)*h(5)/(1-a)/T/n0/n(5)/B)/log(2))+f(5)/c(5))+…
(n(6)B(-rel_entr(1-a,1+z(6)*h(6)/(1-a)/T/n0/n(6)/B)/log(2))+f(6)/c(6)))…
/(h(1)*P(1)*a+h(2)*P(2)*a+h(3)*P(3)*a+h(4)*P(4)*a+h(5)*P(5)*a+h(6)*P(6)a))
subject to
z(1)+lamda
pow_pos(f(1),3)*T <= h(1)P(1)aT;
z(2)+lamda
pow_pos(f(2),3)*T <= h(2)P(2)aT;
z(3)+lamda
pow_pos(f(3),3)*T <= h(3)P(3)aT;
z(4)+lamda
pow_pos(f(4),3)*T <= h(4)P(4)aT;
z(5)+lamda
pow_pos(f(5),3)*T <= h(5)P(5)aT;
z(6)+lamda
pow_pos(f(6),3)*T <= h(6)*P(6)aT;

    z(1) >= 0;
    z(2) >= 0;
    z(3) >= 0;
    z(4) >= 0;
    z(5) >= 0;
    z(6) >= 0;
    
    n(1) >= 0 && n(1) <= 1;
    n(2) >= 0 && n(2) <= 1;
    n(3) >= 0 && n(3) <= 1;
    n(4) >= 0 && n(4) <= 1;
    n(5) >= 0 && n(5) <= 1;
    n(6) >= 0 && n(6) <= 1;
    0 <= a;
    a <= 1;
    
    f(1) >= 0
    f(1) <= 447
    %f_max could be found from related work,firstly set it as 447
    f(2) >= 0
    f(2) <= 447
    f(3) >= 0
    f(3) <= 447
    f(4) >= 0
    f(4) <= 447
    f(5) >= 0
    f(5) <= 447
    f(6) >= 0
    f(6) <= 447

cvx_end;
cvx_optval;
f;
z;
a;
end

here is the screenshot of the error.

cvx don’t allow multiplying two expressions, but allow multiplying one expression and one constant. this is part of the dcp ruleset, which you can read in cvx uses’ guide.

1 Like

Ok , let me have a detailed read of the CVX users guide and check my code , Thanks for your suggestion!

If you employ my proposed reformulation
(1-a)*log(1+y/(1-a)) as -rel_entr(1-a,1-a+y).
there should not be any such error, because I believe the 'yinvolves the variablez`, multiplied and divided by some input data. And that is allowed by CVX.

If you use CVX 2.2. with Mosek 9.x, Mosek’s native exponential cone capability will be used (in which case, do not use CVXQUAD"s exponential.m replacement). Otherwise, my proposed formulation can be used by CVXQUAD without any further modification.

1 Like

Hey , Mark ! I found that I misunderstood your formula as (1-a)*log(1+y/1-a) instead of the proper (1-a)log(1+y/(1-a)) . You are right ! After using the correct formula , I made it to computing the results ! Thank you , Mark ! You are one of the leaders of my scientific journey !

Sorry about that. I have now edited my previous posts to insert the missing {

1 Like