hey every one, I am new to matlab and cvx and I am trying to convert this to cvx:

can anyone help me with it?

hey every one, I am new to matlab and cvx and I am trying to convert this to cvx:

can anyone help me with it?

This is straightforward once you have read the CVX Users’ Guide, except for one term. You should find Exponential perspective function on CVX and Solve optimization problems of exp function helpful with that term.

@Mark_L_Stone thank you for the answer. I have coded my optimization problem like this:

minimize (sum(bw./ChannelGainUN(row)).*(2.^(MinRateOfUsers(col)./inv_pos(bw))-1))

but I get these two errors:

Error using .* (line 173)

Disciplined convex programming error:

Cannot perform the operation: {positive constant} ./ {convex}

Error in ./ (line 19)

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

I read the documents but could not solve the errors. w

You are violating CVX’s DCP rules. That is not allowed.

Re-write `2^(R/k)`

as `exp(R*log(2)/k)`

. Then `k*2^(R/k)`

can be re-written as `k*exp(R*log(2)/k)`

, which can be handled per the links.

@Mark_L_Stone so its like this?

minimize (sum(bw./ChannelGainUN(row))*(exp(MinRateOfUsers(col)*log(2)./bw)-1))

@Mark_L_Stone hello again, I have worked on my cvx code since then, but unfortunately I have not been able to solve it.

you told me to write 2^(R/k) as exp(R*log(2)/k) and then to rewrite them as:
k*exp(R

I figured that means this and I don’t know if I’m right:

(sum(bw/ChannelGainUN(row)).

and till now this is what I am trying to minimize and my variable is Bw which is an array of bandwidths for n users.

I followed those two links and this is what I did according to what has been told there:

```
for i=1:n
cvx_begin;
variable bw(n);
sum(bw)==MaxBandwidthOfEachRRH(row);
bw>=0;
z=(bw/ChannelGainUN(row)).*(exp(currentUsersMinRate(i)*log(2))/bw)-1;
{(currentUsersMinRate(i)*log(2)),bw,z}==exponential(1);
minimize(sum(bw/ChannelGainUN(row)).*(exp(currentUsersMinRate(i)*log(2))/bw)-1);
cvx_end;
```

but I am not getting anything but errors. I know that I am doing it wrong but I cant fix it. could you please help me with it? I have a very short time to solve this, I would really appreciate any help.

I don’t have time to write it out carefully, but note:

z must be declared a variable.

Remove the line z = …,. .

Use z in place of the expression being replaced in the objective function.

You need a separate z for each term in the sum in the objective function sun, so declare variable z(n) and put (…,z(i)) = exponential(1) inside a for loop over i.

Get rid of the for statement you now ihave n the first line.

You need to write your objective in terms of z. You may have other errors, I haven’t checked.

Please re-read the links so that you can understand how my guidance relates to them.

Remove the line z = …,. .

if I remove z=… where can I declare what do I mean by z?

because when I remove it, I get an error that z is not declared.

Use z in place of the expression being replaced in the objective function.

you mean in place of bw? I don’t get it correctly…

so declare variable z(n)

so I have to remove bw(n)? or declare them both like: variable bw(n), z(n)

Get rid of the for statement you now ihave n the first line.

yes I forgot to remove it, thanks.

sorry for many many questions I am asking. using CVX for the first time is really confusing…

Unfortunately, you started with a tricky problem on which to start using CVX.

As I wrote above, z needs to be declared a (CVX) variable. Given that you really need z to be a length n,vector, and still need bw to be a CVX variable, you can use

`variables bw(n) z(n)`

I’m not sure I understand the relation between your code and the problem in your first post, so I will present code as if the simplified 1-D indexing in your code covers your situation, and guess on variable names. Otherwise, you will need to make modifications. You should be able to figure out how to modify my code if doiesn’t quite match your problem.

```
cvx_begin
variables bw(n) z(n)
minimize(sum((z-bw)./ChannelGainUN))
for i=1:n
{currentUsersMinRate(i)*log(2),bw(i),z(i)} == exponential(1)
end
sum(bw) == MaxBandwidthOfEachRRH
bw >= 0
cvx_end
```

I made up some (I suppose non-sensical) data, ran the code, and it produced an answer. No guarantees beyond that.

```
n = 5;
ChannelGainUN = [1.1:.1:1.5]';
currentUsersMinRate = [3.2 2.1 1.4 2.6 5.3]';
```

With result:

```
CVX Warning:
Models involving "exponential" or other functions in the log, exp, and entropy
family are solved using an experimental successive approximation method.
This method is slower and less reliable than the method CVX employs for
other models. Please see the section of the user's guide entitled
The successive approximation method
for more details about the approach, and for instructions on how to
suppress this warning message in the future.
Successive approximation method to be employed.
For improved efficiency, SDPT3 is solving the dual problem.
SDPT3 will be called several times to refine the solution.
Original size: 21 variables, 10 equality constraints
5 exponentials add 40 variables, 25 equality constraints
-----------------------------------------------------------------
Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------+---------------------------------+---------
5/ 5 | 3.021e+00 6.360e-01 0.000e+00 | Solved
5/ 5 | 6.867e-01 2.941e-02 0.000e+00 | Solved
5/ 5 | 7.530e-02 3.598e-04 0.000e+00 | Solved
5/ 5 | 9.459e-03 5.666e-06 0.000e+00 | Solved
5/ 5 | 1.189e-03 8.907e-08 0.000e+00 | Solved
0/ 5 | 1.492e-04 1.100e-09 0.000e+00 | Solved
-----------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +64.154
disp(bw)
0.683591761913353
0.440268935079385
0.288547159549769
0.527562346711498
1.060029796730820
```

thank you so much for this, there is just one problem:

minimize(sum((z-bw)./ChannelGainUN))

in here when I start debuging, z and bw are 4 × 1 arrays and ChannelGainUN is a 1 × 5. so they can not be divided and there is a “Matrix dimensions must agree” error. can I change z and bw to an array with 1 row? so they agree?

my arrays is:

currentUsersMinRate=[0.1,1,10,0.1,1]

and in my problem and in this part, channel gain is a single number.

Everything in my example data is 5 by 1, including `ChannelGainUN = [1.1:.1:1.5]'`

, so it was all compatible and successfully ran. I just made up the data so I could check that there were no syntax errors and that ir ran successfully. You should be able to duplicate my results.

I presume that you have or will obtain actual input data which you want to use. Of course, you should make the dimensions of everything compatible. You can make adjustments to my program as needed to match your data and problem.

@Mark_L_Stone

yes your example is totally correct, but my channelgainUN is a signle number, and when I put that is here:

minimize(sum((z-bw)./ChannelGainUN))

it gives no errors but it does not solve it and says that its infeasible.

If you show a complete reproducible example, with all input data, then perhaps we can diagnose your problem.

Let’s make this simpler. Just display with format long all the input data used by your CVX code.

```
gainofthisRRH
currentUsersMinRate
MaxBandwidthOfEachRRH
```

Please show the CVX and solver output you got when you ran your code which you wrote “says that its infeasible”/

i gave these values:

gainofthisRRH=15;

currentUsersMinRate=[0.1,1,10,0.1]

MaxBandwidthOfEachRRH=20;

I changed the MaxBandwidthOfEachRRH to a single number (i had given an array before but it was a mistake) and now it says "solved"

and now it gives me 4 values for bw:

disp(bw)

0.1786

1.7857

17.8571

0.1786

and this is the output:

Successive approximation method to be employed.

For improved efficiency, SDPT3 is solving the dual problem.

SDPT3 will be called several times to refine the solution.

Original size: 16 variables, 7 equality constraints

4 exponentials add 32 variables, 20 equality constraints

Cones | Errors |

Mov/Act | Centering Exp cone Poly cone | Status

--------±--------------------------------±--------

4/ 4 | 6.429e-01 2.889e-02 0.000e+00 | Solved

4/ 4 | 2.916e-02 6.174e-05 0.000e+00 | Solved

2/ 4 | 1.786e-03 2.098e-07 0.000e+00 | Solved

0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Solved

Status: Solved

Optimal value (cvx_optval): +0.474269

thank you so much for your help

After solution, `bw`

should be an n by 1 vector containing the optimal values.

After `cvx_end`

, you have the statement `bandwidth(i)=max(0,bw(i));`

This will only be executed for the then current value of `i,`

which is `n`

(because it had been used as the index of a for loop from 1 to n). If an optimal solution has been obtained, bw should be non-negative anyhow, unless you are worried about roundoff-level negative values. If you really want to do this, then use `bandwidth = max(0,bw)`

; which will ensure each element is non-negative.