Clear Filters
Clear Filters

How To multiply this Formula to run this code Please

2 views (last 30 days)
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);
% 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(['Minimum total power transmitted: ', num2str(fval)]);
Thank You so much
Torsten on 2 May 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 on 2 May 2023
Edited: Dalia ElNakib on 2 May 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

Sign in to comment.

Accepted Answer

MarKf on 2 May 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);

More Answers (0)


Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!