# How can i solve this problem

cvx_begin
variables t a1(101) a2(101) a3(101) b1(101) b2(101) b3(101) P1(101) P2(101) P3(101)

``````maximize(t)
subject to

R1u = log(1+Pu*h0./(a1.*(H^2+(x-s1x).^2+(y-s1y).^2)))./log(2).*a1;
R2u = log(1+Pu*h0./(a2.*(H^2+(x-s2x).^2+(y-s2y).^2)))./log(2).*a2;
R3u = log(1+Pu*h0./(a3.*(H^2+(x-s3x).^2+(y-s3y).^2)))./log(2).*a3;
R1v = log(1+P1.*h0./(b1.*(H^2+(x-d1x).^2+(y-d1y).^2)))./log(2).*b1;
R2v = log(1+P2.*h0./(b2.*(H^2+(x-d2x).^2+(y-d2y).^2)))./log(2).*b2;
R3v = log(1+P3.*h0./(b3.*(H^2+(x-d3x).^2+(y-d3y).^2)))./log(2).*b3;

B0/(101*Rt)*sum(R1u) >= t;
B0/(101*Rt)*sum(R2u) >= t;
B0/(101*Rt)*sum(R3u) >= t;
B0/(101*Rt)*sum(R1v) >= t;
B0/(101*Rt)*sum(R2v) >= t;
B0/(101*Rt)*sum(R3v) >= t;
Pall=P1+P2+P3;
Ball=a1+a2+a3+b1+b2+b3;
for i=1:101
Pall(i) <= Pv;
P1(i) >= 0;
P2(i) >= 0;
P3(i) >= 0;
Ball(i) <= 1;
a1(i) >= 0;
a2(i) >= 0;
a3(i) >= 0;
b1(i) >= 0;
b2(i) >= 0;
b3(i) >= 0;
end
``````

cvx_end

the errors are:

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

z = times( x, y, ‘./’ );

R1u = log(1+Puh0./(a1.(H^2+(x-s1x).^2+(y-s1y).^2)))./log(2).*a1;

If you are willing to have `a1` implicitly constrained to be positive, you can use `inv_pos(a1).`. Otherwise it is non-convex. Similarly for the other expressions.

Also, use of the for loop is not incorrect, but it is faster and simpler to use

``````Pall <= Pv
P1 >= 0
``````

etc.
rather than use a for loop,.

i change my code to this, but still have some problems.

cvx_begin

``````variables t a1(101) a2(101) a3(101) b1(101) b2(101) b3(101) P1(101) P2(101) P3(101)

maximize(t)
subject to

R1u = log(1+inv_pos(a1).*Pu*h0./(H^2+(x-s1x).^2+(y-s1y).^2))./log(2).*a1;
R2u = log(1+inv_pos(a2).*Pu*h0./(H^2+(x-s2x).^2+(y-s2y).^2))./log(2).*a2;
R3u = log(1+inv_pos(a3).*Pu*h0./(H^2+(x-s3x).^2+(y-s3y).^2))./log(2).*a3;
R1v = log(1+inv_pos(b1).*P1.*h0./(H^2+(x-d1x).^2+(y-d1y).^2))./log(2).*b1;
R2v = log(1+inv_pos(b2).*P2.*h0./(H^2+(x-d2x).^2+(y-d2y).^2))./log(2).*b2;
R3v = log(1+inv_pos(b3).*P3.*h0./(H^2+(x-d3x).^2+(y-d3y).^2))./log(2).*b3;

B0/(101*Rt)*sum(R1u) >= t;
B0/(101*Rt)*sum(R2u) >= t;
B0/(101*Rt)*sum(R3u) >= t;
B0/(101*Rt)*sum(R1v) >= t;
B0/(101*Rt)*sum(R2v) >= t;
B0/(101*Rt)*sum(R3v) >= t;
Pall=P1+P2+P3;
Ball=a1+a2+a3+b1+b2+b3;
Pall <= Pv;
P1 >= 0;
P2 >= 0;
P3 >= 0;
Ball <= 1;
``````

cvx_end

the errors are:
Disciplined convex programming error:
Illegal operation: log( {convex} ).

R1u =
log(1+inv_pos(a1). Pu h0./(H^2+(x-s1x).^2+(y-s1y).^2))./log(2).*a1;

it seems like the function in log() is a convex function, but it’s illegal

it seems that the function in log() must be concave. so i rewrite the function in log(), this time the error that Illegal operation: log( {convex} ) is eliminated. but there is another error. it seems that R1u={convex}.a1 is violating the DCP ruleset where a1 is a variable. it seems that a variable can not be a part of .

cvx_begin

``````variables t a1(101) a2(101) a3(101) b1(101) b2(101) b3(101) P1(101) P2(101) P3(101)

maximize(t)
subject to

R1u = -log(1-inv_pos(1+a1.*((H^2+(x-s1x).^2+(y-s1y).^2)./Pu*h0)))./log(2).*a1;
R2u = -log(1-inv_pos(1+a2.*((H^2+(x-s2x).^2+(y-s2y).^2)./Pu*h0)))./log(2).*a2;
R3u = -log(1-inv_pos(1+a3.*((H^2+(x-s3x).^2+(y-s3y).^2)./Pu*h0)))./log(2).*a3;
R1v = -log(1-inv_pos(1+b1.*((H^2+(x-d1x).^2+(y-d1y).^2)./P1*h0)))./log(2).*b1;
R2v = -log(1-inv_pos(1+b2.*((H^2+(x-d2x).^2+(y-d2y).^2)./P2*h0)))./log(2).*b2;
R3v = -log(1-inv_pos(1+b3.*((H^2+(x-d3x).^2+(y-d3y).^2)./P3*h0)))./log(2).*b3;

B0/(101*Rt)*sum(R1u) >= t;
B0/(101*Rt)*sum(R2u) >= t;
B0/(101*Rt)*sum(R3u) >= t;
B0/(101*Rt)*sum(R1v) >= t;
B0/(101*Rt)*sum(R2v) >= t;
B0/(101*Rt)*sum(R3v) >= t;
Pall=P1+P2+P3;
Ball=a1+a2+a3+b1+b2+b3;
Pall <= Pv;
P1 >= 0;
P2 >= 0;
P3 >= 0;
Ball <= 1;
``````

cvx_end

the errors are:
Disciplined convex programming error:
Cannot perform the operation: {convex} .* {real affine}

R1u = -log(1-inv_pos(1+a1.((H^2+(x-s1x).^2+(y-s1y).^2)./Puh0)))./log(2).*a1;

Whoops, I misread the last `a1`as being in the denominator and not seeing the `a1` inside the log. Hopefully my answer to your subsequent question How to write x*log(1+A/(B*x))? solves your problem. And maybe you’ve now implemented that, so see my answer to your question Why is my program failed? .

Thank you Mark! I used rel_entr() to rewrite the R1u expression, and the errors are fixed! But I still can’t get the result as shown in Why is my program failed?. I will try to solve this problem according to your suggestion. Thanks again!