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

Power Flow Program Using Matlab

This document provides a MATLAB code for performing power flow analysis using the Newton-Raphson method on a three bus system. It includes functions to define primitive data like line impedances, bus schedules, form the admittance matrix, calculate power injections and flows. The code performs an iterative Newton-Raphson load flow calculation, checking for convergence at each iteration. It displays the results of each iteration including bus voltages, power injections, line flows and losses.

Uploaded by

Safnas Kariapper
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views

Power Flow Program Using Matlab

This document provides a MATLAB code for performing power flow analysis using the Newton-Raphson method on a three bus system. It includes functions to define primitive data like line impedances, bus schedules, form the admittance matrix, calculate power injections and flows. The code performs an iterative Newton-Raphson load flow calculation, checking for convergence at each iteration. It displays the results of each iteration including bus voltages, power injections, line flows and losses.

Uploaded by

Safnas Kariapper
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lab sheet: Power flow analysis

Semester-07

POWER FLOW PROGRAM USING MATLAB


Through NR method algorithm
Example: For three bus system:

Line impedances converted to admittances:

Let 100 MVA is the base value.

− ( 400+ j250 )
Ssch
2 = =−4.0− j2.5 pu … … … … … … … … …(1)
100
200
Psch
3 = =2.0 pu … … … … … … … … …(2)
100

The slack bus voltage V1=1.05∠ 0 pu, and the bus3 voltage magnitude is |V 3|=1.04 pu .
Starting with initial estimate|V (0)
2 |=1.0 pu δ 2 ¿ 0.0
, (0) and δ (0)
3 =0.0,

A) Matlab function for primitive data


function linedt = Primitive_Data()

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


% | Bus | Bus | pu | pu | pu | TAP (a) |
linedat3 = [1 2 0.02 0.04 0 1
1 3 0.01 0.03 0 1
2 3 0.0125 0.025 0 1];
linedt = linedat3;

B) Matlab function for bus schedule data:


function busdt = Scheduled_Bus_Data()

% Type....
% 1 - Slack Bus..
% 2 - PV Bus..
% 3 - PQ Bus..
% |Bus| Type| Vsp| delta| PGi | QGi | PLi | QLi | Qmin | Qmax|
busdat3 = [1 1 1.05 0 0 0 0 0 0 0;
2 3 1.0 0 0 0 400 250 0 0;
3 2 1.04 0 200 0 0 0 -1000 +1000;];
busdt = busdat3;
C) Program to for Admittance And Impedance Bus Formation....
function YB = Admittance_Formation() % Returns Y

linedata = Primitive_Data(); % 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 + j*x; % z matrix...
y = 1./z; % To get inverse of each element...
b = j*b; % Make B imaginary...

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


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

% Formation of the Off Diagonal Elements...


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

% Formation of Diagonal Elements....


for m = 1:nb
for n = 1:nl
if fb(n) == m
YB(m,m) = YB(m,m) + y(n)/(a(n)^2) + b(n);
elseif tb(n) == m
YB(m,m) = YB(m,m) + y(n) + b(n);
end
end
end
%YB; % Bus Admittance Matrix
%ZB = inv(YB); % Bus Impedance Matrix

D) Polar to Rectangular Conversion


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

function rect = pol2rect(rho,delta)


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

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

Y = Admittance_Formation(); % Calling Ybus program..


lined = Primitive_Data(); % Get linedats..
busd = Scheduled_Bus_Data(); % 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); % Commented out..
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); % Commented out..
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;
Continued…….

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', p); fprintf('%4g', q); fprintf(' %8.3f', Pij(p,q)); fprintf(' %8.3f',
Qij(p,q));
fprintf(' %4g', q); fprintf('%4g', p); fprintf(' %8.3f', Pij(q,p)); fprintf(' %8.3f',
Qij(q,p));
fprintf(' %8.3f', Lpij(m)); fprintf(' %8.3f', Lqij(m));
fprintf('\n');
end
disp('-------------------------------------------------------------------------------------');
fprintf(' Total Loss ');
fprintf(' %8.3f', sum(Lpij)); fprintf(' %8.3f', sum(Lqij)); fprintf('\n');
disp('-------------------------------------------------------------------------------------');
disp('#####################################################################################');

F) Matlab Program for Newton-Raphson Load Flow Analysis..


Y = Admittance_Formation(); % Calling ybusppg.m to get Y-Bus
Matrix..
busd = Scheduled_Bus_Data(); % Calling busdatas..
nbus=3; % Number of buses
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

Continued…
% 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 a = 1:nbus
J1(i,k) = J1(i,k) + V(m)* V(a)*(-G(m,a)*sin(del(m)-
del(a)) + B(m,a)*cos(del(m)-del(a)));
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

Continued…
% 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;
Output:

>> Main_Program

Y =

20.0000 -50.0000i -10.0000 +20.0000i -10.0000 +30.0000i


-10.0000 +20.0000i 26.0000 -52.0000i -16.0000 +32.0000i
Lab assessment: Perform power flow analysis for following powers system.

Hint: You may use the above code.

The following power network which is being made available to the electrical utility industry
as a standard test case for evaluating various analytical methods and computer program.
Here Bus-1 is taken as the slack bus with its voltage adjusted to 1.06∠ 0 ° pu.
The data for the voltage controlled buses is:

The transformer tap setting:

Data for injected Q due to shunt capacitor is:

You might also like