Borrar filtros
Borrar filtros

How To multiply this Formula to run this code Please

6 visualizaciones (últimos 30 días)
Dalia ElNakib
Dalia ElNakib el 2 de Mayo de 2023
Comentada: Dalia ElNakib el 2 de Mayo de 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 comentarios
Torsten
Torsten el 2 de Mayo de 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 el 2 de Mayo de 2023
Editada: Dalia ElNakib el 2 de Mayo de 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

Iniciar sesión para comentar.

Respuesta aceptada

MarKf
MarKf el 2 de Mayo de 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

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by