Matlab Programs
Matlab Programs
Matlab Programs
M.Tech E.P.S.
( 1 ) Y-BUS FORMATION
% THE Y-BUS FORMATION
clear;
clc;
basemva=100;
nbus=5;
% lp
lq
r
x
ysh
tap
linedata =[ 1
2
0.02
0.06
0.03
1
1
3
0.08
0.24
0.025
1
2
3
0.06
0.18
0.02
1
2
4
0.06
0.18
0.02
1
2
5
0.04
0.12
0.015
1
3
4
0.01
0.03
0.01
1
4
5
0.08
0.24
0.025
1 ];
nline=length(linedata(:,1));
j=sqrt(-1);
i=sqrt(-1);
for k=1:nline
lp(k)=linedata(k,1);
lq(k)=linedata(k,2);
r(k)=linedata(k,3);
x(k)=linedata(k,4);
ysh(k)=linedata(k,5);
a(k)=linedata(k,6);
z(k)= r(k)+j*x(k);
y(k)=1/z(k);
end
ybus=zeros(nbus,nbus);
yln =zeros(nbus,nbus);
% PI METHOD FOR OFF-NOMINAL ADMITTANCE OF TRANSFORMER
for k=1:nline
ylp(k)=[1/(a(k)^2)-1/a(k)]*y(k);
ylq(k)=[1-1/a(k)]*y(k);
y(k)=y(k)/a(k);
end
for k=1:nline
ybus(lp(k),lq(k))=ybus(lp(k),lq(k))-y(k);
ybus(lq(k),lp(k))=ybus(lp(k),lq(k));
ybus(lp(k),lp(k))=ybus(lp(k),lp(k))+y(k)+ylp(k)+j*ysh(k);
ybus(lq(k),lq(k))=ybus(lq(k),lq(k))+y(k)+ylq(k)+j*ysh(k);
end
ybus
SIMULATION LAB
M.Tech E.P.S.
OUTPUT :-
Y-BUS =
6.2500 -18.695i
-5.000 + 15.000i
-1.250 + 3.750i
-5.0000 +15.000i
10.833-32.415i
-1.667 + 5.000i
-1.2500 + 3.750i
-1.667 + 5.000i
-1.667+ 5.000i
-2.500 + 7.500i
0
-1.6667 + 5.000i
0
-2.500 + 7.500i
0
3.750 -11.210i
SIMULATION LAB
M.Tech E.P.S.
( 2 ) GAUSS-SEIDEL METHOD
% THE Y-BUS FORMATION
clear;
clc;
basemva=100;
% n code
v
delta
Pg Qg Pd Qd Qmin
Qmax
busdata = [
1
0
1.04
0
0
0
0
0
0
0
2
1
1.04
0
100 0
50 0
20
100
3
2
1.00
0
0
0 100 -50 0
0
4
2
1.00
0
0
0 -30 10 0
0
0];
% lp
lq
r
x
ysh
tap
linedata =[ 1
2
0.05
0.15
0.0
1
1
3
0.1
0.3
0.0
1
2
3
0.15
0.45
0.0
1
2
4
0.1
0.3
0.0
1
3
4
0.05
0.15
0.0
1];
nline=length(linedata(:,1));
j=sqrt(-1);
i=sqrt(-1);
for k=1:nline
lp(k)=linedata(k,1);
lq(k)=linedata(k,2);
r(k)=linedata(k,3);
x(k)=linedata(k,4);
ysh(k)=linedata(k,5);
a(k)=linedata(k,6);
nbus=length(busdata(:,2));
z(k)= r(k)+j*x(k);
y(k)=1/z(k);
end
ybus=zeros(nbus,nbus);
yln =zeros(nbus,nbus);
% PI METHOD FOR OFF-NOMINAL ADMITTANCE OF TRANSFORMER
for k=1:nline
ylp(k)=[1/(a(k)^2)-1/a(k)]*y(k);
ylq(k)=[1-1/a(k)]*y(k);
y(k)=y(k)/a(k);
end
for k=1:nline
ybus(lp(k),lq(k))=ybus(lp(k),lq(k))-y(k);
ybus(lq(k),lp(k))=ybus(lp(k),lq(k));
ybus(lp(k),lp(k))=ybus(lp(k),lp(k))+y(k)+ylp(k)+j*ysh(k);
ybus(lq(k),lq(k))=ybus(lq(k),lq(k))+y(k)+ylq(k)+j*ysh(k);
end
Qsh
0
0
0
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
if kb(m)==1
%Generator bus
for k=1:nbus
if k~=m
yv(m)=yv(m)+ybus(m,k)*e(k);
end
end
cos(m)=real(e(m))/abs(e(m));
sin(m)=imag(e(m))/abs(e(m));
e(m)=vm(m)*cos(m)+j*vm(m)*sin(m);
Qnew(m)=-imag(conj(e(m))*(yv(m) ybus(m,m)*e(m)))*100;
if(Qnew(m))<Qmin(m)
Q(m)=Qmin(m)/basemva;
S(m)=P(m)+j*Q(m);
e(m)=1.0+0*j;
vc(m)=((conj(S(m))/conj(e(m)))-yv(m))/ybus(m,m);
e(m)=e(m)+1.4*(vc(m)-e(m));
elseif Qnew(m) >Qmax(m)
Q(m)=Qmax(m)/basemva;
S(m)=P(m)+j*Q(m);
e(m)=1+0*j;
vc(m)=((conj(S(m))/conj(e(m)))-yv(m))/ybus(m,m);
e(m)=e(m)+1.4*(vc(m)-e(m));
else
Q(m)=Qnew(m)/basemva;
S(m)=P(m)+j*Q(m);
vc(m)=((conj(S(m))/conj(e(m)))-yv(m))/ybus(m,m);
cos(m)=real(vc(m))/(abs(vc(m)));
sin(m)=imag(vc(m))/(abs(vc(m)));
vnew(m)=vm(m)*cos(m)+j*vm(m)*sin(m);
e(m)=vnew(m);
end
end
end
maxerror=max(error);
iter=iter+1;
iter
e
end
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
E1
E2
E3
E4
1.0400
1.0395 + 0.0335i
1.0444 - 0.1251i
1.0599 - 0.0545i
1.0400
1.1067 - 0.0030i
1.0733 - 0.1206i
1.0965 - 0.0483i
1.0400
1.1281 + 0.0005i
1.0960 - 0.1134i
1.1126 - 0.0438i
1.0400
1.1400 + 0.0040i
1.1033 - 0.1095i
1.1183 - 0.0409i
1.0400
1.1440 + 0.0061i
1.1062 - 0.1075i
1.1205 - 0.0395i
1.0400
1.1456 + 0.0072i
1.1073 - 0.1066i
1.1214 - 0.0388i
1.0400
1.1462 + 0.0077i
1.1078 - 0.1062i
1.1218 - 0.0385i
1.0400
1.1465 + 0.0079i
1.1080 - 0.1060i
1.1219 - 0.0383i
1.0400
1.1466 + 0.0080i
1.1081 - 0.1060i
1.1220 - 0.0383i
10
1.0400
1.1466 + 0.0080i
1.1081 - 0.1059i
1.1220 - 0.0383i
11
1.0400
1.1466 + 0.0081i
1.1081 - 0.1059i
1.1220 - 0.0383i
12
1.0400
1.1467 + 0.0081i
1.1082 - 0.1059i
1.1220 - 0.0383i
27.2172 +64.8737i
-25.9601 +32.2794i
-29.5052 -71.7377i
-29.0835 - 0.3204i
24.3737 -37.0387i
28.1185 - 2.5748i
18.4622 + 2.4761i
-48.4641 + 7.5230i
0
-18.7376 - 3.3020i
47.5099 -10.3857i
0
SIMULATION LAB
M.Tech E.P.S.
E1
E2
E3
E4
1.0400
1.0783 + 0.0477i
1.0543 - 0.1215i
1.0872 - 0.0444i
1.0400
1.1254 - 0.0002i
1.0955 - 0.1125i
1.1145 - 0.0445i
1.0400
1.1463 + 0.0021i
1.1066 - 0.1109i
1.1236 - 0.0429i
1.0400
1.1526 + 0.0031i
1.1110 - 0.1089i
1.1269 - 0.0416i
1.0400
1.1550 + 0.0041i
1.1126 - 0.1079i
1.1282 - 0.0408i
1.0400
1.1559 + 0.0047i
1.1132 - 0.1075i
1.1287 - 0.0405i
1.0400
1.1562 + 0.0049i
1.1135 - 0.1072i
1.1289 - 0.0403i
1.0400
1.1564 + 0.0050i
1.1136 - 0.1072i
1.1289 - 0.0402i
1.0400
1.1564 + 0.0051i
1.1137 - 0.1071i
1.1290 - 0.0402i
10
1.0400
1.1564 + 0.0051i
1.1137 - 0.1071i
1.1290 - 0.0402i
11
1.0400
1.1565 + 0.0051i
1.1137 - 0.1071i
1.1290 - 0.0402i
27.4140 +71.6035i
0
-25.7502 + 34.1245i
-29.2448 - 1.3727i
0
-18.8788 - 4.3724i
28.2834 - 1.5113i
47.6586 - 9.2942i
18.5980 + 3.5300i
-48.6003 + 6.4688i
SIMULATION LAB
M.Tech E.P.S.
( 3 ) F.D.L.F. METHOD
clear;
clc;
basemva=100;
% n code v del pg qg pd qd qmin qmax qsh
busdata=[1 0 1.06 0
0 0 0 0 0
0
0
2 2 1.0 0 40 30 20 10 0
0
0
3 2 1.0 0 0 0 45 15 0
0
0
4 2 1.0 0 0 0 40 5 0
0
0
5 2 1.0 0 0 0 60 10 0 0
0 ];
% lp lq r
x
ysh
tap
linedata=[1 2 0.02 0.06 0.030
1
1 3 0.08 0.24 0.025
1
2 3 0.06 0.18 0.020
1
2 4 0.06 0.18 0.020
1
2 5 0.04 0.12 0.015
1
3 4 0.01 0.03 0.01
1
4 5 0.08 0.24 0.025
1 ];
%Ybus formulation by inspection method
nline=length(linedata(:,1));
for k=1:nline
lp(k)=linedata(k,1);
lq(k)=linedata(k,2);
r(k)=linedata(k,3);
x(k)=linedata(k,4);
ysh(k)=linedata(k,5);
a(k)=linedata(k,6);
nbus=length(busdata(:,2));
z(k)=r(k)+j*x(k);
y(k)=1/z(k);
end
ybus=zeros(nbus,nbus);
% PI METHOD FOR OFF-NOMINAL ADMITTANCE OF TRANSFORMER
for k=1:nline
ylp(k)=(1/a(k)^2-1/a(k))*y(k);
ylq(k)=(1.0-1/a(k))*y(k);
y(k)=y(k)/a(k);
end
for k=1:nline
ybus(lp(k),lq(k))=ybus(lp(k),lq(k))-y(k);
ybus(lq(k),lp(k))=ybus(lp(k),lq(k));
ybus(lp(k),lp(k))=ybus(lp(k),lp(k))+y(k)+ylp(k)+j*ysh(k);
ybus(lq(k),lq(k))=ybus(lq(k),lq(k))+y(k)+ylq(k)+j*ysh(k);
end
SIMULATION LAB
M.Tech E.P.S.
for n=1:nbus
bus(n)=busdata(n,1);
kb(n)=busdata(n,2);
vm(n)=busdata(n,3);
delta(n)=busdata(n,4);
pg(n)=busdata(n,5);
qg(n)=busdata(n,6);
pd(n)=busdata(n,7);
qd(n)=busdata(n,8);
qmin(n)=busdata(n,9);
qmax(n)=busdata(n,10);
qsh(n)=busdata(n,11);
delta(n)=pi/180*delta(n);
v(n)=vm(n)*cos(delta(n))+j*vm(n)*sin(delta(n));
p(n)=(pg(n)-pd(n))/basemva;
q(n)=(qg(n)-qd(n))/basemva;
s(n)=p(n)+j*q(n);
end
ym=abs(ybus);
t=angle(ybus);
ii=0;
for n=1:nbus
if(kb(n)==1|kb(n)==2)
ii=ii+1;
jj=0;
for m=1:nbus
if(kb(m)==1|kb(m)==2)
jj=jj+1;
B1(ii,jj)=imag(ybus(n,m));
end
end
end
end
ii=0;
for n=1:nbus
if(kb(n)==2)
ii=ii+1;
jj=0;
for m=1:nbus
if(kb(m)==2)
jj=jj+1;
B2(ii,jj)=imag(ybus(n,m));
end
end
end
end
SIMULATION LAB
M.Tech E.P.S.
B1inv=inv(B1);
B2inv=inv(B2);
maxerror=0.1;
iter=0;
while maxerror>0.00001&iter<15
iter=iter+1;
id=0;
iv=0;
for n=1:nbus
J11=0;
J33=0;
for m=1:nline
if(lp(m)==n|lq(m)==n)
if(lp(m)==n)
l=lq(m);
end
if(lq(m)==n)
l=lp(m);
end
J11=J11+vm(n)*vm(l)*ym(n,l)*sin(t(n,l)-delta(n)
+delta(l));
J33=J33+vm(n)*vm(l)*ym(n,l)*cos(t(n,l)-delta(n)
+delta(l));
end
end
pk=vm(n)^2*ym(n,n)*cos(t(n,n))+J33;
qk=-vm(n)^2*ym(n,n)*sin(t(n,n))-J11;
if(kb(n)==0)
p(n)=pk;
q(n)=qk;
end
if(kb(n)==1)
q(n)=qk;
qgc=q(n)*basemva+qd(n)-qsh(n);
if qmax(n)~=0
if iter<=20
if iter>=10
if(qgc<qmin(n)|qgc>qmax(n))
if(qgc<qmin(n))
vm(n)=vm(n)+0.0005;
else
vm(n)=vm(n)-0.0005;
end
end
end
SIMULATION LAB
M.Tech E.P.S.
end
end
end
if(kb(n)~=0)
id=id+1;
dp(id)=p(n)-pk;
dpv(id)=(p(n)-pk)/vm(n);
iv=iv+1;
dq(iv)=q(n)-qk;
dqv(iv)=(q(n)-qk)/vm(n);
end
end
f=dpv';
dd=-B1inv*dpv';
dv=-B2inv*dqv';
id=0;
iv=0;
for n=1:nbus
if(kb(n)~=0)
id=id+1;
delta(n)=delta(n)+dd(id);
iv=iv+1;
vm(n)=vm(n)+dv(iv);
end
end
maxerror=max(max(abs(dp)),max(abs(dq)));
iter
E=vm.*cos(delta)+j*vm.*sin(delta)
end
SIMULATION LAB
M.Tech E.P.S.
OUTPUT :-
ITER
E0
E1
E2
E3
E4
1.0600
1.0691 - 0.0404i
1.0566 - 0.0920i
1.0575 - 0.0988i
1.0558 - 0.1166i
1.0600
1.0493 - 0.0591i
1.0191 - 0.0982i
1.0175 - 0.1043i
1.0089 - 0.1186i
1.0600
1.0427 - 0.0519i
1.0162 - 0.0881i
1.0150 - 0.0938i
1.0077 - 0.1072i
1.0600
1.0461 - 0.0502i
1.0208 - 0.0883i
1.0197 - 0.0942i
1.0129 - 0.1083i
1.0600
1.0466 - 0.0513i
1.0207 - 0.0894i
1.0195 - 0.0953i
1.0124 - 0.1093i
1.0600
1.0461 - 0.0514i
1.0202 - 0.0893i
1.0190 - 0.0951i
1.0119 - 0.1091i
1.0600
1.0461 - 0.0513i
1.0203 - 0.0892i
1.0191 - 0.0950i
1.0121 - 0.1090i
1.0600
1.0462 - 0.0513i
1.0203 - 0.0892i
1.0192 - 0.0951i
1.0121 - 0.1091i
1.0600
1.0462 - 0.0513i
1.0203 - 0.0892i
1.0191 - 0.0951i
1.0121 - 0.1091i
10
1.0600
1.0462 - 0.0513i
1.0203 - 0.0892i
1.0191 - 0.0951i
1.0121 - 0.1091i
11
1.0600
1.0462 - 0.0513i
1.0203 - 0.0892i
1.0191 - 0.0951i
1.0121 - 0.1091i
12
1.0600
1.0462 - 0.0513i
1.0203 - 0.0892i
1.0191 - 0.0951i
1.0121 - 0.1091i
13
1.0600
1.0462 - 0.0513i
1.0203 - 0.0892i
1.0191 - 0.0951i
1.0121 - 0.1091i
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
invG=inv(G(2:nbus,2:nbus));
%reading the bus data
for k=1:nbus
bus(k)=busdata(k,1);
vm(k)=busdata(k,2);
delta(k)=busdata(k,3);
pd(k)=busdata(k,4);
qd(k)=busdata(k,5);
delta=pi/180*delta;
end
maxerror=1;
iter=0;
while(maxerror>0.0001 & iter<30)
iter=iter+1;
%initialisation of isp,ical
for k=1:nbus-1
isp(k)=0;
ik(k)=0;
end
%calculation of specified e.c.i.
for k=1:nbus-1
isp(k)=[conj(pd(k+1)+j*qd(k+1))/vm(k+1)];
end
%calculation of ik
for n=2:nbus
for k=1:nline
if lp(k)==n||lq(k)==n
if lp(k)==n
ik(n-1)=ik(n-1)+y(k)*(vm(lp(k))-vm(lq(k)));
end
if lq(k)==n
ik(n-1)=ik(n-1)+y(k)*(vm(lq(k))-vm(lp(k)));
end
end
end
end
%calculation of ical including the effect of shunt capacitance
for n=2:nbus
ik(n-1)=ik(n-1)+(j*busdata(n,6)*vm(n));
end
%finding e.c.i.mismatcher
for n=1:nbus-1
id(n)=-isp(n)-ik(n);
end
SIMULATION LAB
M.Tech E.P.S.
for i=1:nbus-1
delir(i,1)=real(id(i));
delii(i,1)=imag(id(i));
end
dele=invG*delir;
%change in bus voltage(real part)
delf=invG*delii;
%change in bus voltage(imag part)
%calculation of modified bus voltages
for i=1:nbus-1
e(i)=real(vm(i+1))+dele(i);
f(i)=imag(vm(i+1))+delf(i);
vm(i+1)=e(i)+j*f(i);
end
maxerror=max(max(abs(dele)),max(abs(delf)));
Em=abs(vm);
ang=angle(vm);
iter
Em
ang
end
SIMULATION LAB
M.Tech E.P.S.
E0
E1
E2
E3
E4
E5
1.0500
0.9684
0.9496
0.9235
0.9214
0.9048
2.
1.0500
0.9907
0.9695
0.9597
0.9571
0.9672
3.
1.0500
1.0066
0.9945
0.9954
0.9939
1.0083
4.
1.0500
1.0038
0.9937
0.9925
0.9914
0.9986
5.
1.0500
0.9975
0.9833
0.9783
0.9766
0.9829
6.
1.0500
0.9965
0.9809
0.9755
0.9736
0.9819
7.
1.0500
0.9985
0.9846
0.9801
0.9784
0.9865
8.
1.0500
0.9995
0.9864
0.9824
0.9808
0.9882
9.
1.0500
0.9991
0.9853
0.9811
0.9795
0.9872
10.
1.0500
0.9985
0.9843
0.9800
0.9783
0.9863
11.
1.0500
0.9985
0.9846
0.9802
0.9785
0.9863
12.
1.0500
0.9988
0.9850
0.9807
0.9790
0.9867
13.
1.0500
0.9988
0.9850
0.9807
0.9790
0.9868
14.
1.0500
0.9987
0.9848
0.9805
0.9788
0.9867
15.
1.0500
0.9987
0.9848
0.9805
0.9788
0.9866
16.
1.0500
0.9987
0.9849
0.9806
0.9789
0.9866
SIMULATION LAB
M.Tech E.P.S.
-0.0483
-0.0455
-0.0816
-0.0810
-0.1318
-0.0715
-0.0829
-0.1368
-0.1381
-0.1965
-0.0557
-0.0638
-0.1063
-0.1072
-0.1525
-0.0519
-0.0590
-0.0991
-0.0999
-0.1421
-0.0519
-0.0573
-0.0975
-0.0980
-0.1441
-0.0555
-0.0637
-0.1060
-0.1068
-0.1530
-0.0567
-0.0659
-0.1088
-0.1099
-0.1548
-0.0622
-0.0757
-0.1225
-0.1241
-0.1685
-0.0549
-0.0625
-0.1046
-0.1054
-0.1512
10
-0.0551
-0.0630
-0.1052
-0.1060
-0.1515
11
-0.0554
-0.0637
-0.1059
-0.1069
-0.1521
12
-0.0555
-0.0636
-0.1059
-0.1068
-0.1522
13
-0.0553
-0.0633
-0.1056
-0.1064
-0.1520
14
-0.0553
-0.0633
-0.1055
-0.1064
-0.1519
15
-0.0553
-0.0634
-0.1056
-0.1065
-0.1519
16
-0.0554
-0.0634
-0.1057
-0.1066
-0.1520
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
pause
time(i)=t;
ang(i)=deltadeg
i=i+1;
end
axis ([0 0.6 0 160])
plot(time,ang,'ko-')
grid
SIMULATION LAB
M.Tech E.P.S.
OUTPUT :-
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
Comparison of Accelerating Powers (Pa) (p.u.) at different Fault clearing times :S.No.
Time(t)
(sec)
1.
0.00
0.2878
0.2878
0.2878
2.
0.05
0.3095
0.2878
0.5391
3.
0.10
-0.0862
0.4390
0.4390
4.
0.15
-0.2215
-0.4614
0.3010
5.
0.20
-0.2951
-0.6339
0.1629
6.
0.25
-0.2937
-0.6675
0.0615
7.
0.30
-0.2177
-0.5667
0.0204
8.
0.35
-0.0806
-0.3223
0.0480
9.
0.40
0.0857
0.0453
0.1465
10.
0.45
0.2338
0.4389
0.3229
11.
0.50
0.3160
0.7160
0.5964
SIMULATION LAB
M.Tech E.P.S.
Time (t)
(sec)
1.
0.00
24.2100
24.2100
24.2100
2.
0.05
29.5432
31.5936
31.5936
3.
0.10
34.1071
42.8966
42.8966
4.
0.15
36.6935
50.0804
56.8872
5.
0.20
36.6454
51.6045
72.3324
6.
0.25
33.9747
47.1688
88.3267
7.
0.30
29.3607
37.6732
104.5030
8.
0.35
24.0270
25.2998
121.1082
9.
0.40
19.4581
13.3307
139.0219
10.
0.45
16.9764
5.2801
159.8188
11.
0.50
17.3166
3.6218
185.9408
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
SIMULATION LAB
M.Tech E.P.S.
Fig . TIE-LINE POWER DEVIATION IN TWO AREA SYSTEM WITH INTEGRAL CONTROL