필터 지우기
필터 지우기

How To multiply this Formula to run this code Please

조회 수: 6 (최근 30일)
Dalia ElNakib
Dalia ElNakib 2023년 5월 2일
댓글: Dalia ElNakib 2023년 5월 2일
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
Torsten
Torsten 2023년 5월 2일
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 2023년 5월 2일
편집: Dalia ElNakib 2023년 5월 2일
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

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

채택된 답변

MarKf
MarKf 2023년 5월 2일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by