# Conversion to double from cvx is not possible

I want to solve a simple convex problem that minimizes the power of transmitting devices. I have a supposed that there are 10 devices each communicating with another device. But, when I run the program it gives me this error,

The following error occurred converting from cvx to double:
Conversion to double from cvx is not possible.
Error in testcode4 (line 12)
Rate(i,j) = log(1+(p(i)*((distance(i,j)).^(-pathloss))));

``````distance = rand(10,10);
Rate_min = ones(10,10);
Power_total = 10;
Rate = zeros(10,10);

cvx_begin
variable p(10,1) nonnegative
minimize norm(p)
subject to
for i = 1:10
for j = 1:10
Rate(i,j) = log(1+(p(i)*((distance(i,j)).^(-pathloss))));
end
end

Rate >= Rate_min;
sum(p) <= Power_total;
cvx_end``````

You are using `Rates` as an expression, after first having defined it as a MATLAB (double) variable. This is neither allowed nor necessary. See http://cvxr.com/cvx/doc/basics.html#assignment-and-expression-holders . Had you read that, you would have seen discussion of the exact error message you received.

Either

delete the line `Rate = zeros(10,10);`

or

change it to `expression Rate(10,10);` and move it to someplace after cvx_begin and before the for loops.

or

change it to `Rate = cvx(zeros(10,10));`

or

remove all instances of `Rate` and instead use
`log(1+(p(i)*((distance(i,j)).^(-pathloss)))) >= Rate_min(i,j)`

Note: the usage of `cvx()` doesn’t seem to be in the CVX Users’ Guide.

3 Likes