How to maximize achievable Rate for spectrum sharing in MIMO?

3 visualizaciones (últimos 30 días)
Nasrin
Nasrin el 20 de Jul. de 2024
Editada: Umar el 19 de Ag. de 2024
Hello, I am simulating a paper. I want to maximize achievable rate but there is an error in my code. the problem is maximiz (sum(log(1 + p2_k/ (sigma^2 + norm(w2_k,2)^2)))) when P2 and W2 are my variable matrices subject to 0=< p2_k =< tilde_P2 and sum( p2_k * xi_k =< zeta1_l. I used CVX function for optimization but I am not sure if it is true or not. my error is
Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {convex}
I would really appreciate it if someone could help me with it.
thank you in advance.
  3 comentarios
Nasrin
Nasrin el 20 de Jul. de 2024
@William Rose thank you. I copied my code bellow.
% Define constants
Ns = 4; % Number of secondary users
Ms = 20;
Nup = 200; % value for Nup
Nt = 12; % value for Nt
Np = 200; % value for Np
sigma2_dBm = -104; % Noise power in dB
tilde_P2_dBW = 20; % Maximum power constraint for secondary users
xi_k = rand(Ns, 1); % Example values for xi_k, replace with actual values
hat_zeta1_l = rand(Np, 1); % Example values for hat_zeta1_l, replace with actual values
P2 = rand(Ns,1);
W2 = rand(Ns,Ms);
%convert dB to linear
tilde_P2 = 10^(tilde_P2_dBW/10);
sigma2 = 10^(sigma2_dBm/10 -3 ); %dBm to mW then to W
% % Define the function f(P_tilde1) as a placeholder
% f = @(P_tilde1) rand(Ns, 1); % Example function, replace with actual function
%
% % Calculate xi_k using the function f and some P_tilde1
% P_tilde1 = 10:5:60; % Example value, replace with actual value
% xi_k = f(P_tilde1);
% CVX optimization
cvx_begin
variables P2(Ns,1) W2(Ms,Ns)
expression gamma_2k(Ns)
expression log_terms(Ns)
% Calculate gamma_2k and log terms
for k = 1:Ns
gamma_2k(k) = P2(k) / (sigma2 * square_pos(W2(k)));
log_terms(k) = log(1 + gamma_2k(k));
end
% Objective function
maximize((Nup - Nt) / Nup * sum(log_terms))
% Constraints
subject to
0 <= P2(k) <= tilde_P2 / Ns;
for l = 1:Np
sum(P2(k) .* xi_k) <= hat_zeta1_l(l);
end
cvx_end
Unrecognized function or variable 'cvx_begin'.
Walter Roberson
Walter Roberson el 20 de Jul. de 2024
My interpretation would be that you have an operation which is Real_Value divided by Complex_Value and it is complaining about that. You may need to specifically convert the Real_Value to complex

Iniciar sesión para comentar.

Respuestas (1)

Umar
Umar el 19 de Ag. de 2024
Editada: Umar el 19 de Ag. de 2024

Hi @Nasrin ,

After analyzing your error you encountered regarding cvx_begin, I did some research and find out that you probably need to make sure that the CVX package is correctly installed and initialized in your MATLAB environment.

CVX installation instructions

Download the CVX package from

https://cvxr.com/cvx/download/

Unzip the downloaded files into your directory then add the CVX folder to your Matlab path using:

   addpath('path_to_cvx_directory');

Afterwards, initialize CVX by running the command:

   cvx_setup;
This command will set up CVX and check for any missing components.

Update Code

Here’s an updated version of your code with additional checks for clarity and error handling:

% Define constants
Ns = 4; % Number of secondary users
Ms = 20;
Nup = 200; % value for Nup
Nt = 12; % value for Nt
Np = 200; % value for Np
sigma2_dBm = -104; % Noise power in dB
tilde_P2_dBW = 20; % Maximum power constraint for secondary users
xi_k = rand(Ns, 1); % Example values for xi_k, replace with actual values
hat_zeta1_l = rand(Np, 1); % Example values for hat_zeta1_l, replace with 
actual values
% Convert dB to linear
tilde_P2 = 10^(tilde_P2_dBW/10);
sigma2 = 10^(sigma2_dBm/10 - 3);  % Convert dBm to mW then to W
% Initialize CVX optimization
cvx_begin quiet
    variables P2(Ns,1) W2(Ms,Ns)
    expression gamma_2k(Ns)
    expression log_terms(Ns)
     % Calculate gamma_2k and log terms
     for k = 1:Ns
        gamma_2k(k) = P2(k) / (sigma2 * square_pos(W2(k)));
        log_terms(k) = log(1 + gamma_2k(k));
      end
      % Objective function
       maximize((Nup - Nt) / Nup * sum(log_terms))
      % Constraints
       subject to
        for k = 1:Ns
            0 <= P2(k) <= tilde_P2 / Ns;
            for l = 1:Np
                sum(P2(k) .* xi_k) <= hat_zeta1_l(l);
            end
        end
cvx_end
% Check if optimization was successful
    if strcmp(cvx_status, 'Solved')
    disp('Optimization successful!');
else
    disp('Optimization failed!');
end

In the code, you will see the addition of a check on cvx_status which allows you to identify whether the optimization was successful. Also, make sure that square_pos is defined elsewhere in your code or replace it with a suitable function if it's not recognized and when you are working with larger datasets or more complex models, consider optimizing your constraints or objective function further to improve performance.

Hope this helps. Please let us know if you have any further questions.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by