Index exceeds matrix dimensions. running my_code

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)

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``````

Your problem is not reproducuble. For instance, `cvx_p` is not provided.

Your problem has terrible scaling - try to get numbers closer to 1 in magnitude by changing units.

Don’t use `cvx_quiet(true)` until you have verified that evrything is running properly, which it obviously is not.

As for the error message, I can’t run the program myself because as stated above, it is not reproducible. That said, it looks like either a CVX bug, or a “messed up” CVX installation. What is the output of `cvx_version` ? Install CVX 2.2 if you are running another version of CVX.Do NOT use CVX 3.0beta., which is known to have many serious bugs.

Your topic title says “Index exceeds matrix dimensions”, but your post doesn’t show this error.

`cvx_p` is provided as follow:
1.The flie of ‘cvx_p.m’
function [P_rs,P_rd,T]=cvx_p(t_min,t_max,P_rmax)
B_rs=30010^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(-i2pi/lamda(D-drs))ones(1,n) + sqrt(1/(K+1))sqrt(1/2)(randn(1,n)+irandn(1,n));

cvx_begin
%cvx_quiet(true);
variable P_rs;
variable P_rd;
expression R_rs;
expression R_rd;
R_rs=B_rslog(1+(rho(k+1)a(cos(phi)^(k))(cos(psi))P_rs)/(2(pi)B_rsdrs^2N_rs));

R_rd=B_rdlog(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

Cones | Errors | Mov/Act | Centering Exp cone Poly cone | Status --------±--------------------------------±-------- 3/ 3 | 8.000e+00 2.299e+01 0.000e+00 | Unbounded 3/ 3 | 8.000e+00s 1.752e+01 0.000e+00 | Unbounded 1/ 1 | 8.000e+00 9.599e+00 0.000e+00 | Unbounded 2/ 2 | 8.000e+00 4.100e+00 0.000e+00 | Unbounded 0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Unbounded

Status: Infeasible
Optimal value (cvx_optval): +Inf

y = max( sparse( r, c, cvx___.readonly( r ), s(1), s(2) ), [], 1 );

Error cvxprob/newcnstr (line 94)

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));

Error main (line 9)
[P_rs,P_rd,t]=cvx_p(t_min,t_max,P_max);
4.Could you please reproduce my problem again and give some guidance？Thanks!

As I wrote before, fix the scaling. This may not be easy, but it is essential.

If the problem is still reported by CVX as infeasible, follow the advice in https://yalmip.github.io/debugginginfeasible/ (except for section 1, which does not apply to CVX).

ok，I try to solve it.But i have another question,When cvx verifies the feasible domain, there is no objective function, but the format of cvx must have an objective function. Is the objective function written min0?

CVX does not require an objective function. Having no objective function is basically the same as specifying a constant objective function, such as `minimize 0` . .

By specifying `minimize 0`, you are specifying a feasibility problem, i.e., any feasible solution is “optimal”.

ok,thanks so much!That is to say my errors is not because of my model,it roots in function of log during solver in cvx.