To write perfectly this command: A(i,:) = A(i,:) + h(i)*[0, ones(1,i-1), 0, ones(1,n-i)];

1 回表示 (過去 30 日間)
Dalia ElNakib
Dalia ElNakib 2023 年 5 月 2 日
コメント済み: Walter Roberson 2023 年 5 月 3 日
Please I need to express this command perfectly:
A(i,:) = A(i,:) + h(i)*[0, ones(1,i-1), 0, ones(1,n-i)];
In order to Run this:
n = 3
n = 3
h(1) = 0.6
h = 0.6000
h(2) = 0.8
h = 1×2
0.6000 0.8000
h(3) = 1
h = 1×3
0.6000 0.8000 1.0000
T = 4
T = 4
% Objective function: minimize total power transmitted by all users
f = ones(n, 1);
% Inequality constraints: signal-to-interference ratio must exceed threshold
A = zeros(n,n);
b = zeros(n,1);
for i = 1:3
A(i,i) = -h(i);
A(i,:) = A(i,:) + h(i)*[0, ones(1,i-1), 0, ones(1,n-i)];
b(i) = -T*h(i);
end
Arrays have incompatible sizes for this operation.
% Lower bounds: power transmitted by each user must be non-negative
lb = zeros(n,1);
% Solve using linprog
[x, fval] = linprog(f, A, b, [], [], lb);
% Display results
disp('Optimal power transmitted by each user:');
disp(x);
disp(['Minimum total power transmitted: ', num2str(fval)]);

採用された回答

Walter Roberson
Walter Roberson 2023 年 5 月 2 日
n = 3
A = zeros(n,n);
So A will be initialized as 3 x 3
for i = 1:3
A(i,i) = -h(i);
A(i,:) = A(i,:) + h(i)*[0, ones(1,i-1), 0, ones(1,n-i)];
when i = 1 then:
  • literal 0 is a 1 x 1 scalar
  • ones(1,i-1) is ones(1,0) which is 1 x 0 empty
  • literal 0 is 1 x 1 scalar
  • ones(1,n-i) is ones(1,3-1) (for this iteration) which is ones(1,2) which is 1 x 2
Those widths are 1 + 0 + 1 + 2 = 4.
So you are trying to add a 1 x 4 vector to a 1 x 3 vector A(i,:)
  5 件のコメント
Torsten
Torsten 2023 年 5 月 3 日
Matlab needs a multiplication sign (*) between numbers you want to multiply.
Walter Roberson
Walter Roberson 2023 年 5 月 3 日
Assuming that g and h are row vector
A = - h * g.';
A(1:n+1:end) = h;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by