File Merged
File Merged
─
Submitted by- Submitted To-
Kanishque Yadav Mr. Kuldeep Singh
2K22/EE.142
TABLE OF CONTENT:
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
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
Matlab Output :-
Editor - /Users /kunalgupta/Documents/MATLAB/PAS_LAB/EXP_1.m • x Workspace
EXP_1m xE
| XP_2m
. x | EXP_3m . x| +
. x | EXP_4m Name 4 Value
clc 5x5 double
nb=5; % bn is number of buses ni hte network E D 5x5 double
z = inf(nb, nb); 旧i
s ss
b = zeros(nb, nb);
D
S
D=1 2 0.004 0.0533 0;2 30.02 02.5 0.22;3 40.02 02.5 0.22;2 400.1 0.15 0.11;4 5 0.006 0.08 0]; %Fvie 155,1
4 9
# rows
r=size(D);
⽥Y
6 8
rows=r(1);
10
11 무 for 1=1: rows
12 z(D(i,1),D(i,2))=D(1,3)+j*D(i,4);|
13 z(D(i,2) ,D(i,1))=z(D(i, 1),D(i,2));
14
15
16
B 0(4,210(4, 2) 6 1(1)41,0(1, 21);
17
18 @ for i=1:nb
19
20 end Ye(1) =j*sumcb(1,:)1/2;
21
22 무 for i=1inb
32 뮈 for m=1:nb
24 if i~=m
52 Y(i,m)=-1/z(i,m);
26 else
28
27
end Y1(, m)=yo(1) + sum(1/2(1, :)):
29
30 end end
31
32 disp(Y);
Command Window
1.4001
-1.4001
-18.65671
+18.65671
0.0000 + 0.00001
-1.4001 +18.6567i
2.1606 -29.10341
-0.3180 + 3.97461
0.0000 + 0.0000i
-0.3180 + 3.97461
0.6359 - 7.72911
94.425 +66.9121
-0.4425
-0.3180 + 3.97461
0.0000
0.0000 + 0.0000i -0.4425 + 6.63721 -0.3180 + 3.97461 1.6927 -22.87681 -0.9323 +12.43011
0.0000 + 0.00001 0.0000 + 0.0000i 0.0000 + 0.00001 -0.9323 +12.43011 0.9323 - 12.43011
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:
pqb=1;
• err
⽥i 5 59290-05
nb=slb+pvb+pqb; 旧k 3
57.2958
¥=I-j*19.98 j*10 j*10;j*10 -j*19.98 j*10;j*10 j*10 -j×19.98];
⿊ phi -1.570815..
10
11 paaangler: • pab
12
31 th(1)=0;
v(2)=1.05;
Psp
pvb
Px
1100,,06..66616-02,8.6-258.635121
14
15 Psp(2)=0.6661; Qsp [0,0,-1.2244)
16 PSp(3) =-2. 8653: Qx [0,1.6417,-1.2244]
17 Qsp (3)=-1.2244; sib
18
19
20
21
th
1 0105000,9500
2
eprootn ot us, estl anurer t etiraotns of
eht aglhotm
ir
畑
23
24 while err>le-4
⽩
52 for i=2:3
62 PX(1)=0: 0X( 4)=0;
Command Window
ans =
1.0000
1.0500 -2.9999
0.9500 -10.0001
Computational Time:-
Profile Summary (Total time: 0.029 s)
+Falme Graph
EXP. 2
Profile Summary
Generated 13-Feb-2025 13:42:58 using performance time.
Function Name Calls Total Tm
ie Self Time* Total Time Plot
(s) (s) (self time / total time)
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%
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']
Matlab Output :-
• Editor - /Users/kunalgupta/Documents/MATLAB/PAS_LAB/EXP_3.m x Workspace
EXP_3.m x+ Name A Value
60 [1,0;1.0500,-3.0...
⽩ 57.2958
61
62
for p = 1: pqb
d e l q ( p ) = Qsp(p+slb+pvb) - Q×(p+slb+pvb); E9ep [4.0124e-07,-8....
63 end
Text
⽥delpo [-1.3475e-06;4....
64
65 ⽩ for p = 1: (pvb+pqb) 坦del thv 00 4-017 .
11.3475e-06
66 delp(p) = Psp(p+slb) - Px(p+slb);
67 end ⽥i
68
69 delPQ = [delq' ;delp'1; %j⽥
J
eth
70 delthv = THV + (inv(J)*delPQ); [1.2796;-3.01611
71 [1.2156,-2.86531
72 for p = (slb+1) :nb 17.6921
m m
73 th(p) = d e l t h v ( p - 1 ) ;
74 end
75 3
76
77
for p = (slb + pvb +1):nb
v(p) = delthv(p+pqb-slb); 1.5708.1.570.
78 end 10,0.6661,-2.86531
79
80 V = delthv;
T
H [0,0.6661,-2.8653]
18 err = max (abs (delPQ)) 1 0. 0 -1.2244]
82 t t +1; 10,1.6417,-1.2244]
83 end
84 Iv' co*th'l
85
Command Window ◎ [1,1.0500,0.95001
err = 1090-1010
1.3475-06
ans =
10.380 --310.00.000900
0.9500
Computational Time:-
Profile Summary (Total time: 0.021 s)
~Flame Graph
EXP 3
Profile Summary
Generated 13-Feb-2025 13:46:10 using performance time.
Function Name Calls Total Tm
ie i e*
Self Tm Total Time Plot
(s) (s) (self time / total time)
EXP_3 1 0.021 0.021
angle 37 0.000 0.000
webwindowmanager>webwindowmanager.delete 1 0.000 0.000
*Sefl time si hte time spent ni afunction excluding any time spent ni child functions. The m
it e includes any overhead time resulting orfm hte profiling process.
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
while err>1e-4
for i=(slb+1):nb
Px(i)=0;
for k=1:nb
Px(i)=Px(i)+v(i)*v(k)*y(i,k)*cos(th(i)-th(k)-phi(i,k));
end
end
% P-theta loop %
for p=1:(pvb+pqb)
delp(p)=(Psp(p+slb)-Px(p+slb))/v(p+slb);
end
TH=TH+(Jpth*delp');
for p=(slb+1):nb
th(p)=TH(p-1);
end
% Q-v loop %
for i=(slb+pvb+1):nb
Qx(i)=0;
for k=1:nb
Qx(i)=Qx(i)+v(i)*v(k)*y(i,k)*sin(th(i)-th(k)-
phi(i,k));
end
end
for p=1:pqb
delq(p)=(Qsp(p+slb+pvb)-Qx(p+slb+pvb))/v(p+slb+pvb);
end
V=V+(Jqv*delq');
for p=1:pqb
v(slb+pvb+p)=V(p);
end
delPQ=[delp';delq'];
err=max(abs(delq))
t=t+1;
end
[v' cc*th']
Matlab Output :- Workspace
• Editor - /Users /kunalgupta/Documents/MATLAB/PAS_LAB/EXP_4.m ° x
EXP_4.m x+ Name A Value
57 end = ans [1,0;1.0500,-3.0...
58 ⽥B [-19.9800,10,10;..
59 57.2958
60 for i = (slb + pvb + 1):nb [6.2263-05,-6...
61 x (i) = 0;
Q [6.2263e-05;-6....
国dela
62
63
64
⽩
Qx(1) =Qx(1) + v(1)*v(k)*y(i,k)×sin(th(i)-th(k)-phi(i,k)); 43126-005
end end ⽇ Jpt h
65
66
67 ⽇
EJpth_old
# Jqv
1960131
0.0501
for p =1:pqb
delq(p) = (osp(p+slb+pvb)-Qx(p+slb+pvb))/v(p+slb+pvb); " Jqv_old
1920
68
69 end ⽥k
70 Enb
買
71 V = V + (Jqv*delq');
⽩ phi
72
73
for p = 1: pqb
end (sib+pyb+p) = Vp() ; (-1.570,157..
74
75 10.06661--22.68665523)1
10. 0. 6660,
7
76
78
dt etr+1f;m
axatsdea) [0,0,-1.2244]
10,0,-1.2244]
79
80
81 Ev' couth' 1 0.- 0.0524.- 0.17...
1- 0. 0524:- 0.1745]
[ 1, 1.0500,0 .9500]
Command Window ◎ 0.9500
t = 1 19,9800. 10. 10:1. .
10. 0000- 19.980. .
5
ans =
10.9500
0.580 -10.30.0000001
Computational Time:-
Profile Summary (Total time: 0.014 s)
- Flame Graph
EXP 4
Summary
Profile
Generated 13-Feb-2025 13:46:50 using performance time.
‡
Function Name Calls Total Time Self Time* Total Time Plot
(s) (s) (self time / total time)
Conclusion :-
1.Gauss-Seidel method requires the most iterations (17) and highest computation time (29 ms).
2.Newton-Raphson Algorithm achieves faster convergence with only 4 iterations and 21 ms computation time.
3.Fast-Decoupled Load Flow Algorithm is the most efficient, requiring just 5 iterations and the least time (14 ms).