How To multiply this Formula to run this code Please

2 Ansichten (letzte 30 Tage)
Dalia ElNakib
Dalia ElNakib am 2 Mai 2023
Kommentiert: Dalia ElNakib am 2 Mai 2023
Dear Eng.
How I can formulate this as either vectors or numeric only to unify the folmlua
A(i,:) = A(i,:) + h(i)*[0, ones(1,i-1), 0, ones(1,n-i)];
I mean to avoid multipling Numeric by Vector
In order to apply this:
n = 3
h(1) = 0.6;
h(2) = 0.8;
h(3) = 1;
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:n
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
% 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)]);
Thank You so much
  2 Kommentare
Torsten
Torsten am 2 Mai 2023
How do you want to set the elements of the matrix A ?
The vector
[0, ones(1,i-1), 0, ones(1,n-i)];
has length n+1, thus cannot be a row of the matrix A which has to be mxn.
Dalia ElNakib
Dalia ElNakib am 2 Mai 2023
Bearbeitet: Dalia ElNakib am 2 Mai 2023
To set Matrix A to be (3*3) Please
Can you help me in that please? in order to be compatible with the Length of this command
Many Thanks for your cooperation

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

MarKf
MarKf am 2 Mai 2023
The fact that there is the need for a loop for these operations, that b is not simply obtained with b=-T.*h, that [ones(1,i-1), 0, ones(1,n-i)] produces [0 1 1] [1 0 1] [1 1 0] for each iteration and the diagonal value is added to it, I'm guessing that OP simply needs to eliminate the first 0 from that vector. I hope this code is not used to control infrastructure or anything important.
n = 3;
h = [0.6 0.8 1];
T = 4;
A = zeros(n);
b = zeros([n,1]);
for i = 1:n
A(i,i) = -h(i);
A(i,:) = A(i,:) + h(i)*[ones(1,i-1), 0, ones(1,n-i)];
b(i) = -T*h(i);
end

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by