matlab中使用cvx遇到的问题

问题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的程序,是没有问题的;在停止运行另外一个程序之后,继续运行出问题的程序,发现该问题没有了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值