hello,everyone! I’m a new user for using cvx .when i use it with a log constraint,code emits an error as follows,wishing one could help me to sovle it or give me some help.
error cvx/cvx_readlevel (line 6)
y = max( sparse( r, c, cvx___.readonly( r ), s(1), s(2) ), [], 1 );
error cvxprob/newcnstr (line 94)
tx = cvx_readlevel( x );
error <= (line 21)
b = newcnstr( evalin( ‘caller’, ‘cvx_problem’, ‘[]’ ), x, y, ‘<=’ );
error cvx/log (line 74)
exp( yt ) <= xt; %#ok
error cvx_p (line 25)
R_rs=B_rslog(1+(rho^2(k+1)^2a^2(cos(phi)^(2k))(cos(psi)^2)P_rs)/(4(pi^2)B_rsdrs^2*N_rs));
main (line 9)
[P_rs,P_rd,t]=cvx_p(t_min,t_max,P_max);
my main function as follows:
clc;clear
t_min=1;
t_max=2*10^10;
P_max=20;
epsilon=0.0001;
%save result for per n
save_n_result=[];
for n=1:1000
[P_rs,P_rd,t]=cvx_p(t_min,t_max,P_max);
save_n_result=[save_n_result;[P_rs,P_rd,t]];
if isnan([P_rs,P_rd])
t_max=t;
if t_max-t_min<epsilon
break;
end
else
t_min=t;
if t_max-t_min<epsilon
break;
end
end
end
The cvx solving codes as follows:
function [P_rs,P_rd,T]=cvx_p(t_min,t_max,P_rmax)
B_rs=300*10^6;
B_rd=60*10^6;
N_rs=10^(-24);
N_rd=10^(-19);
phi=pi/3;
psi=pi/3;
a=1;
rho=0.8;
k=-log(2)/log(cos(pi/3));
Pmax=20;
D=20;
drs=10;
n=1000;
K=10;
lamda=5e-3;
h_rd=sqrt(K/(K+1))*exp(-i*2*pi/lamda*(D-drs))*ones(1,n) + sqrt(1/(K+1))*sqrt(1/2)*(randn(1,n)+i*randn(1,n));
cvx_begin
cvx_quiet(true);
variable P_rs;
variable P_rd;
expression R_rs;
expression R_rd;
R_rs=B_rs*log(1+(rho*(k+1)*a*(cos(phi)^(k))*(cos(psi))*P_rs)/(2*(pi)*B_rs*drs^2*N_rs));
R_rd=B_rd*log(1+P_rd*((norm(h_rd))^2)/(B_rd*N_rd));
minimize 0;
subject to
-R_rs<=-1/2*(t_min+t_max)%constraint 1
-R_rd<=-1/2*(t_min+t_max)%constraint 2
P_rd>=0
P_rs>=0
P_rs+P_rd<=P_rmax
cvx_end
T=1/2*(t_min+t_max);
end