I have this code in my matlab but it has an error as:
Incorrect number or types of inputs or outputs for function vec.
I would really appreciate it if you could help me to solve it.
I should emphasize that I installed cvx on my matla.
Np = 4;
Nsc= 4;
mu_l_n = [1.56247628361161e-06;
1.59519914659906e-06;
1.27498226759933e-06;
1.03143933197703e-05];
tilde_P1_tot = 1000;
sigma2_dBm = -104;
sigma2 = 10^(sigma2_dBm / 10 - 3);
cvx_begin quiet
Unrecognized function or variable 'cvx_begin'.
variable p1_l_n(Np) % Power allocation vector, column vector
term = (mu_l_n.^2 .* p1_l_n) / sigma2; % Define term for clarity
maximize(sum(log(1 + term))) % Objective function to maximize sum rates
subject to
sum(p1_l_n) == tilde_P1_tot / Nsc; % Total power constraint across subcarriers
p1_l_n >= 0; % Power must be non-negative
cvx_end
% Display the optimal power allocation
disp('Optimal power allocation:');
disp(p1_l_n);

답변 (1개)

M.
M. 2024년 10월 3일

0 개 추천

The code you provided works fine on my computer and outputs :
Optimal power allocation:
62.4982
62.4989
62.4901
62.5129
You have to make sure that the directory that stores the cvx toolbox is on your Matlab path.

댓글 수: 5

Nasrin
Nasrin 2024년 10월 3일
@M.would you please share your code with me?
because it does not work for my friend and me.
M.
M. 2024년 10월 3일
I simply launched your code with cvx installed...
Nasrin
Nasrin 2024년 10월 3일
@M.you might use a different version of Matlab. it does not work with matlab 2024.
thank you by the way.
Walter Roberson
Walter Roberson 2024년 10월 3일
Is the problem with R2024a or R2024b ?
Nasrin
Nasrin 2024년 10월 8일
@Walter Roberson matlab R2024a

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2024년 10월 2일

댓글:

2024년 10월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by