0% found this document useful (0 votes)
93 views41 pages

Lab Experiments Psad M.tech

The document contains programs and outputs for solving simultaneous algebraic and differential equations using MATLAB. In Experiment 1, the Gauss-Seidel elimination method is used to solve simultaneous algebraic equations for 3 and 4 variables. Experiment 2 uses the Range-Kutta method to solve simultaneous differential equations for 2 and 3 variables. Experiment 3 formulates the bus admittance matrix (Y-bus) for a 4 bus and 6 bus system using the direct inspection method in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views41 pages

Lab Experiments Psad M.tech

The document contains programs and outputs for solving simultaneous algebraic and differential equations using MATLAB. In Experiment 1, the Gauss-Seidel elimination method is used to solve simultaneous algebraic equations for 3 and 4 variables. Experiment 2 uses the Range-Kutta method to solve simultaneous differential equations for 2 and 3 variables. Experiment 3 formulates the bus admittance matrix (Y-bus) for a 4 bus and 6 bus system using the direct inspection method in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

EXPERIMENT -1

SOLUTION OF SIMULATENOUS ALGEBRAIC EQUATIONS USING MATLAB

PROGRAM FOR GAUSS SEIDEL ELIMINATION METHOD IN MATLAB


clc;
clear all;
ip=fopen('mat.ip','r+');
op=fopen('mat.op','w+');
n=3;
a=fscanf(ip,'%g',[n,n]);
y=fscanf(ip,'%g',[n,1]);
g=transpose(y);
b=transpose(a);
fprintf(op,'Solution for Simultaneous Algebraic Equation\n');
fprintf(op,'\t\t\t AX=Y Using MATLAB\n\n');
fprintf(op,'Input 3-Varibale \n');
fprintf(op,'Matrix A :\n');
for i=1:n
for j=1:n
fprintf(op,'%g\t',a(i,j));
end
fprintf(op,'\n');
end
fprintf(op,'\nMatrix Y :\n');
fprintf(op,'%g\n',g);
fprintf(op,'\n\n');
for i=1:n
g(i)=g(i)/b(i,i);
for j=n:-1:i
b(i,j)=b(i,j)/b(i,i);
end
for k=n:-1:i+1
g(k)=g(k)-b(k,i)*g(i);
for jj=n:-1:1
b(k,jj)=b(k,jj)-b(k,i)*b(i,jj);
end
end
end
x=g;
for i=n:-1:1
for j=i+1:n
x(i)=x(i)-b(i,j)*x(j);
end
end
fprintf(op,'Output\n');
fprintf(op,'Matrix X :\n');
fprintf(op,'%g\n',x);
fclose all;

INPUT FOR GAUSS SEIDEL ELIMINATION METHOD


10
2
2

1
10
2

1
1
10

12
13
14

OUTPUT FOR GAUSS SEIDEL ELIMINATION METHOD


Solution for Simultaneous Algebraic Equation
AX=Y Using MATLAB
Inputs 3-Variable
Matrix A :
10 2
2
1
10 2
1
1
10
Matrix Y :
12
13
14

Output
Matrix X :
1
1
1

PROGRAM FOR GAUSS SEIDEL ELIMINATION METHOD IN MATLAB


clc;
clear all;
ip=fopen('mat.ip','r+');
op=fopen('mat.op','w+');
n=4;
a=fscanf(ip,'%g',[n,n]);
y=fscanf(ip,'%g',[n,1]);
g=transpose(y);
b=transpose(a);
fprintf(op,'Solution for Simultaneous Algebraic Equation\n');
fprintf(op,'\t\t\t AX=Y Using MATLAB\n\n');
fprintf(op,'Input 4-Varibale \n');
fprintf(op,'Matrix A :\n');
for i=1:n
for j=1:n
fprintf(op,'%g\t',a(i,j));
end
fprintf(op,'\n');
end
fprintf(op,'\nMatrix Y :\n');
fprintf(op,'%g\n',g);
fprintf(op,'\n\n');
for i=1:n
g(i)=g(i)/b(i,i);
for j=n:-1:i
b(i,j)=b(i,j)/b(i,i);
end
for k=n:-1:i+1
g(k)=g(k)-b(k,i)*g(i);
for jj=n:-1:1
b(k,jj)=b(k,jj)-b(k,i)*b(i,jj);
end
end
end
x=g;
for i=n:-1:1
for j=i+1:n
x(i)=x(i)-b(i,j)*x(j);
end
end
fprintf(op,'Output\n');
fprintf(op,'Matrix X :\n');
fprintf(op,'%g\n',x);
fclose all;

INPUT FOR GAUSS SEIDEL ELIMINATION METHOD


2.38
3.21
1.44
4.17

1.95
-0.86
2.95
3.60

-3.27
2.40
-2.14
-1.68

1.58
-3.20
1.86
-2.26

2.16
3.28
1.42
5.21

OUTPUT FOR GAUSS SEIDEL ELIMINATION METHOD


Solution for Simultaneous Algebraic Equation
AX=Y Using MATLAB
Inputs 4-Variable
Matrix A :
2.38
3.21
1.44
4.17
1.95
-0.86
2.95
3.6
-3.27
2.4 -2.14
-1.68
1.58
-3.2
1.86
-2.26
Matrix Y :
2.16
3.28
1.42
5.21

Output
Matrix X :
0.805827
0.238181
-0.106058
-0.360209

EXPERIMENT -2
SOLUTION OF SIMULATENOUS DIFFERENTIAL EQUATIONS USING RK METHOD IN MATLAB

PROGRAM FOR RANGE-KUTTA METHOD IN MATLAB


Program for RK Method 4th Order with 2 Variable
clc;
clear all;
op=fopen('mat.op','w+');
x0=0;
y0=1;
h=0.2;
fprintf(op,'Solution for Simultaneous Differential Equations \n');
fprintf(op,'\t\t\tUsing RK Method in MATLAB \n\n');
fprintf(op,'Program for RK Method 4th Order with 2 Variable \n\n');
fprintf(op,'When X0=0, Y0=1 and h=0.2\n\n');
x=x0;
y=y0;
f1=((y^2-x^2)/(y^2+x^2));
k1=h*f1;
fprintf(op,'F1=\t%g\n',f1);
fprintf(op,'K1=\t%g\n',k1);
fprintf(op,'Y=\t%g\n\n',y);
x1=x+(h/2);
y1=y+(k1/2);
f2=((y1^2-x1^2)/(y1^2+x1^2));
k2=h*f2;
fprintf(op,'F2=\t%g\n',f2);
fprintf(op,'K2=\t%g\n',k2);
fprintf(op,'Y1=\t%g\n\n',y1);
x2=x+(h/2);
y2=y+(k2/2);
f3=((y2^2-x2^2)/(y2^2+x2^2));
k3=h*f3;
fprintf(op,'F3=\t%g\n',f3);
fprintf(op,'K3=\t%g\n',k3);
fprintf(op,'Y2=\t%g\n\n',y2);
x3=x+h;
y3=y+k3;
f4=((y3^2-x3^2)/(y3^2+x3^2));
k4=h*f4;
Y=y+((k1+2*k2+2*k3+k4)/6);
fprintf(op,'F4=\t%g\n',f4);
fprintf(op,'K4=\t%g\n\n',k4);
fprintf(op,'Y=(Y+(K1+2*K2+2*K3=K4)/6)=\t%g',Y);
fclose all;

OUTPUT BY RANGE-KUTTA METHOD


Solution for Simultaneous Differential Equations
Using RK Method in MATLAB
Program for RK Method 4th Order with 2 Variable
When X0=0, Y0=1 and h=0.2
F1= 1
K1= 0.2
Y= 1
F2= 0.983607
K2= 0.196721
Y1= 1.1
F3= 0.983558
K3= 0.196712
Y2= 1.09836
F4= 0.945657
K4= 0.189131
Y=(Y+(K1+2*K2+2*K3=K4)/6)=

1.196

PROGRAM FOR RANGE-KUTTA METHOD IN MATLAB


Program for RK Method 4th Order with 3 Variable
clc;
op=fopen('out.op','w+')
x0=0;
y0=0;
z0=1;
h=0.1;
n=3;
fprintf(op,'Solution for Simultaneous Differential Equations \n');
fprintf(op,'\t\t\tUsing RK Method in MATLAB \n\n');
fprintf(op,'Program for RK Method 4th Order with 3 Variables \n\n');
fprintf(op,'When X0=0,Y0=0,Z0=1 and h=0.1\n\n');
fprintf(op,'The First Iteration at: \n');
for t=1:3;
fprintf(op,'t=%g\n',t)
x=x0;
y=y0;
z=z0;
f=x+z;
g=x-y;
k1=h*f;
l1=h*g;
fprintf(op,'K1=%f\nL1=%f\n',k1,l1);
x1=x0+(h/2);
y1=y0+(k1/2);
z1=z0+(l1/2);
f=x1+z1;
g=x1-y1;
k2=h*f;
l2=h*g;
fprintf(op,'K2=%f\nL2=%f\n',k2,l2);
x2=x0+(h/2);
y2=y0+(k2/2);
z2=z0+(l2/2);
f=x2+z2;
g=x2-y2;
k3=h*f;
l3=h*g;
fprintf(op,'K3=%f\nL3=%f\n',k3,l3);
x3=x0+h;
y3=y0+k3;
z3=z0+l3;
f=x3+z3;
g=x3-y3;
k4=h*f;
l4=h*g;
fprintf(op,'K4=%f\nL4=%f\n',k4,l4);
X=x0+h;
Y=y0+((k1+(2*k2)+(2*k3)+k4)/6);
Z=z0+((l1+(2*l2)+(2*l3)+l4)/6);
x0=X;
y0=Y;
z0=Z;
fprintf(op,'X=%f\nY=%f\nZ=%f\n',X,Y,Z);
t=t+1;
if t<=n
fprintf(op,'\nThe Next Iteration is :\n');

end
end
fclose all;

OUTPUT BY RANGE-KUTTA METHOD


Solution for Simultaneous Differential Equations
Using RK Method in MATLAB
Program for RK Method 4th Order With 3 Variables
When X0=0,Y0=0,Z0=1 and h=0.1
The First Iteration at:
t=1
K1=0.100000
L1=0.000000
K2=0.105000
L2=0.000000
K3=0.105000
L3=-0.000250
K4=0.109975
L4=-0.000500
X=0.100000
Y=0.104996
Z=0.999833

The Next Iteration is :


t=2
K1=0.109983
L1=-0.000500
K2=0.114958
L2=-0.000999
K3=0.114933
L3=-0.001248
K4=0.119859
L4=-0.001993
X=0.200000
Y=0.219933
Z=0.998669

The Next Iteration is :


t=3
K1=0.119867
L1=-0.001993
K2=0.124767
L2=-0.002987
K3=0.124718
L3=-0.003232
K4=0.129544
L4=-0.004465
X=0.300000
Y=0.344663
Z=0.995520

EXPERIMENT -3
FORMULATION OF Y BUS BY DIRECT INSPECTION METHOD IN MATLAB

PROGRAM FOR FORMATION OF Y-BUS (DIRECT INSPECTION METHOD)


%Formation of Bus Admittance Matrix
%
Direct Inspection Method
clc;
clear all;
nbus=4;
nline=4;
fprintf('The Inputs Buses:\n')
sbus=[1 2
1
3]
% Starting Bus
ebus=[2 3
3
4]
% Ending Bus
fprintf('The Impedances')
imp=[0+0.2i 0+0.1i 0+0.3i 0+0.4i]
% Line Impedances
fprintf('Line Capacitances')
lca=[0 0
0
0]
% Line Capacitances
y=zeros(nbus,nbus);
for i=1:nline
m=sbus(i);
n=ebus(i);
y(m,m)=y(m,m)+(1/(imp(i)))+lca(i);
y(n,n)=y(n,n)+(1/(imp(i)))+lca(i);
y(m,n)=-1/(imp(i));
y(n,m)=-1/(imp(i));
end
fprintf('The Obtained Bus Admittance Matrix is')
y

OUTPUT FOR FORMATION OF Y-BUS (DIRECT INSPECTION METHOD)


The Inputs Buses:
sbus =
1
ebus =

2
3
3
The Impedances
imp =
0+0.2000i
Line Capacitances
lca =
0
0

3
4

0+0.1000i

0+0.3000i

0+0.4000i

The Obtained Bus Admittance Matrix is


y =
0-8.3333i
0+5.0000i
0+3.3333i
0

0+5.0000i
0-15.0000i
0+10.0000i
0

0+ 3.3333i
0+10.0000i
0-15.8333i
0+2.5000i

0
0
0+2.5000i
0-2.5000i

PROGRAM FOR FORMATION OF Y-BUS (DIRECT INSPECTION METHOD)


%Formulation of Ybus by Direct Inspection Method(DIM) for an 6 bus system
clc;
ip=fopen('Ybus.ip','r+');
op=fopen('ybus.out','w+');
M=fscanf(ip,'%g',[8,7]);
b=transpose(M);
k=b(:,1);
lp=b(:,2);
lq=b(:,3);
r=b(:,4);
% Resistance, R...
x=b(:,5);
% Reactance, X...
ycp=1i*b(:,6);
ycq=1i*b(:,7);
% Ground Admittance, B/2...
tap=b(:,8);
% Tap setting value..
Z=r+1i*x;
% z matrix...
yline=1./Z;
ysh=1i*0.005;
n=max(max(lp),max(lq));
% No. of buses...
nline=length(lp);
% No. of elements...
ybus=zeros(n,n);
for k=1:nline
yline(k)=1/complex(r(k),x(k));
if tap(k)~=1;
t1=((1/(tap(k))^2)-(1/tap(k)));
t2=(1-(1/tap(k)));
ycp(k)=yline(k)*t1;
ycq(k)=yline(k)*t2;
yline(k)=yline(k)/tap(k);
end
end
for k=1:nline
p=lp(k);
q=lq(k);
ybus(p,p)=ybus(p,p)+yline(k)+ycp(k);
ybus(q,q)=ybus(q,q)+yline(k)+ycq(k);
ybus(p,q)=ybus(p,q)-yline(k);
ybus(q,p)=ybus(p,q);
end
for i=1:n
ybus(i,i)=ybus(i,i)+ysh;
end
fprintf(op,'Y Bus for 6 Bus System is Obtained by using Direct Inspection
Method\n\n\n');
for i=1:n
for j=1:n
fprintf(op,'(%0.4f)+j(%0.4f)\t',real(ybus(i,j)),imag(ybus(i,j)));
end
fprintf(op,'\n');
end
fclose all;

INPUT FOR FORMATION OF Y-BUS (DIRECT INSPECTION METHOD)


1
2
3
4
5
6
7

1
1
2
2
4
4
6

4
6
3
5
3
6
5

0.08
0.123
0.723
0.282
0.000
0.097
0.000

0.37
0.518
1.05
0.64
0.133
0.407
0.300

0.007
0.010
0.000
0.000
0.000
0.0076
0.000

0.007
0.010
0.000
0.000
0.000
0.0076
0.000

1
1
1
1
0.909
1
0.976

OUT PUT FOR FORMATION OF Y-BUS (DIRECT INSPECTION METHOD)


Y Bus for 6 Bus System is Obtained by using Direct Inspection Method

(0.99)+j(-4.39)
(0.00)+j(0.00)
(0.00)+j(0.00)
(-0.56)+j(2.58)
(0.00)+j(0.00)
(-0.43)+j(1.83)

(0.00)+j(0.00)
(1.02)+j(-1.95)
(-0.44)+j(0.65)
(0.00)+j(0.00)
(-0.58)+j(1.31)
(0.00)+j(0.00)

(0.00)+j(0.00)
(-0.44)+j(0.65)
(0.44)+j(-8.16)
(0.00)+j(8.27)
(0.00)+j(0.00)
(0.00)+j(0.00)

(-0.56)+j(2.58) (0.00)+j(0.00) (-0.43)+j(1.83)


(0.00)+j(0.00) (-0.58)+j(1.31) (0.00)+j(0.00)
(0.00)+j(8.27) (0.00)+j(0.00) (0.00)+j(0.00)
(1.11)+j(-13.99)
(0.00)+j(0.00) (-0.55)+j(2.32)
(0.00)+j(0.00) (0.58)+j(-4.64) (0.00)+j(3.42)
(-0.55)+j(2.32) (0.00)+j(3.42) (0.99)+j(-7.63)

EXPERIMENT -4
FORMULATION OF Y BUS BY SINGULAT TRANSFORMATION METHOD IN MATLAB

PROGRAM FOR FORMATION OF Y-BUS (SINGULAR TRANSFORMATION METHOD)


% Formation of Bus Admittance Matrix
%By using Singular Transformation Method
clc
n=5;
% No.Of Buses
nline=7;
% No.of Lines
ip=fopen('ybus.in','r+');
% Initializing the Input File
op=fopen('ybus.out','w+');
% Initializing the Output File..
a=fscanf(ip,'%g',[5 7]);
% Calling the Input data
b=transpose(a);
k=b(:,1);
% Elements
lp=b(:,2);
% From Bus
lq=b(:,3);
% To Bus
r=b(:,4);
% Line Resisitance
x=b(:,5);
% Line Reactance
fprintf(op,'Input Data for Formation of Y-Bus\n');
fprintf(op,'\tk\tlp(k)\tlq(k)\tr(k)\tx(k)\n'); % Printing input Data
for k=1:nline
fprintf(op,'\t%d\t\t%d\t\t%d\t\t%0.3f\t\t%0.3f',k,lp(k),lq(k),r(k),x(k));
fprintf(op,'\n');
end
primz=zeros(n,n);
% Initializing the Primitive Z matrix
for i=1:nline
primz(i,i)=complex(r(i),x(i)); % Diagonal Elements
end
primy=inv(primz);
% Printing Primitive Y Matrix
fprintf(op,'Primitive Y Matrix :\n');
for i=1:nline
for j=1:nline
fprintf(op,'(%0.3f)+j\t',real(primy(i,j)));
end
fprintf(op,'\n');
for j=1:nline
fprintf(op,'(%0.3f)\t',imag(primy(i,j)));
end
fprintf(op,'\n\n');
end
k=b(:,1);
% Elements
lp=b(:,2);
% From Bus
lq=b(:,3);
% To Bus
c=zeros(7,5);
% Bus Incidence Matrix
for i=1:nline
c(i,lp(i))=1;
c(i,lq(i))=-1;
end
fprintf(op,'Matrix for the Bus Incidence Matrix:(A)\n');
for i=1:7
for j=1:5
fprintf(op,'%3d\t',c(i,j));
end
fprintf(op,'\n');
end
d=transpose(c)*primy*c;
% Bus Admittance Matrix

fprintf(op,'Y Bus By Using Singular Transformation is: \n');


for i=1:5
for j=1:5
fprintf(op,'(%0.3f)+j\t',real(d(i,j)));
end
fprintf(op,'\n');
for j=1:5
fprintf(op,'(%0.3f)\t',imag(d(i,j)));
end
fprintf(op,'\n\n');
end
fclose all;

INPUT FOR FORMATION OF Y-BUS (SINGULAR TRANSFORMATION METHOD)


1
2
3
4
5
6
7

1
1
2
2
2
3
4

2
3
3
4
5
4
5

0.02
0.08
0.06
0.06
0.04
0.01
0.08

0.06
0.24
0.18
0.18
0.12
0.03
0.24

OUTPUT FOR FORMATION OF Y-BUS (SINGULAR TRANSFORMATION METHOD)


Input Data for Formation of Y-Bus
k
lp(k)
lq(k)
r(k)
x(k)
1
1
2
0.020
2
1
3
0.080
3
2
3
0.060
4
2
4
0.060
5
2
5
0.040
6
3
4
0.010
7
4
5
0.080

0.060
0.240
0.180
0.180
0.120
0.030
0.240

Primitive Y Matrix :
(5.000)+j
(-15.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(-0.000)+j
(0.000)

(0.000)+j
(0.000)

(1.250)+j
(-3.750)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(-0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(1.667)+j
(-5.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(-0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(1.667)+j
(-5.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(-0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(2.500)+j
(-7.500)

(0.000)+j
(0.000)

(-0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(10.000)+j
(-30.000)

(-0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(1.250)+j
(-3.750)

Matrix for the Bus Incidence Matrix:(A)


1 -1
0
0
0
1
0 -1
0
0
0
1 -1
0
0
0
1
0 -1
0
0
1
0
0 -1
0
0
1 -1
0
0
0
0
1 -1
Y Bus By Using Singular Transformation is:
(6.250)+j
(-18.750)

(-5.000)+j
(15.000)

(-1.250)+j
(3.750)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(-5.000)+j
(15.000)

(10.833)+j
(-32.500)

(-1.667)+j
(5.000)

(-1.667)+j
(5.000)

(-2.500)+j
(7.500)

(-1.250)+j
(3.750)

(-1.667)+j
(5.000)

(12.917)+j
(-38.750)

(-10.000)+j
(30.000)

(0.000)+j
(0.000)

(0.000)+j
(0.000)

(-1.667)+j
(5.000)

(-10.000)+j
(30.000)

(12.917)+j
(-38.750)

(-1.250)+j
(3.750)

(0.000)+j
(0.000)

(-2.500)+j
(7.500)

(0.000)+j
(0.000)

(-1.250)+j
(3.750)

(3.750)+j
(-11.250)

EXPERIMENT -5
FORMULATION OF Z BUS BY STEP BY STEP ALGORITHM IN MATLAB
PROGRAM FOR STEP BY STEP ALGORITHM
% FORMATION OF Z BUS BY BUS BUILDING ALGORITHM
ip=fopen('linedata.m','r');
M=fscanf(ip,'%g',[5,7]);
linedata=transpose(M)
nl=linedata(:,1);
nr=linedata(:,2);
R=linedata(:,3);
X=linedata(:,4);
ll=linedata(:,5);
nbr=length(nl);
nbus=max(max(nl),max(nr));
ZB=R+1j*X;
Zbus=zeros(nbus,nbus)
%Rule - 1
for I=1:nbr
if nl(I)==0 || nr(I)==0
if nl(I)==0
K=nr(I);
elseif nr(I)==0
K=nl(I);
end
Zbus(K,K)=ZB(I);
end
end
% rule -2
for J=1:nbr
if nl(J)>0 && nr(J) >0
if ll(J) == 0
Zbus(:,nr(J))=Zbus(:,nl(J));
Zbus(nr(J),:)=Zbus(nl(J),:);
Zbus(nr(J),nr(J))=Zbus(nr(J),nr(J))+ZB(J);
end
end
end
%Rule - 3
for J=1:nbr
if nl(J)>0 && nr(J) >0
if ll(J) ==1
delta_Z=Zbus(:,nr(J))-Zbus(:,nl(J));
Zll=ZB(J)+Zbus(nr(J),nr(J))+Zbus(nl(J),nl(J))-2*Zbus(nr(J),nl(J));
P=(delta_Z*(-delta_Z)')./Zll
Zbus=Zbus-P;
end
end
end
clc;

OUTPUT FOR STEP BY STEP ALGORITHM


Zbus =
0 + 0.0705i
0 + 0.0295i
0 + 0.0420i
0 + 0.0483i

0 + 0.0295i
0 + 0.0705i
0 + 0.0580i
0 + 0.0517i

0 + 0.0420i
0 + 0.0580i
0 + 0.2041i
0 + 0.1271i

0 + 0.0483i
0 + 0.0517i
0 + 0.1271i
0 + 0.1648i

EXPERIMENT -6
POWER FLOW SOLUTION USING GAUSS SEIDEL METHOD IN MATLAB

PROGRAM FOR LOAD FLOW SOLUTION BY USING GAUSS_SEIDEL METHOD


%Power Flow Solution Using Gauss Seidel
clc;
ip=fopen('linedata.ip','r+');
op=fopen('Gauss.out','w+');
M=fscanf(ip,'%g',[8,7]);
b=transpose(M);
k=b(:,1);
lp=b(:,2);
lq=b(:,3);
r=b(:,4);
% Resistance, R...
x=b(:,5);
% Reactance, X...
ycp=1i*b(:,6);
ycq=1i*b(:,7);
% Ground Admittance, B/2...
tap=b(:,8);
% Tap setting value..
Z=r+1i*x;
% z matrix...
yline=1./Z;
ysh=[0 0
0
0
0];
n=max(max(lp),max(lq));
% No. of buses...
nline=length(lp);
% No. of elements...
alpha=1.4;
epsilon=0.0001;
fprintf(op,'Number of Lines: %d \n',nline);
fprintf(op,'Number of Buses: %d \n',n);
fprintf(op,'Tolerance Value: %0.04f \n',epsilon);
fprintf(op,'\nLine Data is taken as:\n');
fprintf(op,'k\t\tLp\t\tLq\t\tR\t\tX\t\tYcp\t\tYcq\t\tTap\n');
for k=1:nline
fprintf(op,'%d\t\t%d\t\t%d\t\t%0.2f\t%0.2f\t%0.3f\t%0.3f\t%d',k,lp(k),lq(k),
r(k),x(k),imag(ycp(k)),imag(ycq(k)),tap(k));
fprintf(op,'\n');
end
fprintf(op,'\nYshunt is assumed as :\t\t');
fprintf(op,'%g \t',ysh);
in=fopen('busdata.in','r+');
N=fscanf(in,'%g',[7,5]);
a=transpose(N);
busno=a(:,1);
itype=a(:,2);
pu=100;
pload=a(:,3)/pu;
qload=a(:,4)/pu;
pgen=a(:,5)/pu;
qgen=a(:,6)/pu;
vsp=a(:,7);
fprintf(op,'\n\nBus Data is taken as: \n');
fprintf(op,'Bus No\tBus Type\tPgen\tQgen\tPLoad\tQload\tVoltage Specified\n');
for k=1:n
fprintf(op,'%d\t\t%d\t\t\t%0.2f\t%0.2f\t%0.2f\t%0.3f\t%0.3f\t%d',busno(k),it
ype(k),pgen(k),qgen(k),pload(k),qload(k),vsp(k));
fprintf(op,'\n');
end
ybus=zeros(n,n);

for i=1:nline
yline(i)=1/complex(r(i),x(i));
if tap(i)~=1;
t1=((1/(tap(i))^2)-(1/tap(i)));
t2=(1-(1/tap(i)));
ycp(i)=yline(i)*t1;
ycq(i)=yline(i)*t2;
yline(i)=yline(i)/tap(i);
end
end
for i=1:nline
p=lp(i);
q=lq(i);
ybus(p,p)=ybus(p,p)+yline(i)+ycp(i);
ybus(q,q)=ybus(q,q)+yline(i)+ycq(i);
ybus(p,q)=ybus(p,q)-yline(i);
ybus(q,p)=ybus(p,q);
end
for i=1:n
ybus(i,i)=ybus(i,i)+ysh(i);
end
fprintf(op,'\nY Bus is obtained by using Direct Inspection as : \n\n');
for i=1:n
for j=1:n
fprintf(op,'(%0.4f)+j\t',real(ybus(i,j)));
end
fprintf(op,'\n');
for j=1:n
fprintf(op,'(%0.4f)\t',imag(ybus(i,j)));
end
fprintf(op,'\n');
end
for i=1:n;
pinj(i)=pgen(i)-pload(i);
qinj(i)=qgen(i)-qload(i);
end
for i=1:n
Eold(i)=complex(vsp(i),0);
end
iter=0;
itermax=20;
delEmax=0;
nslack=1;
E=Eold;
foriter=1:itermax
for i=1:n
if i~=nslack
csum = complex(0,0);
for j=1:n
if j~=i
csum=csum+ybus(i,j)*E(j);
end
end
E(i)=(((complex(pinj(i),-qinj(i)))/(conj(E(i))))-csum)*(1/ybus(i,i));
deltaE(i)=E(i)-Eold(i);
E(i)=Eold(i)+alpha*deltaE(i);
Eold(i)=E(i);
if abs(deltaE(i))>delEmax
delEmax=abs(deltaE(i));

end
end
end
ifdelEmax<=epsilon
break
else
iter=iter+1;
delEmax=0;
end
end
for i=1:nline
P=lp(i);
Q=lq(i);
I1(i)=((E(P)-E(Q))*yline(i))+(ycp(i)*E(P));
S1(i)=E(P)*conj(I1(i));
P1(i)=real(S1(i));
Q1(i)=imag(S1(i));
end
for i=1:nline
P=lp(i);
Q=lq(i);
I2(i)=((E(Q)-E(P))*yline(i))+(ycq(i)*E(Q));
S2(i)=E(Q)*conj(I2(i));
P2(i)=real(S2(i));
Q2(i)=imag(S2(i));
end
for i=1:nline
Ploss(i)=P1(i)+P2(i);
Qloss(i)=Q1(i)+Q2(i);
end
pgen(nslack)=P1(1)+P1(2);
qgen(nslack)=Q1(1)+Q1(2);
for i=1
Pgen(i)=pgen(nslack)+Ploss(i);
Qgen(i)=qgen(nslack)+Qloss(i);
end
tploss=sum(Ploss);
tqloss=sum(Qloss);
bvs=abs(E);
degE=angle(E)/pi*180;
ps=pgen(nslack);
qs=qgen(nslack);
pl=sum(pload);
ql=sum(qload);
tpg=pl+tploss;
tqg=ql+tqloss;
fprintf(op,'\nThePowerflow is Converged at Iteration : %d',iter);
fprintf(op,'\n\nPower Flow Solution is Obtained as:\n');
fprintf(op,'Bus No\tBus Type\t Generation\tLoad Demand\t\tBus Voltages
Solved\n');
fprintf(op,'\t\t\t\t\tReal\tReac\tReal\tReac\t Mag\tAngle(Deg)');
fprintf(op,'\n');
for i=1:n
fprintf(op,'%d\t\t\t%d\t\t%0.4f\t%0.4f\t%0.2f\t%0.2f\t%0.4f\t%0.4f',busno(i)
,itype(i),pgen(i),qgen(i),pload(i),qload(i),bvs(i),degE(i));
fprintf(op,'\n');
end
fprintf(op,'\nLine Flow Solution is Obtained as: \n');
fprintf(op,'From Bus\tTo Bus\tPLoss\t\tQLoss\t\tTotalPLoss\t\tTotalQLoss');

fprintf(op,'\n');
for i=1:nline
fprintf(op,'%d\t\t\t%d\t\t%0.4f\t\t%0.4f',lp(i),lq(i),P1(i),Q1(i));
fprintf(op,'\n');
ploss(i)=P1(i)+P2(i);
qloss(i)=Q1(i)+Q2(i);
fprintf(op,'%d\t\t\t%d\t\t%0.4f\t\t%0.4f\t\t%0.4f\t\t\t%0.4f',lp(i),lq(i),P2
(i),Q2(i),ploss(i),qloss(i));
fprintf(op,'\n');
end
fprintf(op,'\nTotal Line Loss is calculated as : (%f)+j(%f)',tploss,tqloss);
fprintf(op,'\nTotal Load is calculated as : (%f)+j(%f)',pl,ql);
fprintf(op,'\nSlack Bus Generation is calculated as : (%f)+j(%f)',ps,qs);
fprintf(op,'\nTotal Generation Required is : (%f)+j(%f)',tpg,tqg);
fclose all;

INPUT FOR LINE DATA


1
2
3
4
5
6
7

1
1
2
2
2
3
4

2
3
3
4
5
4
5

0.02
0.08
0.06
0.06
0.04
0.01
0.08

0.06
0.24
0.18
0.18
0.12
0.03
0.24

0.030
0.025
0.020
0.020
0.015
0.010
0.025

0.030
0.025
0.020
0.020
0.015
0.010
0.025

1
1
1
1
1
1
1

INPUT FOR BUS DATA


1
2
3
4
5

1
1
2
2
2

0
20
45
40
60

0
10
15
5
10

0
40
0
0
0

0
30
0
0
0

1.06
1
1
1
1

OUTPUT IS OBTAINED AS
Number of Lines: 7
Number of Buses: 5
Tolerance Value: 0.0001
Line Data is taken as:
kLpLq
R
X
1
1
2
2
1
3
3
2
3
4
2
4
5
2
5
6
3
4
7
4
5
Yshunt is assumed as :

YcpYcq
0.02
0.06
0.08
0.24
0.06
0.18
0.06
0.18
0.04
0.12
0.01
0.03
0.08
0.24
0

Tap
0.030
0.025
0.020
0.020
0.015
0.010
0.025
0

0.030
0.025
0.020
0.020
0.015
0.010
0.025

1
1
1
1
1
1
1

Bus Data is taken as:


Bus No Bus Type
PgenQgenPLoadQload
Voltage Specified
1
1
0.00
0.00
0.00
0.000
1.060
2
1
0.40
0.30
0.20
0.100
1.000
3
2
0.00
0.00
0.45
0.150
1.000

4
5

2
2

0.00
0.00

0.00
0.00

0.40
0.60

0.050
0.100

1.000
1.000

Y Bus is obtained by using Direct Inspection as :


(6.2500)+j
(-18.6950)
(-5.0000)+j
(15.0000)
(-1.2500)+j
(3.7500)
(0.0000)+j
(0.0000)
(0.0000)+j
(0.0000)

(-5.0000)+j
(15.0000)
(10.8333)+j
(-32.4150)
(-1.6667)+j
(5.0000)
(-1.6667)+j
(5.0000)
(-2.5000)+j
(7.5000)

(-1.2500)+j
(3.7500)
(-1.6667)+j
(5.0000)
(12.9167)+j
(-38.6950)
(-10.0000)+j
(30.0000)
(0.0000)+j
(0.0000)

(0.0000)+j
(0.0000)
(-1.6667)+j
(5.0000)
(-10.0000)+j
(30.0000)
(12.9167)+j
(-38.6950)
(-1.2500)+j
(3.7500)

(0.0000)+j
(0.0000)
(-2.5000)+j
(7.5000)
(0.0000)+j
(0.0000)
(-1.2500)+j
(3.7500)
(3.7500)+j
(-11.2100)

The Powerflow is Converged at Iteration : 10


Power Flow Solution is Obtained as:
Bus No Bus Type
Generation
Real
Reac
1
1
1.2952 -0.0756
2
1
0.4000 0.3000
3
2
0.0000 0.0000
4
2
0.0000 0.0000
5
2
0.0000 0.0000

Load Demand
Real
Reac
0.00
0.00
0.20
0.10
0.45
0.15
0.40
0.05
0.60
0.10

Line Flow Solution is Obtained as:


From Bus
To Bus PLossQLoss
Total PLoss
1
2
0.8882
-0.0868
1
2
-0.8741
0.0625
0.0141
1
3
0.4070
0.0113
1
3
-0.3951
-0.0299
0.0119
2
3
0.2467
0.0354
2
3
-0.2432
-0.0678
0.0035
2
4
0.2793
0.0296
2
4
-0.2748
-0.0593
0.0044
2
5
0.5482
0.0736
2
5
-0.5370
-0.0719
0.0113
3
4
0.1893
-0.0516
3
4
-0.1889
0.0317
0.0004
4
5
0.0634
-0.0228
4
5
-0.0631
-0.0284
0.0003

Total
Total
Slack
Total

Line Loss is calculated as :


Load is calculated as :
Bus Generation is calculated as :
Generation Required is :

Bus Voltages Solved


Mag
Angle(Deg)
1.0600 0.0000
1.0475 -2.8060
1.0243 -4.9946
1.0236 -5.3274
1.0180 -6.1491

Total QLoss
-0.0243
-0.0186
-0.0324
-0.0297
0.0018
-0.0199
-0.0512

(0.045832)+j(-0.174353)
(1.650000)+j(0.400000)
(1.295189)+j(-0.075588)
(1.695832)+j(0.225647)

EXPERIMENT -7
SIMULATION OF TRANSMISSION LINE PERFORMANCE USING MATLAB

PROBLEM -1
A 500KV VOLTAGE A 3- Tr.Line is 250KM. The series impedance is
Z=(0.045+j0.4)/Ph/KM. The Shunt admittance is Y=j4*10 -6 .Evaluate Equivalent model &
trans mission network.
Program for Problem-1
clc
z=0.045+1i*0.4;
y=1i*4/1000000;
l=250;
op=fopen('trans.out','w+');
gamma=sqrt(z*y);
zc=sqrt(z/y);
a=cosh(gamma*l);
b=zc*sinh(gamma*l);
c=(1/zc)*sinh(gamma*l);
d=a;
abcd=[a b;c d];
Z=b;
Y=(2/zc)*tanh(gamma*(l/2));
fprintf(op,'SeriesImpedence z=(%f)+j(%f)\nShunt Admittance
y=(%f)+j(%f)\nGamma=(%f)+j(%f)\nCharacteristicImpedence
Zc=(%f)+j(%f)\nA=(%f)+j(%f)\nB=(%f)+j(%f)\nC=(%f)+j(%f)\nD=(%f)+j(%f)\nPI
Parameter Z=(%f)+j(%f)\nPI Parameter
Y=(%f)+j(%f)\n',real(z),imag(z),real(y),imag(y),real(gamma),imag(gamma),real(zc),i
mag(zc),real(a),imag(a),real(b),imag(b),real(c),imag(c),real(d),imag(d),real(Z),im
ag(Z),real(Y),imag(Y));
fclose all;

Output for problem -1


Series Impedence z=(0.045000)+j(0.400000)
Shunt Admittance y=(0.000000)+j(0.000004)
Gamma=(0.000071)+j(0.001267)
Characteristic ImpedenceZc=(316.726083)+j(-17.759826)
A=(0.950410)+j(0.005532)
B=(10.877792)+j(98.362426)
C=(-0.000002)+j(0.000983)
D=(0.950410)+j(0.005532)
PI Parameter Z=(10.877792)+j(98.362426)
PI Parameter Y=(0.000001)+j(0.001008)

PROBLEM -2
A 3-, 60 Hz 500 KV Tr.Line is 300KM. The parameters per phase/unit are found to be
R=(0.016)/KM, L=(0.97)mH/KM, C=(0.05)F/KM..Determine the ohase constants . Surge
Impedance (Zc), Velocity of propagation () and line wave length().
Program for Problem-2
clc
l=input('\n Enter the Length of Transmission Line in KM:');
r=input('\n Enter the Resistance in Ohm/KM:');
L=input('\n Enter the Inductance value in H/KM:');
C=input('\n Enter the Capacitance value in F/KM:');
f=60;
w=2*pi*f;
beta=w*sqrt(L*C);
zc=sqrt(L/C);
velocity=1/sqrt(L*C);
lamda=velocity/f;
fprintf('\n Velocity of Propogation in KM/s:(%f)\n',velocity);
fprintf('\n Line Wavelength in KM is:(%f)\n',lamda);
fprintf('\n Phase Constant Beta is:(%f)\n',beta);
fprintf('\n Surge Impedance Zc is:(%f)\n',zc);
fclose all;

Output for problem -2


Enter the Length of Transmission Line in KM:300
Enter the Resistance in Ohm/KM:0.016
Enter the Inductance value in H/KM:0.97e-3
Enter the Capacitance value in F/KM:0.0115e-6
Velocity of Propogation in KM/s:(299409.249523)
Line Wavelength in KM is:(4990.154159)
Phase Constant Beta is:(0.001259)
Surge Impedance Zc is:(290.426972)

PROBLEM -3
Determine the pe rformance of 500KV transmission line, when the load at receiving end is
800MW @ 0.8 p.f lagging. Remaining all other parameters are same as problem -2
Program for Problem-3
clc
vr=input('\n Enter the Receiving End Line Voltage in KV:');
vrph=vr/sqrt(3);
load=input('\n Enter Load in MW:');
pf=input('\n Enter Power Factor:');
theta=acos(pf);
loadinmva=load/pf;
sr=load+(1i*loadinmva *sin(theta));
l=input('\n Enter the Length of Transmission Line:');
r=input('\n Enter the Resistance in Ohm/KM:');
L=input('\n Enter the Inductance Value in H/KM:');
C=input('\n Enter the Capacitance in F/KM:');
G=input('\n Enter the Conductance in Mho/KM:');
f=60;
w=2*pi*f;
beta=w*sqrt(L*C);
z=(r+1i*w*L);
y=(G+1i*w*C);
g=sqrt(z*y);
zc=sqrt(z/y);
a=cosh(g*l);
b=zc*sinh(g*l);
c=sinh(g*l)/zc;
d=cosh(g*l);
format long;
abcd=[a b;c d];
ir=(conj(sr)*(1000)/(3*vrph));
abs(ir);
angle((ir)*(180/pi));
vsis=abcd*[vrph*1000;ir];
vs=abs(vsis(1)*sqrt(3));
is=abs(vsis(2)*sqrt(3));
thetav =angle(vsis(1));
thetai=angle(vsis(2));
ps=vs*is*cos(thetav-thetai)/1000000;
qs=vs*is*sin(thetav-thetai)/1000000;
reg=(((vs/(cos(beta*l)*sqrt(3)))-(vrph*1000))/(vrph*1000))*100;
abs(reg);
efficency=(load/ps)*100;
fprintf('\n Voltage Regulation is:(%f)\n',abs(reg));
fprintf('\n Efficency is:(%f)\n',efficency);
fprintf('\n Sending End Voltage is:(%f)\n',vs);
fprintf('\n Sending End Current is:(%f)\n',is);
fprintf('\n Sending End Active Power is:(%f)\n',ps);
fprintf('\n sending End Reactive Power is:(%f)\n',qs);
fclose all;

Output for problem -3


Enter the Receiving End Line Voltage in KV:500
Enter Load in MW:800
Enter Power Factor:0.8
Enter the Length of Transmission Line:300
Enter the Resistance in Ohm/KM:0.016
Enter the Inductance Value in H/KM:0.97e-3
Enter the Capacitance in F/KM:0.0115e-6
Enter the Conductance in Mho/KM:0
Voltage Regulation is:(34.160145)
Efficency is:(98.110843)
Sending End Voltage is:(623510.889701)
Sending End Current is:(1564.237090)
Sending End Active Power is:(815.404265)
sending End Reactive Power is:(535.128735)

EXPERIMENT -8
SHORT CIRCUIT STUDIES USING MATLAB

PROGRAM FOR SHORT CIRCUIT STUDIES USING MATLAB


% Fault analysis for LG, LL and LLG faults
clc;
bmva=input('Enter Base MVA:');
bv=input('Enter Base Voltage in KV:');
bc=(bmva*1000)/(1.732*bv);
fprintf(' The Base current: %d Amps', bc);
E=1.0;
z1=input('\n Enter Positive Sequence Impedance Z1:');
z2=input('Enter Negative Sequence Impedance Z2:');
z0=input('Enter Zero Sequence Impedance Z0:');
zf=0;
Ia1= E / (z1+z2+z0+(3*zf));
Ia2=Ia1;
Ia0=Ia1;
If_pu= 3*Ia1;
Fault_curent_for_LG_Fault=If_pu*bc
% calcuation of sequence voltages
va1=E-(Ia1*z1);
va2=-(Ia2*z2);
va0=-(Ia0*z0);
%calculation of line to neutral voltages
a=-0.5+0.866i;
va=va0+va1+va2;
vb=va0+(a*a*va1)+(a*va2);
vc=va0+(a*va1)+(a*a*va2);
Line_to_Line_Voltages_in_kV_for_LG_Fault=[((va-vb)*(bv/1.732))
vc)*(bv/1.732))
((vc-va)*(bv/1.732))]
% L-L fault calculations
Ia1_LL= E/(z1+z2+zf);
Ia2_LL=-Ia1_LL;
% line currents for LL fault
Ia_LL=0;
Ib_LL=(-1.732)*j*Ia1_LL;
Ic_LL=-Ib_LL;
Fault_curent_in_Amps_for_LL_Fault=[Ia_LL*bcIb_LL*bcIc_LL*bc]
% calcution of sequence voltages
va1_LL=E-(Ia1_LL*z1);
va2_LL=va1_LL;
va0_LL=0;
%calculation of line to neutral voltages
va_LL=va0_LL+va1_LL+va2_LL;
vb_LL=va0_LL+(a*a*va1_LL)+(a*va2_LL);
vc_LL=va0_LL+(a*va1_LL)+(a*a*va2_LL);
Line_to_neutral_Voltages_in_kV_for_LL_Fault=[(va_LL*bv)/1.732
(vc_LL*bv)/1.732]
% LLG fault calcutions
x1=(z0+(3*zf))/(z2+z0+(3*zf));
Ia1_LLG=E/(z1+(z2*x1));
Ia2_LLG=(-Ia1_LLG)* (z0/(z0+z2));
Ia0_LLG=(-Ia1_LLG)* (z2/(z0+z2));
%line currents in pu
Ia_LLG=Ia0_LLG+Ia1_LLG+Ia2_LLG;

((vb-

(vb_LL*bv)/1.732

Ib_LLG=Ia0_LLG+(a*a*Ia1_LLG)+(a*Ia2_LLG);
Ic_LLG=Ia0_LLG+(a*Ia1_LLG)+(a*a*Ia2_LLG);
% actual line currents
Fault_curent_in_Amps_for_LLG_Fault=[Ia_LLG*bcIb_LLG*bcIc_LLG*bc]
%sequence voltages
va1_LLG=(E-(Ia1_LLG*z1));
va2_LLG=va1_LLG;
va0_LLG=va1_LLG;
%calculation of line to neutral voltages in pu.
va_LLG=va0_LLG+va1_LLG+va2_LLG;
vb_LLG=va0_LLG+(a*a*va1_LLG)+(a*va2_LLG);
vc_LLG=va0_LLG+(a*va1_LLG)+(a*a*va2_LLG);
Line_to_neutral_Voltages_in_kV_for_LLG_Fault=[(va_LLG*bv)/1.732
(vb_LLG*bv)/1.732
(vc_LLG*bv)/1.732]

OUTPUT FOR SHORT CIRCUIT STUDIES


Enter Base MVA:30
Enter Base Voltage in KV:13.8
The Base current: 1.255146e+003 Amps
Enter Positive Sequence Impedance Z1:0+0.25i
Enter Negative Sequence Impedance Z2:0+0.35i
Enter Zero Sequence Impedance Z0:0+0.10i
Fault_curent_for_LG_Fault =
0 -5.3792e+003i
Line_to_Line_Voltages_in_kV_for_LG_Fault =
1.7071 + 7.8857i

0.0004 -15.7714i

-1.7075 + 7.8857i

Fault_curent_in_Amps_for_LL_Fault =
1.0e+003 *
0

-3.6232

3.6232

Line_to_neutral_Voltages_in_kV_for_LL_Fault =
9.2956

-4.6476

-4.6476

Fault_curent_in_Amps_for_LLG_Fault =
1.0e+003 *
0 + 0.0000i

-4.0531 + 4.4673i

4.0531 + 4.4675i

Line_to_neutral_Voltages_in_kV_for_LLG_Fault =
5.6719

0.0001

0.0001

EXPERIMENT -8
DETERMINATION OF CRITICAL CLEARING TIME AND SWING CURVE USING MATLAB
PROGRAM FOR DETERMINATION OF CRITICAL CLEARING TIME AND SWING CURVE USING MATLAB
clc;
clear all;
pm=1;
H=5;
f=60;
x1=input('\n Enter the value of Generator Reactance:');
x2=input('\n Enter the value of Tr.Line-1 Reactance:');
x3=input('\n Enter the value of Tr.Line-2 Reactance:');
x4=input('\n Enter the value of Load Reactance:');
E=input('\n Enter the value of Generator Voltage in (P.U):');
V=1;
fprintf('\n During the Pre-Fault Condition:');
x5=(x2*x3)/(x2+x3);
X=x1+x5+x4
pmax1=(E*V)/X
pe1=pm
delta=asin(pe1/pmax1)
fprintf('\n During Fault Condition:');
pe2=0
pmax2=0
fprintf('\n Post Fault Condition');
x23=x1+x2+x4
pmax3=(E*V)/x23
deltamax=pi-asin(pm/pmax3)
pe3=pmax3*sin(deltamax)
fprintf('\n Critical Clearing angle:');
deltacr=acos(((pm*(deltamax-delta))(pmax2*cos(delta))+(pmax3*cos(deltamax)))/(pmax3-pmax2))
fprintf('\n Clearing Time:');
tcr=sqrt((2*H*(deltacr-delta))/(pi*f*pm))
fclose all;

OUTPUT FOR CRITICAL CLEARING TIME AND SWINF CURVE


Enter the value of Generator Reactance:

0.25

Enter the value of Tr.Line-1 Reactance:

0.5

Enter the value of Tr.Line-2 Reactance:

0.4

Enter the value of Load Reactance:

0.05

Enter the value of Generator Voltage in (P.U): 1.2


During the Pre-Fault Condition:
X=

0.5222

pmax1 =

2.2979

pe1 =

delta =

0.4502

During Fault Condition:


pe2 =

pmax2 =

Post Fault Condition


x23 =

0.8000

pmax3 =

1.5000

deltamax =

2.4119

pe3 =

1.0000

Critical Clearing angle:


deltacr =

0.9735

Clearing Time:
tcr =

0.1666

EXPERIMENT -10
SIMULATION OF ROTOR ANGLE STABILITY USING MATLAB

INPUT FOR ROTOR ANGLE STABILITY IN SIMULINK


K1=1.4479;
K2=1.3174;
K3=0.3072;
K4=1.8052;
K5=0.0294;
K6=0.52557;
td=5.9;
Ke=-0.17;
te=0.95;
Ka=400;
Kr=1;
tr=0.1;
Kf=0.04;
tf=1;
ta=0.05;
Wr=1;
hs=2.37;
D=2;
t0=10;
t1=0.5;
t2=0.05;

SIMULINK DIAGRAM FOR ROTOR ANGLE STABILITY

OUT PUT FOR ROTOR ANGLE STABILITY

SUBSYSTEM 1

SUB SYSTEM -2

EXPERIMENT -11
LOAD FLOW BY NR METHOD USING MATLAB

PROGRAM FOR BUS DATA


% 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 |
busdat14 = [1
1
1.060
0
0
0
0
0
2
2
1.045
0
40
42.4 21.7
12.7
3
2
1.010
0
0
23.4 94.2
19.0
4
3
1.0
0
0
0
47.8
-3.9
5
3
1.0
0
0
0
7.6
1.6
6
2
1.070
0
0
12.2 11.2
7.5
7
3
1.0
0
0
0
0.0
0.0
8
2
1.090
0
0
17.4
0.0
0.0
9
3
1.0
0
0
0
29.5
16.6
10
3
1.0
0
0
0
9.0
5.8
11
3
1.0
0
0
0
3.5
1.8
12
3
1.0
0
0
0
6.1
1.6
13
3
1.0
0
0
0
13.5
5.8
14
3
1.0
0
0
0
14.9
5.0

Qmin | Qmax |
0
0;
-40
50;
0
40;
0
0;
0
0;
-6
24;
0
0;
-6
24;
0
0;
0
0;
0
0;
0
0;
0
0;
0
0;];

switch num
case 14
busdt = busdat14;
end

PROGRAM FOR LINE DATA


% Returns Line datas of the system...
function linedt = linedatas(num)
%
| From | To
%
| Bus | Bus
linedat14 = [1
2
1
5
2
3
2
4
2
5
3
4
4
5
4
7
4
9
5
6
6
11
6
12
6
13

|
|

R
|
X
|
pu
| pu
|
0.01938
0.05917
0.05403
0.22304
0.04699
0.19797
0.05811
0.17632
0.05695
0.17388
0.06701
0.17103
0.01335
0.04211
0.0
0.20912
0.0
0.55618
0.0
0.25202
0.09498
0.19890
0.12291
0.25581
0.06615
0.13027

B/2
pu
0.0264
0.0246
0.0219
0.0170
0.0173
0.0064
0.0
0.0
0.0
0.0
0.0
0.0
0.0

| X'mer |
| TAP (a) |
1
1
1
1
1
1
1
0.978
0.969
0.932
1
1
1

7
7
9
9
10
12
13

8
9
10
14
11
13
14

0.0
0.0
0.03181
0.12711
0.08205
0.22092
0.17093

0.17615
0.11001
0.08450
0.27038
0.19207
0.19988
0.34802

0.0
0.0
0.0
0.0
0.0
0.0
0.0

1
1
1
1
1
1
1 ];

switch num
case 14
linedt = linedat14;
end

PROGRAM FOR FORMATION OF YBUS


% Program to for Admittance And Impedance Bus Formation....
function Y = ybusppg(num)

% Returns Y

linedata = linedatas(num);
fb = linedata(:,1);
tb = linedata(:,2);
r = linedata(:,3);
x = linedata(:,4);
b = linedata(:,5);
a = linedata(:,6);
z = r + i*x;
y = 1./z;
b = i*b;

%
%
%
%
%
%
%
%
%
%

Calling Linedatas...
From bus number...
To bus number...
Resistance, R...
Reactance, X...
Ground Admittance, B/2...
Tap setting value..
z matrix...
To get inverse of each element...
Make B imaginary...

nb = max(max(fb),max(tb));
nl = length(fb);
Y = zeros(nb,nb);

% No. of buses...
% No. of branches...
% InitialiseYBus...

% 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);
elseiftb(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

PROGRAM FOR CONVERSION OF POLAR TO RECTANGLE


%
%
%
%
%

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 INJECTION AND LINE AND POWER FLOWS
% Program for Bus Power Injections, Line & Power flows (p.u)...
function [Pi Qi PgQg Pl Ql] = loadflow(nb,V,del,BMva)
Y = ybusppg(nb);
lined = linedatas(nb);
busd = busdatas(nb);
Vm = pol2rect(V,del);
Del = 180/pi*del;
fb = lined(:,1);
tb = lined(:,2);
nl = length(fb);
Pl = busd(:,7);
Ql = busd(:,8);

%
%
%
%
%
%
%
%
%
%

Calling Ybus program..


Get linedats..
Get busdatas..
Converting polar to rectangular..
Bus Voltage Angles in Degree...
From bus number...
To bus number...
No. of Branches..
PLi..
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 RaphsonLoadflow 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('############################################################################
#########');

PROGRAM FOR NEWTON RAPHSON LOAD FLOW ANALYSIS


% Program for Newton-Raphson Load Flow Analysis..
nbus = 14;
Y = ybusppg(nbus);
busd = busdatas(nbus);
BMva = 100;
bus = busd(:,1);
type = busd(:,2);
V = busd(:,3);
del = busd(:,4);
Pg = busd(:,5)/BMva;
Qg = busd(:,6)/BMva;
Pl = busd(:,7)/BMva;
Ql = busd(:,8)/BMva;
Qmin = busd(:,9)/BMva;
Qmax = busd(:,10)/BMva;
P = Pg - Pl;
Q = Qg - Ql;
Psp = P;
Qsp = Q;
G = real(Y);
B = imag(Y);

%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%

IEEE-14, IEEE-30, IEEE-57..


Calling ybusppg.m to get Y-Bus Matrix..
Calling busdatas..
Base MVA..
Bus Number..
Type of Bus 1-Slack, 2-PV, 3-PQ..
Specified Voltage..
Voltage Angle..
PGi..
QGi..
PLi..
QLi..
Minimum Reactive Power Limit..
Maximum Reactive Power Limit..
Pi = PGi - PLi..
Qi = QGi - QLi..
P Specified..
Q Specified..
Conductance matrix..
Susceptance matrix..

pv = find(type == 2 | type == 1);


pq = find(type == 3);
npv = length(pv);
npq = length(pq);
Tol = 1;
Iter = 1;
while (Tol> 1e-5)

%
%
%
%

PV Buses..
PQ Buses..
No. of PV buses..
No. of PQ buses..

% 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];
X = inv(J)*M;
dTh = X(1:nbus-1);
dV = X(nbus:end);

% Jacobian Matrix..
% Correction Vector
% Change in Voltage Angle..
% 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);
k = k+1;
end
end
Iter = Iter + 1;
Tol = max(abs(M));
end
loadflow(nbus,V,del,BMva);

% Voltage Magnitude..

% Tolerance..

% Calling Loadflow.m..

OUTPUT FOR NEWTON RAPHSON LOAD FLOW ANALYSIS


#############################################################################################
-------------------------------------------------------------------------------------------------------------------------------------------------------Newton RaphsonLoadflow Analysis
-------------------------------------------------------------------------------------------------------------------------------------------------------| Bus
| V
| Angle
|
Injection
|
Generation
|
Load |
| No
| pu
| Degr ee | MW
| MVar
| MW
| Mvar
| MW
| MVar|
-------------------------------------------------------------------------------------------------------------------------------------------------------1
1.0600 0.0000
232.593 -15.233
232.593
-15.233
0.000
0.000
-------------------------------------------------------------------------------------------------------------------------------------------------------2
1.0450 -4.9891
18.300
35.228
40.000
47.928
21.700
12.700
-------------------------------------------------------------------------------------------------------------------------------------------------------3
1.0100 -12.7492
-94.200 8.758
0.000
27.758
94.200
19.000
-------------------------------------------------------------------------------------------------------------------------------------------------------4
1.0132 -10.2420
-47.800 3.900
0.000
-0.000
47.800
-3.900
-------------------------------------------------------------------------------------------------------------------------------------------------------5
1.0166 -8.7601
-7.600
-1.600
-0.000
-0.000
7.600
1.600
-------------------------------------------------------------------------------------------------------------------------------------------------------6
1.0700 -14.4469
-11.200 15.526
-0.000
23.026
11.200
7.500
-------------------------------------------------------------------------------------------------------------------------------------------------------7
1.0457 -13.2368
-0.000
0.000
-0.000
0.000
0.000
0.000
-------------------------------------------------------------------------------------------------------------------------------------------------------8
1.0800 -13.2368
0.000
21.030
0.000
21.030
0.000
0.000
-------------------------------------------------------------------------------------------------------------------------------------------------------9
1.0305 -14.8201
-29.500 -16.600
0.000
-0.000
29.500
16.600
-------------------------------------------------------------------------------------------------------------------------------------------------------10
1.0299 -15.0360
-9.000
-5.800
-0.000
0.000
9.000
5.800
-------------------------------------------------------------------------------------------------------------------------------------------------------11
1.0461 -14.8581
-3.500
-1.800
0.000
0.000
3.500
1.800
-------------------------------------------------------------------------------------------------------------------------------------------------------12
1.0533 -15.2973
-6.100
-1.600
0.000
0.000
6.100
1.600
-------------------------------------------------------------------------------------------------------------------------------------------------------13
1.0466 -15.3313
-13.500 -5.800
0.000
0.000
13.500
5.800
-------------------------------------------------------------------------------------------------------------------------------------------------------14
1.0193 -16.0717
-14.900 -5.000
-0.000
0.000
14.900
5.000
-------------------------------------------------------------------------------------------------------------------------------------------------------Total
13.593
31.009
272.593
104.509
259.000
73.500
-------------------------------------------------------------------------------------------------------------------------------------------------------#############################################################################################
-------------------------------------------------------------------------------------------------------------------------------------------------------Line FLow and Losses

-------------------------------------------------------------------------------------------------------------------------------------------------------| From | To |
P
| Q
| From | To
| P
| Q
| Line Loss
|
|Bus
|Bus
| MW
| MVar | Bus
| Bus
| MW
| MVar
| MW
| MVar
|
-------------------------------------------------------------------------------------------------------------------------------------------------------1
2
157.080 -17.484
2
1
-152.772
30.639
4.309
13.155
-------------------------------------------------------------------------------------------------------------------------------------------------------1
5
75.513
7.981
5
1
-72.740
3.464
2.773
11.445
-------------------------------------------------------------------------------------------------------------------------------------------------------2
3
73.396
5.936
3
2
-71.063
3.894
2.333
9.830
-------------------------------------------------------------------------------------------------------------------------------------------------------2
4
55.943
2.935
4
2
-54.273
2.132
1.670
5.067
-------------------------------------------------------------------------------------------------------------------------------------------------------2
5
41.733
4.738
5
2
-40.813
-1.929
0.920
2.809
-------------------------------------------------------------------------------------------------------------------------------------------------------3
4
-23.137 7.752
4
3
23.528
-6.753
0.391
0.998
-------------------------------------------------------------------------------------------------------------------------------------------------------4
5
-59.585 11.574
5
4
60.064
-10.063
0.479
1.511
-------------------------------------------------------------------------------------------------------------------------------------------------------4
7
27.066
-15.396
7
4
-27.066
17.327
0.000
1.932
----------------------------------------------------------------------------------------------------------------------------------------- --------------4
9
15.464
-2.640
9
4
-15.464
3.932
-0.000
1.292
----------------------------------------------------------------------------------------------------------------------------------------------------- --5
6
45.889
-20.843
6
5
-45.889
26.617
0.000
5.774
-------------------------------------------------------------------------------------------------------------------------------------------------------6
11
8.287
8.898
11
6
-8.165
-8.641
0.123
0.257
-------------------------------------------------------------------------------------------------------------------------------------------------------6
12
8.064
3.176
12
6
-7.984
-3.008
0.081
0.168
-------------------------------------------------------------------------------------------------------------------------------------------------------6
13
18.337
9.981
13
6
-18.085
-9.485
0.252
0.496
-------------------------------------------------------------------------------------------------------------------------------------------------------7
8
-0.000
-20.362
8
7
0.000
21.030
0.000
0.668
-------------------------------------------------------------------------------------------------------------------------------------------------------7
9
27.066
14.798
9
7
-27.066
-13.840
-0.000
0.957
------------------------------------------------------------------------------------------------------------------------------------------------------9
10
4.393
-0.904
10
9
-4.387
0.920
0.006
0.016
-------------------------------------------------------------------------------------------------------------------------------------------------------9
14
8.637
0.321
14
9
-8.547
-0.131
0.089
0.190
-------------------------------------------------------------------------------------------------------------------------------------------------------10
11
-4.613
-6.720
11
10
4.665
6.841
0.051
0.120
-------------------------------------------------------------------------------------------------------------------------------------------------------12
13
1.884
1.408
13
12
-1.873
-1.398
0.011
0.010
-------------------------------------------------------------------------------------------------------------------------------------------------------13
14
6.458
5.083
14
13
-6.353
-4.869
0.105
0.215
-------------------------------------------------------------------------------------------------------------------------------------------------------Total Loss
13.593
56.910
-------------------------------------------------------------------------------------------------------------------------------------------------------#############################################################################################

You might also like