2 views (last 30 days)
Kamilu Sanusi on 29 Jan 2023
Commented: Walter Roberson on 2 Feb 2023
Hello
I am trying to solve an equation of which i need to be using the new values of V and delta as an update in equations (1).The closed equation (1) when expanded will be in the form of equation (2) for i = 2 and j is between 1 -5.
% P(i) = sum(j=1->n) |Vi||Vj|(Gij * cos(delta_i - delta_j) + Bij * sin(delta_i - delta_j) EQUATION (1) % The formula for calculating the P
Implementation of P(2) for example:
P(2) = P(2) + V(2)*V(1)*(G(2,1)*cos(delta(2)-delta(1)) + B(2,1)*sin(delta(2)-delta(1))) + V(2)*V(2)*(G(2,2)*cos(delta(2)-delta(2)) + B(2,2)*sin(delta(2)-delta(2))) + V(2)*V(3)*(G(2,3)*cos(delta(2)-delta(3)) + B(2,3)*sin(delta(2)-delta(3))) + V(2)*V(4)*(G(2,4)*cos(delta(2)-delta(4)) + B(2,4)*sin(delta(2)-delta(4))) + V(2)*V(5)*(G(2,5)*cos(delta(2)-delta(5)) + B(2,5)*sin(delta(2)-delta(5))) EQUATION (2)
Please is the below program good enough to represent the expansion of P(2) in equation (2) as an example ?
% Program
P = zeros(nbus,1);
Q = zeros(nbus,1);
V = zeros(nbus,1);
% B and G are constants
% Computing P
% nbus = 5
for i = 1:nbus
for j = 1:nbus
if type(i) == 2 % Computing Pi & Qi for Droop bus
P(i) = V(i)*V(j)*(G(i,j)*cos(delta(i)-delta(j)) + ...
B(i,j)*sin(delta(i)-delta(j)))+ PO(i)-PL(i);
Q(i) = V(i)*V(j)*(G(i,j)*sin(delta(i)-delta(j)) - ...
B(i,j)*cos(delta(i)-delta(j)))+ QO(i)-QL(i);
end
end
end
Walter Roberson on 2 Feb 2023
for i = 1:nbus
for j = 1:nbus
if type(i) == 2 % Computing Pi & Qi for Droop bus
That is inefficient. type(i) does not change according to changes in j, so you should be testing type(i) outside the for j loop, only executing the for j loop if type(i) == 2
P(i) = V(i)*V(j)*(G(i,j)*cos(delta(i)-delta(j)) + ...
B(i,j)*sin(delta(i)-delta(j)))+ PO(i)-PL(i);
Q(i) = V(i)*V(j)*(G(i,j)*sin(delta(i)-delta(j)) - ...
B(i,j)*cos(delta(i)-delta(j)))+ QO(i)-QL(i);
P(i) does not depend upon P(i) or Q(i) so at each different j you completely overwrite P(i) and Q(i) and the final result will be the same as if you had only done the final j=nbus .

### Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!