0% found this document useful (0 votes)
77 views

% Program For Newton-Raphson Load Flow Analysis: While

The document describes a program for performing Newton-Raphson load flow analysis on a power system network. It initializes the bus data, forms the Y-bus matrix, and iterates to solve for bus voltages and angles using the NR method. In each iteration, it calculates mismatch between specified and calculated power injections, forms the Jacobian matrix, and updates the state variables using the correction vector until the solution converges within the specified tolerance.

Uploaded by

Rahul_Kittu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

% Program For Newton-Raphson Load Flow Analysis: While

The document describes a program for performing Newton-Raphson load flow analysis on a power system network. It initializes the bus data, forms the Y-bus matrix, and iterates to solve for bus voltages and angles using the NR method. In each iteration, it calculates mismatch between specified and calculated power injections, forms the Jacobian matrix, and updates the state variables using the correction vector until the solution converges within the specified tolerance.

Uploaded by

Rahul_Kittu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

% Program for Newton-Raphson Load Flow Analysis

nbus = 14; % IEEE-14, IEEE-30, IEEE-57..


Y = ybusppg(nbus); % Calling ybusppg.m to get Y-Bus Matrix..
busd = busdatas(nbus); % Calling busdatas..
BMva = 100; % Base MVA..
bus = busd(:,1); % Bus Number..
type = busd(:,2); % Type of Bus 1-Slack, 2-PV, 3-PQ..
V = busd(:,3); % Specified Voltage..
del = busd(:,4); % Voltage Angle..
Pg = busd(:,5)/BMva; % PGi..
Qg = busd(:,6)/BMva; % QGi..
Pl = busd(:,7)/BMva; % PLi..
Ql = busd(:,8)/BMva; % QLi..
Qmin = busd(:,9)/BMva; % Minimum Reactive Power Limit..
Qmax = busd(:,10)/BMva; % Maximum Reactive Power Limit..
P = Pg - Pl; % Pi = PGi - PLi..
Q = Qg - Ql; % Qi = QGi - QLi..
Psp = P; % P Specified..
Qsp = Q; % Q Specified..
G = real(Y); % Conductance matrix..
B = imag(Y); % Susceptance matrix..

pv = find(type == 2 | type == 1); % PV Buses..


pq = find(type == 3); % PQ Buses..
npv = length(pv); % No. of PV buses..
npq = length(pq); % No. of PQ buses..

Tol = 1;
Iter = 1;
while (Tol > 1e-5) % Iteration starting..

P = zeros(nbus,1);
Q = zeros(nbus,1);
% Calculate P and Q
for i = 1:nbus
for k = 1:nbus
P(i) = P(i) + V(i)* V(k)*(G(i,k)*cos(del(i)-del(k)) +
B(i,k)*sin(del(i)-del(k)));
Q(i) = Q(i) + V(i)* V(k)*(G(i,k)*sin(del(i)-del(k)) -
B(i,k)*cos(del(i)-del(k)));
end
end

% Checking Q-limit violations..


if Iter <= 7 && Iter > 2 % Only checked up to 7th iterations..
for n = 2:nbus
if type(n) == 2
QG = Q(n)+Ql(n);
if QG < Qmin(n)
V(n) = V(n) + 0.01;
elseif QG > Qmax(n)
V(n) = V(n) - 0.01;
end
end
end
end
% Calculate change from specified value
dPa = Psp-P;
dQa = Qsp-Q;
k = 1;
dQ = zeros(npq,1);
for i = 1:nbus
if type(i) == 3
dQ(k,1) = dQa(i);
k = k+1;
end
end
dP = dPa(2:nbus);
M = [dP; dQ]; % Mismatch Vector

% Jacobian
% J1 - Derivative of Real Power Injections with Angles..
J1 = zeros(nbus-1,nbus-1);
for i = 1:(nbus-1)
m = i+1;
for k = 1:(nbus-1)
n = k+1;
if n == m
for n = 1:nbus
J1(i,k) = J1(i,k) + V(m)* V(n)*(-G(m,n)*sin(del(m)-del(n)) +
B(m,n)*cos(del(m)-del(n)));
end
J1(i,k) = J1(i,k) - V(m)^2*B(m,m);
else
J1(i,k) = V(m)* V(n)*(G(m,n)*sin(del(m)-del(n)) -
B(m,n)*cos(del(m)-del(n)));
end
end
end

% J2 - Derivative of Real Power Injections with V..


J2 = zeros(nbus-1,npq);
for i = 1:(nbus-1)
m = i+1;
for k = 1:npq
n = pq(k);
if n == m
for n = 1:nbus
J2(i,k) = J2(i,k) + V(n)*(G(m,n)*cos(del(m)-del(n)) +
B(m,n)*sin(del(m)-del(n)));
end
J2(i,k) = J2(i,k) + V(m)*G(m,m);
else
J2(i,k) = V(m)*(G(m,n)*cos(del(m)-del(n)) + B(m,n)*sin(del(m)-
del(n)));
end
end
end

% J3 - Derivative of Reactive Power Injections with Angles..


J3 = zeros(npq,nbus-1);
for i = 1:npq
m = pq(i);
for k = 1:(nbus-1)
n = k+1;
if n == m
for n = 1:nbus
J3(i,k) = J3(i,k) + V(m)* V(n)*(G(m,n)*cos(del(m)-del(n)) +
B(m,n)*sin(del(m)-del(n)));
end
J3(i,k) = J3(i,k) - V(m)^2*G(m,m);
else
J3(i,k) = V(m)* V(n)*(-G(m,n)*cos(del(m)-del(n)) -
B(m,n)*sin(del(m)-del(n)));
end
end
end

% J4 - Derivative of Reactive Power Injections with V..


J4 = zeros(npq,npq);
for i = 1:npq
m = pq(i);
for k = 1:npq
n = pq(k);
if n == m
for n = 1:nbus
J4(i,k) = J4(i,k) + V(n)*(G(m,n)*sin(del(m)-del(n)) -
B(m,n)*cos(del(m)-del(n)));
end
J4(i,k) = J4(i,k) - V(m)*B(m,m);
else
J4(i,k) = V(m)*(G(m,n)*sin(del(m)-del(n)) - B(m,n)*cos(del(m)-
del(n)));
end
end
end

J = [J1 J2; J3 J4]; % Jacobian Matrix..

X = inv(J)*M; % Correction Vector


dTh = X(1:nbus-1); % Change in Voltage Angle..
dV = X(nbus:end); % Change in Voltage Magnitude..

% Updating State Vectors..


del(2:nbus) = dTh + del(2:nbus); % Voltage Angle..
k = 1;
for i = 2:nbus
if type(i) == 3
V(i) = dV(k) + V(i); % Voltage Magnitude..
k = k+1;
end
end

Iter = Iter + 1;
Tol = max(abs(M)); % Tolerance..

end
loadflow(nbus,V,del,BMva); % Calling Loadflow.m..
% Program to for Admittance And Impedance Bus Formation....

function Y = ybusppg(num) % Returns Y

linedata = linedatas(num); % Calling Linedatas...


fb = linedata(:,1); % From bus number...
tb = linedata(:,2); % To bus number...
r = linedata(:,3); % Resistance, R...
x = linedata(:,4); % Reactance, X...
b = linedata(:,5); % Ground Admittance, B/2...
a = linedata(:,6); % Tap setting value..
z = r + i*x; % z matrix...
y = 1./z; % To get inverse of each element...
b = i*b; % Make B imaginary...

nb = max(max(fb),max(tb)); % No. of buses...


nl = length(fb); % No. of branches...
Y = zeros(nb,nb); % Initialise YBus...

% Formation of the Off Diagonal Elements...


for k = 1:nl
Y(fb(k),tb(k)) = Y(fb(k),tb(k)) - y(k)/a(k);
Y(tb(k),fb(k)) = Y(fb(k),tb(k));
end

% Formation of Diagonal Elements....


for m = 1:nb
for n = 1:nl
if fb(n) == m
Y(m,m) = Y(m,m) + y(n)/(a(n)^2) + b(n);
elseif tb(n) == m
Y(m,m) = Y(m,m) + y(n) + b(n);
end
end
end
%Y; % Bus Admittance Matrix
%Z = inv(Y); % Bus Impedance Matrix
% Returns Initial Bus datas of the system...
function busdt = busdatas(num)

% Type....
% 1 - Slack Bus..
% 2 - PV Bus..
% 3 - PQ Bus..
% |Bus | Type | Vsp | theta | PGi | QGi | PLi | QLi | Qmin | Qmax |
busdat14 = [1 1 1.060 0 0 0 0 0 0 0;
2 2 1.045 0 40 42.4 21.7 12.7 -40 50;
3 2 1.010 0 0 23.4 94.2 19.0 0 40;
4 3 1.0 0 0 0 47.8 -3.9 0 0;
5 3 1.0 0 0 0 7.6 1.6 0 0;
6 2 1.070 0 0 12.2 11.2 7.5 -6 24;
7 3 1.0 0 0 0 0.0 0.0 0 0;
8 2 1.090 0 0 17.4 0.0 0.0 -6 24;
9 3 1.0 0 0 0 29.5 16.6 0 0;
10 3 1.0 0 0 0 9.0 5.8 0 0;
11 3 1.0 0 0 0 3.5 1.8 0 0;
12 3 1.0 0 0 0 6.1 1.6 0 0;
13 3 1.0 0 0 0 13.5 5.8 0 0;
14 3 1.0 0 0 0 14.9 5.0 0
% |Bus | Type | Vsp | theta | PGi | QGi | PLi | QLi | Qmin | Qmax |
busdat30 = [1 1 1.06 0 0 0 0 0 0 0;
2 2 1.043 0 40 50.0 21.7 12.7 -40 50;
3 3 1.0 0 0 0 2.4 1.2 0 0;
4 3 1.06 0 0 0 7.6 1.6 0 0;
5 2 1.01 0 0 37.0 94.2 19.0 -40 40;
6 3 1.0 0 0 0 0.0 0.0 0 0;
7 3 1.0 0 0 0 22.8 10.9 0 0;
8 2 1.01 0 0 37.3 30.0 30.0 -10 40;
9 3 1.0 0 0 0 0.0 0.0 0 0;
10 3 1.0 0 0 19.0 5.8 2.0 0 0;
11 2 1.082 0 0 16.2 0.0 0.0 -6 24;
12 3 1.0 0 0 0 11.2 7.5 0 0;
13 2 1.071 0 0 10.6 0.0 0.0 -6 24;
14 3 1.0 0 0 0 6.2 1.6 0 0;
15 3 1.0 0 0 0 8.2 2.5 0 0;
16 3 1.0 0 0 0 3.5 1.8 0 0;
17 3 1.0 0 0 0 9.0 5.8 0 0;
18 3 1.0 0 0 0 3.2 0.9 0 0;
19 3 1.0 0 0 0 9.5 3.4 0 0;
20 3 1.0 0 0 0 2.2 0.7 0 0;
21 3 1.0 0 0 0 17.5 11.2 0 0;
22 3 1.0 0 0 0 0.0 0.0 0 0;
23 3 1.0 0 0 0 3.2 1.6 0 0;
24 3 1.0 0 0 4.3 8.7 6.7 0 0;
25 3 1.0 0 0 0 0.0 0.0 0 0;
26 3 1.0 0 0 0 3.5 2.3 0 0;
27 3 1.0 0 0 0 0.0 0.0 0 0;
28 3 1.0 0 0 0 0.0 0.0 0 0;
29 3 1.0 0 0 0 2.4 0.9 0 0;
30 3 1.0 0 0 0 10.6 1.9 0 0 ];

% |Bus | Type | Vsp | theta | PGi | QGi | PLi | QLi | Qmin | Qmax |
busdat57 = [1 1 1.040 0 0.0 0.0 0.0 0.0 0.0 0.0;
2 2 1.010 0 3.0 88.0 0.0 -0.8 50.0 -17.0;
3 2 0.985 0 41.0 21.0 40.0 -1.0 60.0 -10.0;
4 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
5 3 1.000 0 13.0 4.0 0.0 0.0 0.0 0.0;
6 2 0.980 0 75.0 2.0 0.0 0.8 25.0 -8.0;
7 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
8 2 1.005 0 150.0 22.0 450.0 62.1 200.0 -140.0;
9 2 0.980 0 121.0 26.0 0.0 2.2 9.0 -3.0;
10 3 1.000 0 5.0 2.0 0.0 0.0 0.0 0.0;
11 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
12 2 1.015 0 377.0 24.0 310.0 128.5 155.0 -150.0;
13 3 1.000 0 18.0 2.3 0.0 0.0 0.0 0.0;
14 3 1.000 0 10.5 5.3 0.0 0.0 0.0 0.0;
15 3 1.000 0 22.0 5.0 0.0 0.0 0.0 0.0;
16 3 1.000 0 43.0 3.0 0.0 0.0 0.0 0.0;
17 3 1.000 0 42.0 8.0 0.0 0.0 0.0 0.0;
18 3 1.000 0 27.2 9.8 0.0 0.0 0.0 0.0;
19 3 1.000 0 3.3 0.6 0.0 0.0 0.0 0.0;
20 3 1.000 0 2.3 1.0 0.0 0.0 0.0 0.0;
21 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
22 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
23 3 1.000 0 6.3 2.1 0.0 0.0 0.0 0.0;
24 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
25 3 1.000 0 6.3 3.2 0.0 0.0 0.0 0.0;
26 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
27 3 1.000 0 9.3 0.5 0.0 0.0 0.0 0.0;
28 3 1.000 0 4.6 2.3 0.0 0.0 0.0 0.0;
29 3 1.000 0 17.0 2.6 0.0 0.0 0.0 0.0;
30 3 1.000 0 3.6 1.8 0.0 0.0 0.0 0.0;
31 3 1.000 0 5.8 2.9 0.0 0.0 0.0 0.0;
32 3 1.000 0 1.6 0.8 0.0 0.0 0.0 0.0;
33 3 1.000 0 3.8 1.9 0.0 0.0 0.0 0.0;
34 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
35 3 1.000 0 6.0 3.0 0.0 0.0 0.0 0.0;
36 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
37 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
38 3 1.000 0 14.0 7.0 0.0 0.0 0.0 0.0;
39 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
40 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
41 3 1.000 0 6.3 3.0 0.0 0.0 0.0 0.0;
42 3 1.000 0 7.1 4.4 0.0 0.0 0.0 0.0;
43 3 1.000 0 2.0 1.0 0.0 0.0 0.0 0.0;
44 3 1.000 0 12.0 1.8 0.0 0.0 0.0 0.0;
45 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
46 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
47 3 1.000 0 29.7 11.6 0.0 0.0 0.0 0.0;
48 3 1.000 0 0.0 0.0 0.0 0.0 0.0 0.0;
49 3 1.000 0 18.0 8.5 0.0 0.0 0.0 0.0;
50 3 1.000 0 21.0 10.5 0.0 0.0 0.0 0.0;
51 3 1.000 0 18.0 5.3 0.0 0.0 0.0 0.0;
52 3 1.000 0 4.9 2.2 0.0 0.0 0.0 0.0;
53 3 1.000 0 20.0 10.0 0.0 0.0 0.0 0.0;
54 3 1.000 0 4.1 1.4 0.0 0.0 0.0 0.0;
55 3 1.000 0 6.8 3.4 0.0 0.0 0.0 0.0;
56 3 1.000 0 7.6 2.2 0.0 0.0 0.0 0.0;
57 3 1.000 0 6.7 2.0 0.0 0.0 0.0 0.0];
switch num
case 14
busdt = busdat14;
case 30
busdt = busdat30;
case 57
busdt = busdat57;
end
% Returns Line datas of the system...
function linedt = linedatas(num)

% | From | To | R | X | B/2 | X'mer |


% | Bus | Bus | pu | pu | pu | TAP (a) |
linedat14 = [1 2 0.01938 0.05917 0.0264 1
1 5 0.05403 0.22304 0.0246 1
2 3 0.04699 0.19797 0.0219 1
2 4 0.05811 0.17632 0.0170 1
2 5 0.05695 0.17388 0.0173 1
3 4 0.06701 0.17103 0.0064 1
4 5 0.01335 0.04211 0.0 1
4 7 0.0 0.20912 0.0 0.978
4 9 0.0 0.55618 0.0 0.969
5 6 0.0 0.25202 0.0 0.932
6 11 0.09498 0.19890 0.0 1
6 12 0.12291 0.25581 0.0 1
6 13 0.06615 0.13027 0.0 1
7 8 0.0 0.17615 0.0 1
7 9 0.0 0.11001 0.0 1
9 10 0.03181 0.08450 0.0 1
9 14 0.12711 0.27038 0.0 1
10 11 0.08205 0.19207 0.0 1
12 13 0.22092 0.19988 0.0 1
13 14 0.17093 0.34802 0.0 1 ];

% | From | To | R | X | B/2 | X'mer |


% | Bus | Bus | pu | pu | pu | TAP (a) |
linedat30 = [1 2 0.0192 0.0575 0.0264 1
1 3 0.0452 0.1652 0.0204 1
2 4 0.0570 0.1737 0.0184 1
3 4 0.0132 0.0379 0.0042 1
2 5 0.0472 0.1983 0.0209 1
2 6 0.0581 0.1763 0.0187 1
4 6 0.0119 0.0414 0.0045 1
5 7 0.0460 0.1160 0.0102 1
6 7 0.0267 0.0820 0.0085 1
6 8 0.0120 0.0420 0.0045 1
6 9 0.0 0.2080 0.0 0.978
6 10 0.0 0.5560 0.0 0.969
9 11 0.0 0.2080 0.0 1
9 10 0.0 0.1100 0.0 1
4 12 0.0 0.2560 0.0 0.932
12 13 0.0 0.1400 0.0 1
12 14 0.1231 0.2559 0.0 1
12 15 0.0662 0.1304 0.0 1
12 16 0.0945 0.1987 0.0 1
14 15 0.2210 0.1997 0.0 1
16 17 0.0824 0.1923 0.0 1
15 18 0.1073 0.2185 0.0 1
18 19 0.0639 0.1292 0.0 1
19 20 0.0340 0.0680 0.0 1
10 20 0.0936 0.2090 0.0 1
10 17 0.0324 0.0845 0.0 1
10 21 0.0348 0.0749 0.0 1
10 22 0.0727 0.1499 0.0 1
21 23 0.0116 0.0236 0.0 1
15 23 0.1000 0.2020 0.0 1
22 24 0.1150 0.1790 0.0 1
23 24 0.1320 0.2700 0.0 1
24 25 0.1885 0.3292 0.0 1
25 26 0.2544 0.3800 0.0 1
25 27 0.1093 0.2087 0.0 1
28 27 0.0 0.3960 0.0 0.968
27 29 0.2198 0.4153 0.0 1
27 30 0.3202 0.6027 0.0 1
29 30 0.2399 0.4533 0.0 1
8 28 0.0636 0.2000 0.0214 1
6 28 0.0169 0.0599 0.065 1 ];

% | From | To | R | X | B/2 | X'mer |


% | Bus | Bus | pu | pu | pu | TAP (a) |
linedat57 = [ 1 2 0.0083 0.0280 0.0645 1
2 3 0.0298 0.0850 0.0409 1
3 4 0.0112 0.0366 0.0190 1
4 5 0.0625 0.1320 0.0129 1
4 6 0.0430 0.1480 0.0174 1
6 7 0.0200 0.1020 0.0138 1
6 8 0.0339 0.1730 0.0235 1
8 9 0.0099 0.0505 0.0274 1
9 10 0.0369 0.1679 0.0220 1
9 11 0.0258 0.0848 0.0109 1
9 12 0.0648 0.2950 0.0386 1
9 13 0.0481 0.1580 0.0203 1
13 14 0.0132 0.0434 0.0055 1
13 15 0.0269 0.0869 0.0115 1
1 15 0.0178 0.0910 0.0494 1
1 16 0.0454 0.2060 0.0273 1
1 17 0.0238 0.1080 0.0143 1
3 15 0.0162 0.0530 0.0272 1
4 18 0.0 0.5550 0.0 0.970
4 18 0.0 0.4300 0.0 0.978
5 6 0.0302 0.0641 0.0062 1
7 8 0.0139 0.0712 0.0097 1
10 12 0.0277 0.1262 0.0164 1
11 13 0.0223 0.0732 0.0094 1
12 13 0.0178 0.0580 0.0302 1
12 16 0.0180 0.0813 0.0108 1
12 17 0.0397 0.1790 0.0238 1
14 15 0.0171 0.0547 0.0074 1
18 19 0.4610 0.6850 0.0 1
19 20 0.2830 0.4340 0.0 1
21 20 0.0 0.7767 0.0 1.043
21 22 0.0736 0.1170 0.0 1
22 23 0.0099 0.0152 0.0 1
23 24 0.1660 0.2560 0.0042 1
24 25 0.0 1.1820 0.0 1
24 25 0.0 1.2300 0.0 1
24 26 0.0 0.0473 0.0 1.043
26 27 0.1650 0.2540 0.0 1
27 28 0.0618 0.0954 0.0 1
28 29 0.0418 0.0587 0.0 1
7 29 0.0 0.0648 0.0 0.967
25 30 0.1350 0.2020 0.0 1
30 31 0.3260 0.4970 0.0 1
31 32 0.5070 0.7550 0.0 1
32 33 0.0392 0.0360 0.0 1
34 32 0.0 0.9530 0.0 0.975
34 35 0.0520 0.0780 0.0016 1
35 36 0.0430 0.0537 0.0008 1
36 37 0.0290 0.0366 0.0 1
37 38 0.0651 0.1009 0.0010 1
37 39 0.0239 0.0379 0.0 1
36 40 0.0300 0.0466 0.0 1
22 38 0.0192 0.0295 0.0 1
11 41 0.0 0.7490 0.0 0.955
41 42 0.2070 0.3520 0.0 1
41 43 0.0 0.4120 0.0 1
38 44 0.0289 0.0585 0.0010 1
15 45 0.0 0.1042 0.0 0.955
14 46 0.0 0.0735 0.0 0.900
46 47 0.0230 0.0680 0.0016 1
47 48 0.0182 0.0233 0.0 1
48 49 0.0834 0.1290 0.0024 1
49 50 0.0801 0.1280 0.0 1
50 51 0.1386 0.2200 0.0 1
10 51 0.0 0.0712 0.0 0.930
13 49 0.0 0.1910 0.0 0.895
29 52 0.1442 0.1870 0.0 1
52 53 0.0762 0.0984 0.0 1
53 54 0.1878 0.2320 0.0 1
54 55 0.1732 0.2265 0.0 1
11 43 0.0 0.1530 0.0 0.958
44 45 0.0624 0.1242 0.0020 1
40 56 0.0 1.1950 0.0 0.958
56 41 0.5530 0.5490 0.0 1
56 42 0.2125 0.3540 0.0 1
39 57 0.0 1.3550 0.0 0.980
57 56 0.1740 0.2600 0.0 1
38 49 0.1150 0.1770 0.0015 1
38 48 0.0312 0.0482 0.0 1
9 55 0.0 0.1205 0.0 0.940];

switch num
case 14
linedt = linedat14;
case 30
linedt = linedat30;
case 57
linedt = linedat57;
end

% Polar to Rectangular Conversion


% [RECT] = RECT2POL(RHO, THETA)
% RECT - Complex matrix or number, RECT = A + jB, A = Real, B = Imaginary
% RHO - Magnitude
% THETA - Angle in radians

function rect = pol2rect(rho,theta)


rect = rho.*cos(theta) + j*rho.*sin(theta);

\
% Program for Bus Power Injections, Line & Power flows (p.u)...
function [Pi Qi Pg Qg Pl Ql] = loadflow(nb,V,del,BMva)

Y = ybusppg(nb); % Calling Ybus program..


lined = linedatas(nb); % Get linedats..
busd = busdatas(nb); % Get busdatas..
Vm = pol2rect(V,del); % Converting polar to rectangular..
Del = 180/pi*del; % Bus Voltage Angles in Degree...
fb = lined(:,1); % From bus number...
tb = lined(:,2); % To bus number...
nl = length(fb); % No. of Branches..
Pl = busd(:,7); % PLi..
Ql = busd(:,8); % QLi..

Iij = zeros(nb,nb);
Sij = zeros(nb,nb);
Si = zeros(nb,1);

% Bus Current Injections..


I = Y*Vm;
Im = abs(I);
Ia = angle(I);

%Line Current Flows..


for m = 1:nl
p = fb(m); q = tb(m);
Iij(p,q) = -(Vm(p) - Vm(q))*Y(p,q); % Y(m,n) = -y(m,n)..
Iij(q,p) = -Iij(p,q);
end
Iij = sparse(Iij);
Iijm = abs(Iij);
Iija = angle(Iij);

% Line Power Flows..


for m = 1:nb
for n = 1:nb
if m ~= n
Sij(m,n) = Vm(m)*conj(Iij(m,n))*BMva;
end
end
end
Sij = sparse(Sij);
Pij = real(Sij);
Qij = imag(Sij);

% Line Losses..
Lij = zeros(nl,1);
for m = 1:nl
p = fb(m); q = tb(m);
Lij(m) = Sij(p,q) + Sij(q,p);
end
Lpij = real(Lij);
Lqij = imag(Lij);

% Bus Power Injections..


for i = 1:nb
for k = 1:nb
Si(i) = Si(i) + conj(Vm(i))* Vm(k)*Y(i,k)*BMva;
end
end
Pi = real(Si);
Qi = -imag(Si);
Pg = Pi+Pl;
Qg = Qi+Ql;

disp('############################################--########################');
disp('----------------------------------------------------------------------');
disp(' Newton Raphson Loadflow Analysis ');
disp('----------------------------------------------------------------------');
disp('| Bus | V | Angle | Injection | Generation |
Load |');
disp('| No | pu | Degree | MW | MVar | MW | Mvar | MW
| MVar | ');
for m = 1:nb
disp('------------------------------------------------------------------');
fprintf('%3g', m); fprintf(' %8.4f', V(m)); fprintf(' %8.4f', Del(m));
fprintf(' %8.3f', Pi(m)); fprintf(' %8.3f', Qi(m));
fprintf(' %8.3f', Pg(m)); fprintf(' %8.3f', Qg(m));
fprintf(' %8.3f', Pl(m)); fprintf(' %8.3f', Ql(m)); fprintf('\n');
end
disp('-----------------------------------------------------------------------');
fprintf(' Total ');fprintf(' %8.3f', sum(Pi));fprintf(' %8.3f',
sum(Qi));
fprintf(' %8.3f', sum(Pi+Pl)); fprintf(' %8.3f', sum(Qi+Ql));
fprintf(' %8.3f', sum(Pl)); fprintf(' %8.3f', sum(Ql)); fprintf('\n');
disp('-----------------------------------------------------------------------');
disp('#######################################################################');

disp('-----------------------------------------------------------------------');
disp(' Line FLow and Losses ');
disp('-----------------------------------------------------------------------');
disp('|From|To | P | Q | From| To | P | Q | Line
Loss |');
disp('|Bus |Bus| MW | MVar | Bus | Bus| MW | MVar | MW |
MVar |');
for m = 1:nl
p = fb(m); q = tb(m);
disp('--------------------------------------------------------------------');
fprintf('%4g',full(p)); fprintf('%4g',full(q)); fprintf(' %8.3f',
full(Pij(p,q))); fprintf(' %8.3f',full(Qij(p,q)));
fprintf(' %4g',full(q)); fprintf('%4g',full(p)); fprintf('
%8.3f',full(Pij(q,p))); fprintf(' %8.3f',full(Qij(q,p)));
fprintf(' %8.3f',full(Lpij(m))); fprintf(' %8.3f',full(Lqij(m)));
fprintf('\n');
end
disp('---------------------------------------------------------------------');
fprintf(' Total Loss ');
fprintf(' %8.3f', sum(Lpij)); fprintf(' %8.3f', sum(Lqij)); fprintf('\n');
disp('---------------------------------------------------------------------');
disp('######################################################################');

You might also like