问题1
The following error occurred converting from cvx to double:
Conversion to double from cvx is not possible.
Error in comparePaper3 (line 50)
f(i)=(1-x_low)* (power(x(i),-p)-1)/(power(x_low,-p)-1);
解决方案
添加链接描述
参考该问题回答
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 196 . 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.
我的解决方案
f(i)=(1-x_low)* (power(x(i),-p)-1)/(power(x_low,-p)-1);
把之前的声明f=zeros(1,n);删除,直接使用公式
f=(1-x_low)* (power(x(i),-p)-1)/(power(x_low,-p)-1);
问题2
Undefined function or variable 'variables'.
Error in comparePaper3 (line 36)
variables x(n) pai(n) kesi yita
尝试运行另外一个使用CVX的程序,是没有问题的;在停止运行另外一个程序之后,继续运行出问题的程序,发现该问题没有了。