Cannot perform the operation: {invalid} .* {real affine}

I’m new in cvx. When i use cvx,it says"Cannot perform the operation: {invalid} .* {real affine}"
What should i do ?
Here is my code:

  VS = rand(M,K);
        cvx_begin sdp
        cvx_solver Mosek
        variable P(Nu,Nu,U) nonnegative 
        expression object;
        object = cvxobject_monte(K,U,M,Nu,W_cu,W_s,W_BS,xi,P,eta_old,HH_freq,VS,Cw);
        maximize object
        subject to
        for u =1:U
            sum(diag(P(:,:,u))) <= Pmax;
        end
        P>=0;
        cvx_end

where:
function [ object ] = cvxobject_monte(K,U,M,Nu,W_cu,W_s,W_BS,xi,P,eta_old,HH_freq,VS,Cw)

    Ur = dftmtx(M)/sqrt(M);
    Ut = dftmtx(Nu)/sqrt(Nu);
    A=zeros(K,K);
    for u =1:U
        HH_freq(:,:,1,1,u) = Ur*HH_freq(:,:,1,1,u)*Ut';
        A =  A + VS'*Cw^(-1/2)*HH_freq(:,:,1,1,u)*P(:,:,u)*HH_freq(:,:,1,1,u)'*Cw^(-1/2)*VS; 
    end
    Rs = real(log_det(eye(K)+A));

    W_sum = 0;
    for u  = 1:U
        W_sum = W_sum + xi*sum(diag(P(:,:,u)))+ W_cu;
    end
    W_sum = W_sum + K*W_s + W_BS; 

    object =Rs - eta_old*W_sum;

end


Status: Infeasible
Optimal value (cvx_optval): -Inf

wrong use .* (line 173)
Disciplined convex programming error:
Cannot perform the operation: {invalid} .* {real affine}

wrong * (line 36)
z = feval( oper, x, y );

wrong cvxobject_monte (line 32)
object =Rs - eta_old*W_sum;

wrong: Copy_of_DMA_EE_montecalor (line 75)
object = cvxobject_monte(K,U,M,Nu,W_cu,W_s,W_BS,xi,P,eta_old,HH_freq,Q_OD,Cw);

You don’t seem to be showing us the complete output in the order in which it appeared. Perhaps you are running the CVX optimization inside a loop you are not showing us?

You don’t show us where eta_old is ever assigned, but perhaps eta_old has a value of NaN when it appears in a CVX expression, triggering the Cannot perform the operation: {invalid} .* {real affine} error. Was era_old assigned to some output from a previous CVX optimization, and perhaps that optimization did not terminate with an optimal value (maybe due ro being infeasible or the solver failing for some reason), and tha output it was assigned to was NaN?

It looks like my guesses were correct. Perhaps you can show us the solver and CVX output? What happens on the CVX invocation for which what becomes eta_old is NaN. What is the first NaN in the chain of calculations leading to that NaN?

guess you mean these outputs?
CVX_solver: Mosek

Here is the part of the output after the first invocation to CVX

Warning: This linear matrix inequality appears to be unsymmetric. This is
very likely an error that will produce unexpected results. Please check
the LMI; and, if necessary, re-enter the model.

Status: Failed
Optimal value (cvx_optval): NaN

Moreover, after the first invocation to CVX, all elements of P are NAN, and then eta_old(calculated by P) turns to NAN. and then program interrupts. This confuses me. And I have no idea about how to figure out which part of the object function makes NAN appear

Do you want P to be constrained to be semidefinite? if so, either change
variable P(Nu,Nu,U) nonnegative
to
variable P(Nu,Nu,U) nonnegative symmetric
or to
variable P(Nu,Nu,U) nonnegative semidefinite
if the latter is used, you do not need the statement P >= 0 and don’t even need to declare sdp mode.

If you only want the elements of P to be nonnegative, but don’t want to constrain P to be semidefinite, get rid of the P >= 0 statement.

Fix this, and then see what happens on the first iteration through the while loop. Don’t ignore warning messages.

I change variable P(Nu,Nu,U) nonnegative
to
variable P(Nu,Nu,U) nonnegative semidefinite
The warning has been resolved.
What’s more, I change the rate expression in cvx object:
A = A + VS’*Cw^(-1/2)*HH_freq(:,:,1,1,u)*P(:,:,u)*HH_freq(:,:,1,1,u)’*Cw^(-1/2)VS;
to
A = A + HH_freq(:,:,1,1,u)P(:,:,u)HH_freq(:,:,1,1,u)’(Cw^(-1/2)(VS
VS’)*Cw^(-1/2));
(the determinant identity log(det(I+AB)) = log(det(I+BA)))
and then cvx is working. But when the variable ‘VS’ has changed its value( optimized in the other part of the whole optimization), the mistake appears again. :thinking:

You need to state things more clearly and show the code for your last setence to be understandable.