如何解决“无法执行赋值,因为‘cvx‘类型的值不可转换为‘double‘

How to solve ”Unable to perform assignment because value of type ‘cvx’ is not convertible to ‘double’

  1. Here I got this code and error message, could you please help me to solve it?

`cvx_begin
variable E_user(n) nonnegative
variable sigma(n) nonnegative
variable Sigma(n) nonnegative
variable Omega(n) nonnegative
obj=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

sigma=zeros(1,K_num); Sigma=zeros(1,K_num); Omega=zeros(1,K_num);
    
        % Calculate sigma
        for t=1:K_num
            my_hold=zeros(M*N,M*N);
            for i=1:K_num
                if i~=t
                    my_hold=my_hold+E_user(i)*G_DDMA(:,:,i)*G_DDMA(:,:,i)';
                end
            end
            sigma(t)=trace(pinv(D(:,:,t))*U(:,:,t)*H(:,:,t)*my_hold*H(:,:,t)'*U(:,:,t)'*(pinv(D(:,:,t)))');
        end
    
        % Calculate Sigma
        for t=2:K_num
            my_hold=zeros(M*N,M*N);
            for i=2:K_num
                if i~=t
                    my_hold=my_hold+E_user(i)*G_DDMA(:,:,i)*G_DDMA(:,:,i)';
                end
            end
            Sigma(t)=trace(pinv(D(:,:,1))*U(:,:,1)*H(:,:,1)*my_hold*H(:,:,1)'*U(:,:,1)'*(pinv(D(:,:,1)))');
        end
        my_hold=zeros(M*N,M*N);
        for i=3:K_num
            my_hold=my_hold+E_user(i)*G_DDMA(:,:,i)*G_DDMA(:,:,i)';
        end
        Sigma(1)=trace(pinv(D(:,:,2))*U(:,:,2)*H(:,:,2)*my_hold*H(:,:,2)'*U(:,:,2)'*(pinv(D(:,:,2)))');
    
    
        % Calculate Omega
        for i=2:K_num
            Omega(i)=trace(pinv(D(:,:,1))*U(:,:,1)*H(:,:,1)*G_DDMA(:,:,i)*G_DDMA(:,:,i)'*H(:,:,1)'*U(:,:,1)'*(pinv(D(:,:,1)))');
        end
        Omega(1)=trace(pinv(D(:,:,2))*U(:,:,2)*H(:,:,2)*G_DDMA(:,:,1)*G_DDMA(:,:,1)'*H(:,:,2)'*U(:,:,2)'*(pinv(D(:,:,2)))');
    
        sigma=real(sigma);
        Sigma=real(Sigma);
        Omega=real(Omega);
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        for i=2:n
            obj=obj+log(1+2*beta(i)*sqrt(E_user(1)+alpha*Sigma(1)+N0)-beta(i)^2)*(N0+alpha*sigma(i)*Omega(1))/log(2);
        end
        obj=obj+log(1+2*beta(1)*sqrt(E_user(2)+alpha*Sigma(2)+N0)-beta(1)^2)*(N0+alpha*sigma(1)*Omega(2))/log(2);
        maximize (obj)
        E_sum=0;
        for i=1:n
            E_sum=E_sum+E_user(i);
        end
        subject to 
        E_sum<=E_total;
    cvx_end`

The error was ‘Unable to perform assignment because value of type ‘cvx’ is not convertible to ‘double’.’ in the line of ‘sigma(t)’

  1. You seem to be confusing variable with expressions.

sigma=zeros(1,K_num); supersedes (overwrites) the earlier declaration of as a variable. is a CVX expression, because it involves the variable .The, ) is tassigned to a CVX expression involving , but is a double, not a CVX expression; so triggers the error message.sigmamy_holdE_user sigma(tmy_holdsigma

You should declare

expression sigma(n) 
expression Sigma(n) 
expression Omega(n)

instead of as variables. Declared expressions are automatically initialized to all zeros by CVX. If you need them to be nonnegative, you will need to add the constraints

sigma >= 0
Sigma >= 0
Omega >= 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值