 # Why do I have error (NaN) when trying to solve linear programming problem?

I am trying to solve a linear programming problem but it always shows my error. I have no idea why it always returns an error. It says
Unable to use a value of type struct as an index.

Error in cvxprob/solve (line 435)
[ x, status, tprec, iters ] = shim.solve( At, b, c, cones, quiet, prec, solv.settings, eargs{:} );

Error in cvx_end (line 88)
solve( prob );

Error in Project (line 90)
cvx_end

Any help will be greatly appreciated!!! The following are my codes. In my case, M = 1.

clear all
clc
K = 6; % Number of ground users
M = 1; % Number of UAVs in different case
X = 2e3;
Y = 2e3; % Range of area
X_max = 1000;
X_min = -1000;
Y_max = 1000;
Y_min = -1000;
H = 100; % Altitude
sigma_2 = 10^(-110/10)*1e-3; % Receiver noise power(Watts)

rho_0 = 10^(-60/10); % Unit channel power(Watts)
P_max = 0.1; % Maximum transmit power(Watts)
V_max = 50; % Maximum UAV speed
thresh = 1; % Threshold in Algo 1

d_min = 100; % Minimum interference distance
tau = 100;

User_pos = zeros(K,2); % Init user position
User_pos(:,1) = X_min + Xrand(K,1);
User_pos(:,2) = Y_min + Y
rand(K,1);

%% Single UAV Case
%T = [30, 60, 210]; % Different time duration settings
T = 30;
usr_1 = [-419, 410]; % Location of usr_1
usr_2 = [600, 1130]; % Location of usr_2
P = P_max; % Init of power
obj = 1000000; % Init of delta objective

%%
for i = 1:1
%% Trajectory initialization
N = V_maxT(i)/(Hthresh); % determine the minimum number of slots
r_max = V_maxT(i)/(2pi);
c_g = mean(User_pos, 1); % center position
x_trj = c_g(1);
y_trj = c_g(2);
ru = max(norm(c_g - User_pos, 2));
r_trj = min(ru/2, r_max);
q = zeros(N,2);
for n = 1:N
q(n, = [x_trj + r_trjcos(2pi*(n-1)/(N-1)), y_trj + r_trjsin(2pi*(n-1)/(N-1))];
end

``````r = 0;
%%
%while obj > thresh
r = r + 1; % rth iteration
%% Initialize distance, channel gain and gamma from UAV to user
d = zeros(K,N);
h = zeros(K,N);
gamma = zeros(K,N);
for n = 1:N
for k = 1:K
d(k,n) = sqrt(H^2 + norm(q(n,:) - User_pos(k,:), 2)^2);
h(k,n) = rho_0/(d(k,n)^2);
gamma(k,n) = P*h(k,n)/sigma_2;
end
end

%% User scheduling and Association Optimization
cvx_begin
variable a(K, N)
variable eta
maximize eta
subject to
for k = 1:K
(1/N)*sum(a(k,:).*log2(1+gamma(k,:)), 2) >= eta;
for n = 1:N
0 <= a(k,n) <= 1;
end
end
max(sum(a, 1)) <= 1;
cvx_end
disp(optval)
``````

end

Try reinstalling CVX, and make sure it is CVX 2.2/.

Hi Mark. Do you mean CVX 2.2 doen’t work?

Sorry, that was a typo, which I have now fixed. Use CvX 2.2. Do not use CVX 3.0beta, which has many bugs.