The test code is as follows:
clc;
clear all;
close all;
tic;
cvx_solver Mosek_2;
cvx_save_prefs;
% Randomly generate task sizes
Sm_list = (rand(1) + 3) * 10^5; % The size of each task (bits)
% Set distance parameters
WDAP.distance = 10;
WDEve.distance = 15;
JamAP_distance = 50;
JamEve_distance = 8;
% Path loss parameters
alpha = 3;
belta = -30; % Reference path loss (dB)
belta = db2pow(belta); % Convert dB to mW
% Channel gain calculation
WDAP_H = belta * WDAP.distance ^ (-alpha);
JamAP_H = belta * WDEve.distance ^ (-alpha);
% System parameter settings
B = 1 * 10^6; % Total bandwidth (Hz)
p_max = 0.23; % Maximum transmission power (W)
Pj_max = 1; % Maximum cooperative jamming transmission power (W)
% Noise power settings
noise = -110; % Noise power (dB)
noise = db2pow(noise); % Convert dB to mW
% Initialize iteration parameters
iteration = 0;
Dink = ;
I = 0.2 * 10^6; % Number of bits or 200 kbits
nosie_z = 10^(3/10);
nosie_k = 10^(-120/10);
T_p = 0.5 * p_max;
T_Pj = 0.5 * Pj_max; % Used for SCA and Dinkelbach
T_W = log(1 + T_p * WDAP_H / (T_Pj * JamAP_H + noise)) / log(2);
epsilon = 1e-5; % Small positive number to prevent division by zero
% Objective function initialization
F1 = 0;
F2 = 0;
F3 = 0;
F4 = 0;
% Main loop starts
while 1
cvx_begin
variable p
variable Pj
variable T
variable V
variable W
expressions F1 F2 F3 F4
% Update expressions
F1 = I / (B * max(T_W, epsilon)) - (I * (W - T_W)) / (B * (T_W^2 + epsilon^2));
F2 = W + log(Pj * JamAP_H + noise) / log(2) - log(T_p * WDAP_H + T_Pj * JamAP_H + noise) / log(2) - ...
(WDAP_H * (p - T_p)) / ((T_p * WDAP_H + T_Pj * JamAP_H + noise) * log(2)) - ...
(JamAP_H * (Pj - T_Pj)) / ((T_p * WDAP_H + T_Pj * JamAP_H + noise) * log(2));
F3 = V - p * WDAP_H - nosie_k / nosie_z;
F4 = log(nosie_k * nosie_z) / (2 * log(nosie_z)) - V / (2 * log(nosie_z));
% Minimize the objective function
minimize T
subject to
F1 >= T;
F2 >= 0;
F3 >= 0;
F4 >= 0.98;
p <= p_max;
Pj <= Pj_max;
p > 0;
Pj > 0;
T > 0;
V > 0;
W > 0;
cvx_end
iteration = iteration + 1;
T_p = p;
T_Pj = Pj;
T_W = W;
Dink = [Dink, cvx_optval];
if length(Dink) > 1 && abs(Dink(end) - Dink(end-1)) < 1e-2
break
end
end
T_min = cvx_optval; % Minimum value
The following error occurs:
错误使用 + (line 83)
Disciplined convex programming error:
Illegal operation: {real affine} - {invalid}
出错 - (line 21)
z = plus( x, y, true, cheat );
出错 ceshi3 (line 64)
F1 = I / (B * max(T_W, epsilon)) - (I * (W - T_W)) / (B * (T_W^2 + epsilon^2));
The test code is believed to consist entirely of convex functions, and Mosek has been installed. Is the issue caused by the parameters?
Requesting the teacher to provide an help.