error:Conversion to double from cvx is not possible

hello,this is my code

function[Pr,Rr]=SolveP1(Pr)
global beta0 H  N1 N2  V L d0  tolerance  P_ave p1 p2 M SNR  R S;
L=2000;
N=100;
H=100;
N1=1.0000e-17;
N2=1.0000e-17;
P_ave=5;
beta0= 2*10^(-5); 
R=6.7167e+08;
B=2*10^7;
tolerance=0.0001;
tol=tolerance;
M=100;
m = 1 : 1: M;
Q(1,m) = ((L)*(m-1)/(M-1));
Q(2,m)=0;
Qr=Q;
P_begin=10*ones(2,M);
Pl={P_begin};
for l=1:100
     itera=l
    h_au=beta0./((Qr(1,:)-L*ones(1,M)).^2 +Q(2,:).^2 +(H*ones(1,M)).^2);%constant 1*M
    h_ub=beta0./(Q(1,:).^2 +Q(2,:).^2 +H*ones(1,M).^2);%constant  1*M 
    gama=(Pl{l}(1,:).*Pl{l}(2,:).*h_au.*h_ub )  ./  (Pl{l}(2,:).*h_au*N2 +Pl{l}(1,:).*h_ub*N1+ N1*N2*ones(1,M));%constant 1*M  %constant
    gama_inv=(Pl{l}(1,:).*h_au*N2+Pl{l}(2,:).*h_ub*N1+N1*N2*ones(1,M))./(Pl{l}(1,:).*Pl{l}(2,:).*h_au.*h_ub);   %constant 
    R_itera=B*log2(1+gama);
    
    
    cvx_begin 
    variable P(2,M)
    expression S
   for i=1:1:M
         gama_inv1(i)=P(1,i).*h_au(i)*N2+P(2,i).*h_ub(i)*N1+N1*N2 .*(prod_inv([P(1,i) P(2,i)]).*h_ub(i).*h_au(i));
     end
       S=(gama.^2 *log2(exp(1))  ./ (2*(gama+1)))  .* (gama_inv1-gama_inv);
       
    maximize sum(R_itera-S)
 
    subject to
    sum(P(1,:))<=N*20
    sum(P(2,:))<=N*20
    0<=P(1,:)
    0<=P(2,:)
    cvx_end
    Pr=P
     Pl = cat(1, Pl, {Pr});%stored the value in the i iteration and use it in the i+1 iteration 
    Rl=sum(R_itera-S);
    R=[R,Rl];
    
    if (l >= 2) &&(R(l) - R(l-1) < tol)
        break;
    end
end
save P
f = msgbox('over!', 'Done', 'help');
end

I try to solve a convex problem through iteration until the result converges,the error occured in
for i=1:1:M
gama_inv1(i)=P(1,i).*h_au(i)*N2+P(2,i).h_ub(i)N1+N1N2 .(prod_inv([P(1,i) P(2,i)]).*h_ub(i).*h_au(i));
end
I have referd seveal the same mistake in forum ,such as gama_invl =cvx(1,N) or expression gama_invl and so on ,but it does not work ,the mistake occured in the second iteration,when iteration=1,it work properly
what is werong witn me? thank you!

You haven’t provided a reproducible problem. You haven’t shown us the solver and CVX output from either iteration. Did you carefully examine the output from the first iteration, hence the input for the 2nd iteration?

Google:
Conversion to double from cvx is not possible

Did you examine all the items in the statement which triggered the error message?

Here are some possible issues:

The input data is horribly scaled, which can make solving problems numerically unreliable. You are using a crude, unsafeguarded iterative algorithm which might not converge to anything, let alone a local minimum of your original problem.

this is the detail
text1

itera =

 1

Warning: A non-empty cvx problem already exists in this scope.
It is being overwritten.

In cvxprob (line 28)
In cvx_begin (line 41)
In text1 (line 31)

Calling SDPT3 4.0: 1202 variables, 600 equality constraints
For improved efficiency, SDPT3 is solving the dual problem.

num. of constraints = 600
dim. of sdp var = 600, num. of sdp blk = 300
dim. of linear var = 302


SDPT3: Infeasible path-following algorithms


version predcorr gam expon scale_data
HKM 1 0.000 1 0
it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime

0|0.000|0.000|3.5e+02|1.7e+01|8.1e+05| 1.737815e+03 0.000000e+00| 0:0:00| spchol 1 1
1|0.600|0.456|1.4e+02|9.5e+00|5.0e+05| 5.699196e+03 -1.237838e-18| 0:0:00| spchol 1 1
2|0.544|0.570|6.4e+01|4.1e+00|2.5e+05| 1.014558e+04 -1.140069e-18| 0:0:00| spchol 1 1
3|0.705|0.765|1.9e+01|9.6e-01|8.1e+04| 1.422853e+04 -1.072818e-18| 0:0:00| spchol 1 1
4|0.775|0.989|4.3e+00|1.1e-02|1.6e+04| 1.134092e+04 -1.052767e-18| 0:0:01| spchol 1 1
5|0.986|1.000|6.1e-02|1.7e-04|2.6e+02| 1.989940e+02 -1.052595e-18| 0:0:01| spchol 1 1
6|0.989|1.000|6.8e-04|1.2e-02|3.2e+00| 2.203433e+00 -1.052591e-18| 0:0:01| spchol 1 1
7|0.980|1.000|1.3e-05|1.4e-04|8.4e-02| 6.942582e-02 -1.052280e-18| 0:0:01| spchol 1 1
8|0.989|1.000|1.5e-07|2.8e-06|9.4e-04| 7.741899e-04 -1.052276e-18| 0:0:01| spchol 1 1
9|0.989|1.000|1.6e-09|4.7e-08|1.0e-05| 8.511585e-06 -1.052276e-18| 0:0:01| spchol 1 1
10|0.985|1.000|2.4e-11|3.3e-10|2.3e-07| 2.033010e-07 -1.052274e-18| 0:0:01| spchol 1 1
11|0.986|1.000|3.3e-13|4.8e-12|4.9e-09| 4.569651e-09 -1.052272e-18| 0:0:01|
stop: max(relative gap, infeasibilities) < 1.49e-08

number of iterations = 11
primal objective value = 4.56965061e-09
dual objective value = -1.05227239e-18
gap := trace(XZ) = 4.94e-09
relative gap = 4.94e-09
actual relative gap = 4.57e-09
rel. primal infeas (scaled problem) = 3.25e-13
rel. dual " " " = 4.80e-12
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual " " " = 0.00e+00
norm(X), norm(y), norm(Z) = 4.1e-10, 3.5e+03, 3.5e+03
norm(A), norm(b), norm© = 4.2e+01, 1.0e+00, 1.4e+02
Total CPU time (secs) = 0.85
CPU time per iteration = 0.08
termination code = 0
DIMACS: 3.3e-13 0.0e+00 6.8e-12 0.0e+00 4.6e-09 4.9e-09


Status: Solved
Optimal value (cvx_optval): +3.90777e+10

itera =

 2

The following error occurred converting from cvx to double:
Conversion to double from cvx is not possible.

Error in text1 (line 35)
gama_inv1(i)=P(1,i).*h_au(i)*N2+P(2,i).h_ub(i)N1+N1N2 .(prod_inv([P(1,i)
P(2,i)]).*h_ub(i).*h_au(i));

The order of magnitude of h_au and h_ub are 10^(-7)~10^(-12),

You need to declare gama_inv1 an expression, i.e., use expression holder. http://cvxr.com/cvx/doc/basics.html#assignment-and-expression-holders

Thank you for your patience!it works now