Department of Electrical Engineering Delhi Technological University, Delhi-110042
Department of Electrical Engineering Delhi Technological University, Delhi-110042
Aim: To compute the bus admittance matrix Ybus for the small power
system network given below using MATLAB mfile/Python/C++
The branch data / line data for the above network is given below:
From To R X B
bus no. bus no. (p.u) (p.u) (p.u)
1 2 0.02 0.1 0.03
1 3 0.02 0.1 0.03
1 4 0.02 0.1 0.03
2 4 0.02 0.1 0.03
3 4 0.02 0.1 0.03
clc
clear all
nb=4; % nb is number of buses in the network
z=inf(nb,nb);
D=[1 2 0.02 0.1 0.03;1 3 0.02 0.1 0.03;1 4 0.02 0.1 0.03;2 4 0.02 0.1 0.03;3
4 0.02 0.1 0.03]; % Five columns are for ‘From bus’, ‘To bus’, ‘R’, ‘X’
and ‘B’
r=size(D);
rows=r(1);
for i=1:rows
z(D(i,1),D(i,2))=D(i,3)+j*D(i,4);
z(D(i,2),D(i,1))=z(D(i,1),D(i,2));
b(D(i,1),D(i,2))=D(i,5);
b(D(i,2),D(i,1))=b(D(i,1),D(i,2));
end
for i=1:nb
y0(i)=j*sum(b(i,:))/2;
end
for i=1:nb
for m=1:nb
if i~=m
Y(i,m)=-1/z(i,m);
else
Y(i,m)=y0(i)+sum(1./z(i,:));
end
end
end
EXPERIMENT 2
In the above network, all the transmission lines are identical. For each
line, the shunt element is a capacitor with an admittance of ysh=j 0.01
while each series element is an inductor with an impedance of zse=j 0.1.
1. Theory:
2. Procedure: First compute the bus admittance matrix. Check that
Type the code given below for the Gauss-Siedel algorithm in a MATLAB
mfile. Save the code as amit2 if Amit is your first name (no blank spaces in
between). Debug the code and run it to get the final results as:
[ ] [ ]
For the above network, all the transmission lines are identical. In the
equivalent-pi representation of each line, the series impedance equals zse =
j 0.1 while each of the shunt admittances (equal on both sides) equal ysh = j
0.01. This gives the bus admittance matrix Ybus as
Theory: In the above 3-bus system, there are three buses – the first bus is
the slack bus, the second bus is a PV bus and the third bus is a PQ bus.
Hence the unknown variables to be computed are and . Hence, the
Newton-Raphson algorithm for power-flow of the above three bus system
is given by
where
Procedure: Type the code given below for the Newton-Raphson algorithm
in a MATLAB mfile. Save the code as amit3 if Amit is your first name (no
blank spaces in between). Debug the code and run it to get the final results
as:
[ ] [ ]
Code in MATLAB mfile:
clc
clear all
%Data%
slb=1;pvb=1;pqb=1;nb=slb+pvb+pqb;
Y=[-j*19.98 j*10 j*10;j*10 -j*19.98 j*10;j*10 j*10 -j*19.98];
y=abs(Y);phi=angle(Y);
v(1)=1.0;th(1)=0;v(2)=1.05;
Psp(2)=0.6661;Psp(3)=-2.8653;Qsp(3)=-1.2244;
%initial guess for unknown theta and v %
th(2)=0;v(3)=1.0;th(3)=0;
cc=180/pi;
THV=[0;0;1];
%Program for Newton-Raphson algorithm%
err=1.0; t=0; % ‘t’ is number of iterations of the algorithm
while err>1e-4
for i=(slb+1):nb
Px(i)=0;Qx(i)=0;
for k=1:3
Px(i)=Px(i)+v(i)*v(k)*y(i,k)*cos(th(i)-th(k)-phi(i,k));
Qx(i)=Qx(i)+v(i)*v(k)*y(i,k)*sin(th(i)-th(k)-phi(i,k));
end
end
% formation of Jacobian 'J' %
% P-theta jacobian %
JPth(1,1)=-Qx(2)-(((v(2))^2)*abs(Y(2,2))*sin(angle(Y(2,2))));
JPth(1,2)=v(2)*v(3)*abs(Y(2,3))*sin(th(2)-th(3)-(angle(Y(2,3))));
JPth(2,1)=v(3)*v(2)*abs(Y(3,2))*sin(th(3)-th(2)-(angle(Y(3,2))));
JPth(2,2)=-Qx(3)-(((v(3))^2)*abs(Y(3,3))*sin(angle(Y(3,3))));
% P-v jacobian %
JPv(1,1)=v(2)*abs(Y(2,3))*cos(th(2)-th(3)-(angle(Y(2,3))));
JPv(2,1)=(Px(3)/v(3))+(v(3)*abs(Y(3,3))*cos(angle(Y(3,3))));
% Q-theta jacobian %
JQth(1,1)=-v(3)*v(2)*abs(Y(3,2))*cos(th(3)-th(2)-(angle(Y(3,2))));
JQth(1,2)=Px(3)-(((v(3))^2)*abs(Y(3,3))*cos(angle(Y(3,3))));
% Q-v jacobian %
JQv(1,1)=(Qx(3)/v(3))-(v(3)*abs(Y(3,3))*sin(angle(Y(3,3))));
J=[JQth JQv;JPth JPv];
for p=1:pqb
delq(p)=Qsp(p+slb+pvb)-Qx(p+slb+pvb);
end
for p=1:(pvb+pqb)
delp(p)=Psp(p+slb)-Px(p+slb);
end
delPQ=[delq';delp'];
delthv=THV+(inv(J)*delPQ);
for p=(slb+1):nb
th(p)=delthv(p-1);
end
for p=(slb+pvb+1):nb
v(p)=delthv(p+pqb-slb);
end
THV=delthv;
err=max(abs(delPQ))
t=t+1;
end
[v' cc*th']
EXPERIMENT 4
For the above network, all the transmission lines are identical. In the
equivalent-pi representation of each line, the series impedance equals zse =
j 0.1 while each of the shunt admittances (equal on both sides) equal ysh = j
0.01. This gives the bus admittance matrix Ybus as
where
In the above 3-bus system, there are three buses – the first bus is the slack
bus, the second bus is a PV bus and the third bus is a PQ bus. Hence the
unknown variables to be computed are and . Hence, the fast-
decoupled power-flow algorithm for the above three bus system is given by
And
Procedure: Type the code given below for the fast-decoupled power-
flow algorithm in a MATLAB mfile. Save the code as amit4 if Amit is
your first name (no blank spaces in between). Debug the code and run it
to get the final results as
[ ] and
The fuel cost functions of the above three generators are given as
$/hr
$/hr
$/hr
The total active power demand is 850 MW.
The transmission losses are given as
MW.
Theory: (a) Without transmission loss, the optimal dispatch rule is given
as
where
From the three generators‟ fuel cost functions, the above equations can
be written in matrix form as
[ ][ ] [ ]
Thus, after putting values of the parameters given for the system, the
first equation becomes i.e. , which can be
written as
or, .
The above equation pertains to generating unit 1. Similarly, the
equations for generating units 2 and 3 can be written. After putting all
three equations in the matrix form, we get,
[ ][ ]
[ ]
Aim: To compute the bus impedance matrix from scratch for the power
system network given below.
Theory:
The Ybus /Zbus matrix constitutes the models of the passive portions of
the power network. The impedance matrix is a full matrix and is most
useful for short circuit studies. An algorithm for formulating [Z bus] is
described in terms of modifying an existing bus impedance matrix
designated as [Zbus]old. The modified matrix is designated as [Zbus]new.
The network consists of a reference bus and a number of other buses.
When a new element having self impedance Zb is added, a new bus may
be created (if the new element is a tree branch) or a new bus may not be
created (if the new element is a link). Each of these two cases can be
subdivided into two cases so that Zb may be added in the following ways
or modifications:
1. Adding Zb from a new bus to reference bus.
2. Adding Zb from a new bus to an existing bus.
3. Adding Zb from an existing bus to reference bus.
4. Adding Zb between two existing buses.
Type 1 modification:
given by, Vp = Ip Zb
The potential at other buses remains unaltered and the system equations
can be written as,
Type 2 modification:
In type 2 modification, an impedance Zb is added between a new bus p
and an existing bus k as shown in Figure 2. The voltages across the bus k
and p can be expressed as,
Vk(new) = Vk + Ip Zkk
Vp = Vk(new) + Ip Zp
= Vk + Ip(Zb + Zkk)
where, Vk is the voltage across bus k before the addition of impedance
Zb
Zkk is the sum of all impedance connected to bus k.
Type 4 Modification:
On solving the Equations (3) and (4), the system of equations can be
rewritten as,
Procedure: Type the code given below for the Z bus formation in a
MATLAB mfile. Save the code as amit6 if Amit is your first name (no
blank spaces in between).
Sample problem:
Form bus impedance matrix using building algorithm:
Solution:
Step1: Add an element between ref (0) bus and a new bus (1)
Z = [j0.2]
Step2: Add an element between existing bus (1) to a new bus (2).
Step3: Add an element between existing (2) Bus to a ref (0) Bus.
Result:
The bus impedance matrix using building algorithm for the given
system was formed and the results were verified using MATLAB
program.
Matlab Code (With Kron’s Reduction)
clear all
Zbus = [0];
Quit = 0;
i = 0;
while Quit==0
else if i>0
Zb = input('Enter the value of impedance = ');
ord = length(Zb1);
for d = 1:ord+1
for e = i:ord+1
if d<=ord && e<=ord
Zbus1(d,e) = Zb1(d,e);
end
if d==ord+1 && e==ord+1
Zbus1(d,e)=Zb;
end
if d==ord+1 && d~=e || e==ord+1 && d~=e
Zbus1(d,e)= 0;
end
end
end
end
Zbus = [Zbus1]
end
end
if Case == 2
Z_new = input('Enter the value of impedance for new bus = ');
m = length(Zbus);
for a=1:m
for b=1:m
Z_temp(a,b) = Zbus(a,b);
end
end
for c = 1:m
Z_temp(c,m+1) = Zbus(c,m);
Z_temp(m+1,c) = Zbus(c,m);
Z_temp(m+1,m+1) = Zbus(m,m)+Z_new;
end
Zbus = [Z_temp]
i = i+1;
end
if Case == 3
Z_new = input('Enter the value of impedance for new bus = ');
m = length(Zbus);
for a=1:m
for b=1:m
Z_temp(a,b) = Zbus(a,b);
end
end
for c = 1:m
Z_temp(c,m+1) = Zbus(c,m);
Z_temp(m+1,c) = Zbus(c,m);
Z_temp(m+1,m+1) = Zbus(m,m)+Z_new;
end
fprintf('Zbus before Kron Reduction:\n')
Zbus = [Z_temp]
m = length(Zbus);
for i=1:m-1
for k = 1:m-1
Z(i,k) = Zbus(i,k) - Zbus(i,m)*Zbus(m,k))/Zbus(m,m));
end
end
fprintf('Zbus after Kron Reduction:\n')
Zbus = [Z]
end
if Case == 4
Z1 = input('Enter the value of impedance = ');
j = input('Enter the value of bus j = ');
k = input('Enter the value of bus k = ');
m = length(Zbus);
for a=1:m
for b=1:m
Z_temp(a,b) = Zbus(a,b);
end
end
for c = 1:m
Z_temp(c,m+1) = Zbus(c,j)-Zbus(c,k);
Z_temp(m+1,c) = Z_temp(c,m+1);
end
Z_temp(m+1,m+1) = Z1+Zbus(j,j)+Zbus(k,k)-2*Zbus(j,k);
fprintf('Zbus before Kron Reduction:\n')
Zbus = [Z_temp]
m = length(Zbus);
for i=1:m-1
for k = 1:m-1
Z(i,k) = Zbus(i,k) - Zbus(i,m)*Zbus(m,k))/Zbus(m,m));
end
end
fprintf('Zbus after Kron Reduction:\n')
Zbus = [Z]
end
Quit = input('Do u want to quit = ');
Zb1 = [Zbus];
end
EXPERIMENT 7
THEORY:
The short circuit problem essentially consists of determining the
steady state solution of a linear network with a balanced three-phase
sinusoidal excitation. The linear network comprises of a major sub
network fault. The transmission network and the generator network
consist of an interconnection of a three-phase balanced component. If
the lines are assumed to be completely transposed the impedance
matrix for a three-phase transmission line is of form
Zs Zm Zm
Z Zs Z m
m
Z m Zm Z s
Procedure: Type the code given below for the Symmetrical Fault
analysis in a MATLAB mfile. Save the code as amit7 if Amit is your
first name (no blank spaces in between).
MATLAB mfile code
function done=threephfault(nb,ng,nl,nt)
%formation of positive sequence Ybus
Yp=Ypositive(nb,ng,nl,nt);
%formation of Zbus
Zbus=inv(Yp);
%initialisation of all voltage to 1 pu at an angle zero asuming no loading
v0_matrix=ones(nb);
v0=v0_matrix(:,1); %creates a coulumn vector of voltages with 1 pu voltage
%calculation of fault current
fid=fopen('faultdata.txt','r');
b=textread('faultdata.txt');
fclose(fid);
bus=b(1);
imp=b(3);
fault_current=v0(bus)/((Zbus(bus,bus)+imp)*j);
%post fault voltage calculations
for i=1:length(v0)
vf(i)=v0(i)-Zbus(i,bus)*fault_current*j;
end
vf_mag=abs(vf);
vf_phase=angle(vf);
poslineflow(i)=(vf_mag(x(i))*(cos(vf_phase(x(i)))+sin(vf_phase(x(i)))*j)-
vf_mag(y(i))*(cos(vf_phase(y(i)))+sin(vf_phase(y(i)))*j))/(zp(i)*j);
neglineflow(i)=(vf_mag(y(i))*(cos(vf_phase(y(i)))+sin(vf_phase(y(i)))*j)-
vf_mag(x(i))*(cos(vf_phase(x(i)))+sin(vf_phase(x(i)))*j))/(zp(i)*j);
end
poslineflow_mag=abs(poslineflow);
poslineflow_phase=angle(poslineflow);
neglineflow_mag=abs(neglineflow);
neglineflow_phase=angle(neglineflow);
fid=fopen('transformerdata.txt','r');
bb=textread('transformerdata.txt');
fclose(fid);
x=bb(:,1);
y=bb(:,3);
z=bb(:,5);
hv=bb(:,2);
lv=bb(:,4);
hvbuses=x;
ele_num=1:length([ele_num y']);
start_bus=[start_bus' x'];
end_bus=[end_bus' y'];
for i=1:length(x)
if (hv(i)==1 & lv(i)==2) | (hv(i)==2 & lv(i)==1) | (hv(i)==0 &
lv(i)==2) | (hv(i)==2 & lv(i)==0)
status(i+nl)=0;
else
status(i+nl)=3;
end
end
s=length(status);
for i=1:nt
postransflow(i)=(vf_mag(x(i))*(cos(vf_phase(x(i)))+sin(vf_phase(x(i)))*j)-
vf_mag(y(i))*(cos(vf_phase(y(i)))+sin(vf_phase(y(i)))*j))/(z(i)*j);
negtransflow(i)=(vf_mag(y(i))*(cos(vf_phase(y(i)))+sin(vf_phase(y(i)))*j)-
vf_mag(x(i))*(cos(vf_phase(x(i)))+sin(vf_phase(x(i)))*j))/(z(i)*j);
end
postransflow_mag=abs(postransflow);
postransflow_phase=angle(postransflow);
negtransflow_mag=abs(negtransflow);
negtransflow_phase=angle(negtransflow);
fid=fopen('gendata.txt','r');
bb=textread('gendata.txt');
fclose(fid);
x=bb(:,1);
z=bb(:,2);
ele_num=1:length([ele_num y']);
%length(ele_num)
start_bus=[start_bus x'];
for i=1:length(x)
temp(i)=nb+1; %nb+1 is taken as the code for the reference bus i.e
ground
end
end_bus=[end_bus temp];
for i=1:ng
status(s+i)=2;
end
for i=1:ng
posgenflow(i)=(vf_mag(x(i))*(cos(vf_phase(x(i)))+sin(vf_phase(x(i)))*j)-
1)/(z(i)*j);
neggenflow(i)=-
(vf_mag(x(i))*(cos(vf_phase(x(i)))+sin(vf_phase(x(i)))*j)-1)/(z(i)*j);
end
%posgenflow
%neggenflow
posgenflow_mag=abs(posgenflow);
posgenflow_phase=angle(posgenflow);
neggenflow_mag=abs(neggenflow);
neggenflow_phase=angle(neggenflow);
if M(ib)==1000
if M(jb)==1000
k=k+1;
end
if M(jb)~=1000
if status(k)~=0
M(ib)=M(jb);
k=k+1;
end
temp=find(hvbuses==ib);
if k<=(length(ele_num))& k==flag
if status(k)==0
if (length(temp)==0)
M(ib)=M(jb)-1;
k=k+1;
else
M(ib)=M(jb)+1;
k=k+1;
end
end
end
end
kk=find(M==1000);
if length(kk)==0
%M
break;
end
if length(kk)~=0
if k<=length(ele_num)
%k=k+1;
%M
continue;
end
if k>length(ele_num)
k=1;
%M
continue;
end
end
end
if M(ib)~=1000
if M(jb)~=1000
k=k+1;
end
if M(jb)==1000
if status(k)~=0
M(jb)=M(ib);
k=k+1;
end
temp=find(hvbuses==jb);
if k<=(length(ele_num)) & k==flag
if status(k)==0
if (length(temp)==0)
M(jb)=M(ib)-1;
k=k+1;
else
M(jb)=M(ib)+1;
k=k+1;
end
end
end
end
kk=find(M==1000);
if length(kk)==0
%M
break;
end
if length(kk)~=0
if k<=length(ele_num)
%k=k+1;
%M
continue;
end
if k>length(ele_num)
k=1;
%M
continue;
end
end
end
end
fid=fopen('faultdata.txt','r');
b=textread('faultdata.txt');
fclose(fid);
FB=b(1);
flag=M(FB);
for i=1:(nb+1)
M(i)=M(i)-flag;
end
M
%correction of voltage and flows
value=input('Enter the phase shift that you desire in degrees. The choice
that you have are 30 and 90 degrees.');
for i=1:nb
vf_phase(i)=vf_phase(i)+M(i)*(value*pi/180);
end
for i=1:length(posflow_phase)
posflow_phase(i)=posflow_phase(i)+M(start_bus(i))*(value*pi/180);
negflow_phase(i)=negflow_phase(i)+M(end_bus(i))*(value*pi/180);
end
%negflow_mag
%negflow_phase
done=1;
EXPERIMENT 8
Aim: To determine the critical clearing time for the single machine
infinite bus system given below.
Theory: The dynamic equation relating the rotor angle and the
accelerating power is given by the nonlinear differential equation
(swing equation) given as
For numerical solution of the swing equation, the above second order
differential equation is resolved into two first order differential
equations given as
during the two time periods (i) t0 to t0+tc and (ii) t0+tc to tf where
„t0' is the time instant at which the fault occurs, „tc‟ is the time at
which the fault is cleared (clearing time) and „tf‟ is the final time
instant up to which we are interested in finding the solution.
However, during the time interval (i) t0 to t0+tc, Pmax = 0 while
during (ii) t0+tc to tf, Pmax = 1.1024 p.u, as observed from diagrams
(b) and (c), respectively.
Procedure: Type the code given below for the fast-decoupled power-
flow algorithm in a MATLAB mfile. Save the code as amit8 if Amit
is your first name (no blank spaces in between). Debug the code and
run it (by varying „tc‟) to get the critical clearing time tcrit =0.087 secs.
MATLAB CODE:
clc
clear all
p=0.9;q=0.436;et=1;pm=p;
xddash=0.3;xt=0.15;xl1=0.5;xl2=0.93;xleq=(xl1*xl2)/(xl1+xl2);
alpha=160*pi/180;
i1=(p-j*q)/conj(et);
eb=et-j*(xt+xleq)*i1;
edash=et+j*xddash*i1;
% pre fault analysis
del0=angle(edash)-angle(eb) % intial or prefault value of delta
xlbf=xleq+xt+xddash;xldf=xt+xddash;xlaf=xl1+xt+xddash;
tc=0.088;t0=1;tfinal=5;delt=0.001;
n0=t0/delt;arr1=linspace(t0,t0+tc,100);n1=length(arr1);delt1=tc/100;
arr2=linspace(t0+tc,tfinal,10000);n2=length(arr2);delt2=(tfinal-t0-
tc)/10000;
%initial conditions for differential equations
del1(1)=del0;delw1(1)=0;H=3.5;
for i=1:n1-1
del1(i+1)=del1(i)+377*delw1(i)*delt1;
delw1(i+1)=delw1(i)+(pm/(2*H))*delt1;
% during fault from t0 to t0+tc, pe=0
end
del2(1)=del1(end);delw2(1)=delw1(end);
for i=1:n2-1
del2(i+1)=del2(i)+377*delw2(i)*delt2;
peaf=abs(edash)*abs(eb)*sin(del2(i+1))/xlaf;
delw2(i+1)=delw2(i)+((pm-peaf)/(2*H))*delt2;
% during fault from t0+tc to t0+tc+5, pe≠0
end
delin=del0*ones(1,n0);
del=[delin del1 del2]*180/pi;
t1=(0:n0-1)*delt;t2=t1(end)+(0:n1-1)*delt1;t3=t2(end)+(0:n2-1)*delt2;
t=[t1 t2 t3];
plot(t,del),grid
References
1. Power System Analysis by “Bergen and Vittal”, Pearson.
2. Power System Analysis (McGraw-Hill Series in Electrical and
Computer Engineering) by “Stevenson and Grainger”.
3. Power System Analysis and design by “Glover and Sarma”,
Cengage.
4. Power Generation Operation and Control by “Wood and
Wollenberg”, John Wiley.
5. Power System Stability and Control by “Prabha Kundur”, TMH
5. Modern Power System Analysis by “D.P. Kothari and I Nagrath”,
TMH