You are on page 1of 28

PROGRAM FOR MEDIUM TRANSMISSION LINE:

r=input('enter the resistance');


x=input('enter the inductive reactance');
c=input('enter the shunt capacitance');
l=input('enter the length of tx.');
vr=input('enter the receiving end voltage');
pr=input('enter the receiving end power');
pfr=input('ener the receiving end pf:');
vr1=vr/(3^(1/2))
ir=pr/(3*vr1*pfr)
anr=acosd(pfr)
ir1=ir*(cosd(anr)-1i*sind(anr))
y1=1i*l*6.28*50*c
z1=(r+1i*x)*l
a1=1+(y1*(z1/2))
d1=a1
c1=y1
b1=z1+(y1*z1*z1/4)
vs=(a1*vr1)+(b1*ir1)
is1=(c1*vr1)+(d1*ir1)
vs1=abs((3^(1/2))*vs)
vor=(abs(vs/a1)-abs(vr1))*100/abs(vr1)
pfs=cos(angle(vs)-angle(is1))
eff=((abs(vr1*ir*pfr))*100)/abs(vs*is1*pfs)

OUTPUT:

enter the resistance:0.124


enter the inductive reactance:0.00158
enter the shunt capacitance:0.01053*10^(-6)
enter the length of tx.:200
enter the receiving end voltage:1.732*127.07*1000
enter the receiving end power:40*10^6
ener the receiving end pf:0.85
vr1 = 1.2707e+005
ir =123.4496
anr = 31.7883
ir1 = 1.0493e+002 -6.5031e+001i
y1 = 0 +6.6128e-004i
z1 =24.8000 + 0.3160i
a1 = 0.9999 + 0.0082i
d1 = 0.9999 + 0.0082i
c1 = 0 +6.6128e-004i
b1 = 24.7974 + 0.4177i
vs =1.2968e+005 -5.2684e+002i
is1 =1.0545e+002 +1.9863e+001i
vs1 = 2.2462e+005
vor = 2.0668
pfs = 0.9820
eff = 97.5722

PROGRAM FOR LONG TRANSMISSION LINE:


r=input('enter the resistance');
x=input('enter the inductive reactance');
c=input('enter the shunt capacitance');
f=input('enter the frequency');
l=input('enter the length of tx.');
vr=input('enter the receciving end voltage');
pr=input('enter the reciving end power:');
pfr=input('enter the reciving end pf:');
vr1=vr/(3^(1/2))
Ir=pr/(3*vr1*pfr)
ANr=acosd(pfr)
Ir1=Ir*(cosd(ANr)-1i*sind(ANr))
y1=1i*6.28*f*c
z1=(r+1i*x)*l
A1=1+((y1*z1)/2)+((y1*y1*z1*z1)/24)
D1=A1
B1=z1*(1+((y1*z1)/6)+((y1*y1*z1*z1)/120))
C1=y1*(1+((y1*z1)/6)+((y1*y1*z1*z1)/120))
vs=(A1*vr1)+(B1*Ir1)
Is=(C1*vr1)+(D1*Ir1)
vor=((abs(vs/A1)-abs(vr1))*100)/abs(vr1)
pfs=cos(angle(vs)-angle(Is))
eff=(abs(pr)/abs(3*vs*Is*pfs))*100

OUTPUT:

enter the resistance .26


enter the inductive reactance.47
enter the shunt capacitance2.98e-6
enter the frequency50
enter the length of tx.300
enter the receciving end voltage110e3
enter the reciving end power:10e6
enter the reciving end pf:.8
vr1 = 6.3509e+004
Ir = 65.6080
ANr = 36.8699
Ir1 = 52.4864 -39.3648i
y1 = 0 +9.3572e-004i
z1 =7.8000e+001 +1.4100e+002i
A1 = 0.9345 + 0.0357i
D1 =0.9345 + 0.0357i
B1 = 7.4600e+001 +1.3885e+002i
C1 = -1.1232e-005 +9.1524e-004i
vs =6.8732e+004 +6.6178e+003i
Is = 49.7420 +23.2109i
vor = 16.2573
pfs =
0.9426
eff = 93.3058

PROGRAM FOR THREE PHASE DOUBLE CIRCUIT:


r=input('radius:');
dab=input('a&b:');
dbc=input('b&c:');
dca=input('c&a:');
daa1=input('a&a1:');
dab1=input('a&b1:');
dac1=input('a&c1:');
dbc1=input('b&c1:');
da1b1=dab
db1c=dbc1
dc1a=dac1
db1c1=dbc
da1c1=dca
dc1a1=dca
dbb1=daa1
dcc1=daa1
da1b=dab1
dca1=dac1
dcb1=dbc1
ds=r*0.7788
dsa=(ds*daa1)^(1/2)
dsb=(ds*daa1)^(1/2)
dsc=(ds*daa1)^(1/2)
gmr=(dsa*dsb*dsc)^(1/3)
Dab=(dab*dab1*da1b*da1b1)^(1/4)
Dbc=(dbc*dbc1*db1c*db1c1)^(1/4)
Dca=(dca*dca1*dc1a*dc1a1)^(1/4)
gmd=(Dab*Dbc*Dca)^(1/3)
l=0.2*log(gmd/gmr)
c=0.0566*(1/log(gmd/gmr))

OUTPUT:

radius:0.0108965
a&b:4
b&c:4
c&a:8
a&a1:5
a&b1:6.403124
a&c1:9.43398
b&c1:6.403124
da1b1 =4
db1c1 = 4
dbb1 = 5
dca1 = 9.4340
dsa = 0.2060
gmr = 0.2060
gmd = 6.0597
l = 0.6763
c =0.0167

db1c = 6.4031
da1c1 = 8
dcc1 = 5
dcb1 =6.4031
dsb = 0.2060
Dab =5.0609

dc1a =9.4340
dc1a1 =8
da1b = 6.4031
ds = 0.0085
dsc = 0.2060
Dbc =5.0609
Dca =8.6875

PROGRAM FOR FORMATION OF Y-BUS MATRIX USING MATLAB:


clear all
r=0;
v=0;
l=0;
w=0;
x=0;
k=0;
display('menu:');
display('1. y-bus form:');
display('2. y-bus modification:');
display('3. Exit');
while(x~=3)
ch=input('enter choice:');
if ch==1
n=input('no of buses:');
z=zeros(n,n);
y=zeros(n,n);
display('enter the impedance:');
for a=1:n
for b=1:n
z(a,b)=input('');
end
end
for a=1:n
for v=1:n
if z(a,v)~=0
y(a,a)=y(a,a)+(1/z(a,v));
end
end
for b=1:n
if a~=b
if(z(a,b)~=0)
y(a,b)=(-1/z(a,b));
end
end
end
end
y
pause;
elseif ch==2
display('submenu:');
display('1.adding and removal of element:');
display('2.removal of bus node:');
display('3.complete');
while k~=3
k=input('s:enter choice:');
if k==1
d=zeros(n,n);
s=zeros(n,n);
cont=1
while cont==1
r=input('from bus');
c=input('to bus');
x=input('enter 1 for add or 2 for remove');

d(r,c)=input('enter r+jx');
if(d(r,c)==0)
s(r,c)=0;
else
s(r,c)=(1/d(r,c));
end
if(x==2)
s(r,c)=-s(r,c);
end
if(r==c)
y(r,r)=y(r,r)+s(r,r);
else
y(r,c)=y(r,c)-s(r,c);
y(r,r)=y(r,r)+s(r,c);
y(c,c)=y(c,c)+s(r,c);
y(c,r)=y(r,c);
end
y
cont=input('press 1 for continur:');

end
pause;
elseif k==2
h=input('node to be eliminated:');
j=zeros(n,n);
q=zeros(n,n);
for a=1:h-1
for b=1:h-1
ybusnew(a,b)=y(a,b)-((y(a,n)*y(n,b))/y(n,n));
end
end
n=n-1;
y=ybusnew;
y
pause;
elseif k==3
k=10;
k
pause;
end

end

end
elseif ch==3
x=10;
x
pause
end

OUTPUT:
menu:
1. y-bus form:
2. y-bus modification:
3. Exit
enter choice:1
no of buses:4
enter the impedance:
0
0.05+0.15i
0.1+0.3i
0.2+0.4i
0.05+0.15i
0
0
0.1+0.3i
0.1+0.3i
0
0
0.05+0.15i
0.2+0.4i
0.1+0.3i
0.05+0.15i
0
y = Columns 1 through 3
4.0000 -11.0000i -2.0000 + 6.0000i -1.0000 +
-2.0000 + 6.0000i
3.0000 - 9.0000i
0
-1.0000 + 3.0000i
0
3.0000 -1.0000 + 2.0000i -1.0000 + 3.0000i -2.0000 +
Column 4
-1.0000 + 2.0000i
-1.0000 + 3.0000i
-2.0000 + 6.0000i
4.0000 -11.0000i
enter choice:2
submenu:
1.adding and removal of element:
2.removal of bus node:
3.complete
s:enter choice:2
node to be eliminated:4
y = 3.7664 -10.6423i -2.2555 + 6.5474i -1.5109
-2.2555 + 6.5474i
2.7518 - 8.1825i -0.4964 +
-1.5109 + 4.0949i -0.4964 + 1.6350i
2.0073 s:enter choice:3
k =
10

3.0000i
9.0000i
6.0000i

+ 4.0949i
1.6350i
5.7299i

PROGRAM FOR FORMATION OF Y-BUS MATRIX USING C-PROGRAM:


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct imp
{
float r,x;
}
z[10][10],y[10][10],s[10][10];
void main()
{
int ch=0,n,i,j,k,sch,b1,b2,x1,h,cont=1,s,r5;
float a,b,an,bn;
void dis(int);
clrscr();
printf("main menu\n1.Y-bus form\n2.Y-bus modification\n3.Exit\n");
while(ch<4)
{
printf("Enter ch:");
scanf("%d",&ch);
if(ch==1)
{
printf("\nEnter total no of bus");
scanf("%d",&n);
printf("\nEnter the imp");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%f%f",&a,&b);
z[i][j].r=a;
z[i][j].x=b;
}
}
for(i=1;i<=n;i++)
{
y[i][i].r=0;
y[i][i].x=0;
for(j=1;j<=n;j++)
{
if((z[i][j].r!=0)||(z[i][j].x!=0))
{
y[i][i].r=y[i][i].r+(z[i][j].r/((z[i][j].r*z[i][j].r)+
(z[i][j].x*z[i][j].x)));
y[i][i].x=y[i][i].x-(z[i][j].x/((z[i][j].r*z[i][j].r)+
(z[i][j].x*z[i][j].x)));
}
}
for(k=1;k<=n;k++)
{
if(i!=k)
{
if((z[i][k].r!=0)||(z[i][k].x!=0))
{
y[i][k].r=z[i][k].r/((z[i][k].r*z[i][k].r)+(z[i]
[k].x*z[i][k].x));

y[i][k].x=z[i][k].x/((z[i][k].r*z[i][k].r)+(z[i]
[k].x*z[i][k].x));
}
}
}
}
dis(n);
}
else if(ch==2)
{
printf("\nSubmenu\n1.Add/Removalof elements\n2.Removal of
node\n3.complete\n");
printf("Enter ch:");
scanf("%d",&sch);
switch(sch)
{
case 1:
while(cont==1)
{
printf("\nFrom bus to bus:");
scanf("%d%d",&a,&b);
printf("\n1.Add the element\n2.Removal\nEnter the ch:");
scanf("%d",&x1);
if(x1==1)
{
if((a!=0)||(b!=0))
{
bn=-(b/((a*a)+(b*b)));
an=a/((a*a)+(b+b));
a=an;
b=bn;
}
if(b1==b2)
{
y[b1][b2].r=y[b1][b2].r+a;
y[b1][b2].x=y[b1][b2].x+b;
dis(n);
}
else
{
y[b1][b2].r=y[b2][b1].r=y[b1][b2].r-a;
y[b1][b2].x=y[b2][b1].x=y[b1][b2].x-b;
y[b1][b1].r=y[b1][b1].r+a;
y[b1][b1].x=y[b1][b1].x+b;
y[b2][b2].r=y[b2][b2].r+a;
y[b2][b2].x=y[b2][b2].x+a;
dis(n);
}
}
printf("\nPress1 for continue:");
scanf("%d",&cont);
}
break;
case 2:
printf("\nEnter node to be eliminated:");
scanf("%d",&h);
r5=h;

for(i=1;i<=r5;i++)
{
for(s=1;s<=r5;s++)
{
y[i][s].r=y[i][s].r-((y[r5][r5].r*y[i][r5].r*y[r5][s].r)-(y[i]
[r5].x*y[r5][s].x*y[r5][r5].r)+(y[r5][r5].x*y[i][r5].r*y[r5][s].x)+
(y[i][r5].x*y[r5][r5].x*y[r5][s].r))/((y[r5][r5].r*y[r5][r5].r)+(y[r5]
[r5].x*y[r5][r5].x));
y[i][s].x=y[i][s].x-((y[r5][r5].r*y[i][r5].r*y[r5][s].x)-(y[i]
[r5].x*y[r5][s].r*y[r5][r5].r)+(y[r5][r5].x*y[i][r5].r*y[r5][s].r)+
(y[i][r5].x*y[r5][r5].x*y[r5][s].x))/((y[r5][r5].r*y[r5][r5].r)+(y[r5]
[r5].x*y[r5][r5].x));
}}
h=h-1;
printf("New Admittance Matrix is:");
for(i=1;i<=h;i++)
{
for(s=1;s<=h;s++)
{
printf("%1.3f+j(%1.3f)",y[i][s].r,y[i][s].x);
printf("\t");
}
printf("\n");
}
break;
case 3:
exit(0);
}
}
getch();
}}
void dis(int e)
{
int i,j;
printf("\nThe admittance matrix:");
for(i=1;i<=e;i++)
{
for(j=1;j<=e;j++)
{
printf("%1.4f+j(%1.4f)",y[i][j].r,y[i][j].x);
printf("\t");
}
printf("\n");
}
}

OUTPUT:
menu:

1. y-bus form:
2. y-bus modification:
3. Exit
enter choice:1
no of buses:4
enter the impedance:
0
0.05
0.15
0.1
0.3
0.2
0.4
0.05
0.15
0
0
0.1
0.3
0.1
0.3
0
0
0.05
0.15
0.2
0.4
0.1
0.3
0.05
0.15
0
The admittance matrix:
4.0000 +j(-11.0000) -2.0000 + j(6.0000)
+j(2.000)
-2.0000 +j(6.0000)
3.0000+j(-9.0000)
+j(3.0000)
-1.0000 +j(3.0000)
0.0000+j(0.0000)
+j(6.0000)
-1.0000 +j(2.0000)
-1.0000 +j(3.0000)
+j(-11.0000)
enter choice:2
submenu:
1.add/removal of element:
2.removal of bus node:
3.complete
enter choice:1
1.Add the element 2.Removal
enter choice:2
from bus to bus:1 4
entr the imp. To be added/eliminated:0.2
0.4
The admittance matrix:

-1.0000 +j(3.0000)

-1.0000

0.0000+j(0.0000)

-1.0000

3.0000+j(-9.0000)

-2.0000

-2.0000 +j(6.0000)

4.0000

3.0000 +j(-9.0000)
+j(0.000)
-2.0000 +j(6.0000)
+j(3.0000)
-1.0000 +j(3.0000)
+j(6.0000)
0.0000 +j(0.0000)
+j (-9.0000)

-2.0000 + j(6.0000)

-1.0000 +j(3.0000)

0.0000

3.0000 +j(-9.0000)

0.0000+j(0.0000)

-1.0000

3.0000 +j(-9.0000)

-2.0000

0.0000+j(0.0000)
-1.0000 +j(3.0000)

-2.0000 +j(6.0000)

3.0000

Press 1 for continue:1


1.Add the element 2.Removal
enter choice:1
from bus to bus:1 4
entr the imp. To be added/eliminated:0.2
0.4
The admittance matrix:
4.0000 +j(-11.0000) -2.0000 + j(6.0000)
+j(2.000)
-2.0000 +j(6.0000)
3.0000+j(-9.0000)
+j(3.0000)
-1.0000 +j(3.0000)
0.0000+j(0.0000)
+j(6.0000)
-1.0000 +j(2.0000)
-1.0000 +j(3.0000)
+j(-11.0000)

-1.0000 +j(3.0000)

-1.0000

0.0000+j(0.0000)

-1.0000

3.0000+j(-9.0000)

-2.0000

-2.0000 +j(6.0000)

4.0000

Press 1 for continue:2


Enter ch:2
submenu:
1.add/removal of element:
2.removal of bus node:
3.complete
enter choice:2
enter node to be eliminated:4
New admittance matrix is:3.7664+j(-10.6423) -2.2555+j(6.5474)
-1.5109+j(4.0949)
-2.2555 +j(6.5474)
2.7518+j(-8.1825) -0.4964+j(1.6350)
-1.5109 +j(4.0949) -0.4964 +j(1.6350)
2.0073+j(-5.7299)
enter choice:3

PROGRAM FOR FORMATION OF Z-BUS MATRIX USING MATLAB:


clear all
clc

r=0;
x=0;
w=0;
while(x~=5)
w=w+1;
display('main menu');
display('1. add element between new bus to ref bus');
display('2. add element between new to existing bus');
display('3. add element between existing to ref bus');
display('4. add element between existing to existing bus');
display('5. exit');
ch=input('enter ur choice:');
switch(ch)
case 1
n=input('no of buses');
r=input('enter the bus no:');
z(w,w)=input('enter the impedance:');
z
pause;
case 2
q=input('enter the existing bus no:');
p=input('enter the new bus no:');
z(w,w)=input('enter the impedance:');
l=w;
z(l,l)=z(w,w)+z(l-1,l-1);
for r=1:w-1
z(r,w)=z(r,w-1);
z(w,r)=z(r,w);
end
z
pause;
case 3
q=input('enter the existing bus no:');
z(w,w)=input('enter the impedance:');
n=w;
z(n,n)=z(w,w)+z(n-1,n-1);
for r=1:w-1
z(r,w)=z(r,w-1);
z(w,r)=z(r,w);
end
for a=1:w-1
for b=1:w-1
zbusnew(a,b)=z(a,b)-(z(a,w)*z(w,b)/z(w,w));
end
end
w=w-1;
z=zbusnew;
z
pause;
case 4
u=input('lower existing bus no:');
v=input('enter upper existing bus no:');
z(w,w)=input('enter the impedance:');
s=w;
z(s,s)=z(w,w)+z(u,u)+z(v,v)-(2*z(u,v));
for r=1:w-1
z(r,w)=z(r,u)-z(r,v);

end

z(w,r)=z(r,w);
end
for a=1:w-1
for b=1:w-1
zbusnew(a,b)=z(a,b)-(z(a,w)*z(w,b)/z(w,w));
end
end
w=w-1;
z=zbusnew;
z
pause;
case 5
display('THE IMPEDANCE MATRIX:');
z
pause;

end

OUTPUT:

main menu
1. add element between new bus to ref bus
2. add element between new to existing bus
3. add element between existing to ref bus
4. add element between existing to existing bus
5. exit
enter ur choice:1
no of buses3
enter the bus no:1
enter the impedance:1.5j
z =
0 + 1.5000i
main menu
1. add element between new bus to ref bus
2. add element between new to existing bus
3. add element between existing to ref bus
4. add element between existing to existing bus
5. exit
enter ur choice:2
enter the existing bus no:1
enter the new bus no:2
enter the impedance:-.5j
z =
0 + 1.5000i
0 + 1.5000i

0 + 1.5000i
0 + 1.0000i

main menu
1. add element between new bus to ref bus
2. add element between new to existing bus
3. add element between existing to ref bus

4. add element between existing to existing bus


5. exit
enter ur choice:2
enter the existing bus no:2
enter the new bus no:3
enter the impedance:0.6j
z =
0 + 1.5000i
0 + 1.5000i
0 + 1.5000i

0 + 1.5000i
0 + 1.0000i
0 + 1.0000i

0 + 1.5000i
0 + 1.0000i
0 + 1.6000i

main menu
1. add element between new bus to ref bus
2. add element between new to existing bus
3. add element between existing to ref bus
4. add element between existing to existing bus
5. exit
enter ur choice:3
enter the existing bus no:3
enter the impedance:1.5j
z =
0 + 0.7742i
0 + 1.0161i
0 + 0.7258i
main menu
1. add element between
2. add element between
3. add element between
4. add element between
5. exit
enter ur choice:5
THE IMPEDANCE MATRIX:

0 + 1.0161i
0 + 0.6774i
0 + 0.4839i

0 + 0.7258i
0 + 0.4839i
0 + 0.7742i

new bus to ref bus


new to existing bus
existing to ref bus
existing to existing bus

z =
0 + 0.7742i
0 + 1.0161i
0 + 0.7258i

0 + 1.0161i
0 + 0.6774i
0 + 0.4839i

0 + 0.7258i
0 + 0.4839i
0 + 0.7742i

PROGRAM FOR FORMATION OF Z-BUS MATRIX USING C-PROGRAM:


#include<stdio.h>
#include<conio.h>

#include<stdlib.h>
#define x 10
struct impedance
{
float res;
float reac;
}z[x][x];
void main()
{
int n,r,s,ch=0,entry=0,r1,r2,r5;
float r3,r4;
void reduction(int);
clrscr();
printf("\nMain Menu\n1.Add new bus to ref bus\n2.Add new bus to exist
bus\n3.Add exist bus to ref bus\n4.Add exist bus to exist
bus\n5.display\n6.exit\n");
while(ch<=6)
{
entry=entry+1;
printf("\nEnter ur choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
r5=entry;
printf("\nEnter total no of bus");
scanf("%d",&n);
printf("\nBus no:");
scanf("%d",&r1);
printf("\nEnter the resis and reac:");
scanf("%f%f",&r3,&r4);
z[r5][r5].res=r3;
z[r5][r5].reac=r4;
break;
}
case 2:
{
printf("\nEnter the exist bus no");
scanf("%d",&r1);
printf("\nEnter new Bus no:");
scanf("%d",&r2);
printf("\nEnter the resis and reac:");
scanf("%f%f",&r3,&r4);
r5=entry;
z[r5][r5].res=z[r5-1][r5-1].res+r3;
z[r5][r5].reac=z[r5-1][r5-1].reac+r4;
r2=r5;
for(r=1;r<r2;r++)
{
z[r][r2].res=z[r][r2-1].res;
z[r][r2].reac=z[r][r2-1].reac;
z[r2][r].res=z[r][r2].res;
z[r2][r].reac=z[r][r2].reac;
}
break;
}

case 3:
{
r5=entry;
printf("\nEnter the exist bus no");
scanf("%d",&r2);
printf("\nEnter the resis and reac:");
scanf("%f%f",&r3,&r4);
z[r5][r5].res=z[r5-1][r5-1].res+r3;
z[r5][r5].reac=z[r5-1][r5-1].reac+r4;
for(r=1;r<r5;r++)
{
z[r][r5].res=z[r][r5-1].res;
z[r][r5].reac=z[r][r5-1].reac;
z[r5][r].res=z[r][r5].res;
z[r5][r].reac=z[r][r5].reac;
}reduction(r5);
entry=entry-1;
break;
}
case 4:
{
r5=entry;
printf("\nEnter the lower exist bus no");
scanf("%d",&r1);
printf("\nEnter the upper exist bus no");
scanf("%d",&r2);
printf("\nEnter the resis and reac:");
scanf("%f%f",&r3,&r4);
z[r5][r5].res=z[r1][r1].res+z[r2][r2].res+r3-(2*z[r1][r2].res);
z[r5][r5].reac=z[r1][r1].res+z[r2][r2].reac+r4-(2*z[r1][r2].reac);
for(r=1;r<r5;r++)
{
z[r][r5].res=z[r][r2].res-z[r][r1].res;
z[r][r5].reac=z[r][r2].reac-z[r][r1].reac;
z[r5][r].res=z[r][r5].res;
z[r5][r].reac=z[r][r5].reac;
}reduction(r5);
entry=entry-1;
break;
}
case 5:
{
printf("\nImpedance Matrix\n");
r5=entry-1;
for(r=1;r<=r5;r++)
{
for(s=1;s<=r5;s++)
{
printf("%1.4f+j(%1.4f)",z[r][s].res,z[r][s].reac);
printf("\t");
}
printf("\n");
}
entry=entry-1;
break;
}
case 6:

exit(0);
} } }
getch();
}
void reduction(int r6)
{
int r,r5,s;
r5=r6;
for(r=1;r<=r5;r++)
{
for(s=1;s<=r5;s++)
{
z[r][s].res=z[r][s].res-((z[r][r5].res*z[r5][s].res*z[r5][r5].res)(z[r][r5].reac*z[r5][s].reac*z[r5][r5].res)+(z[r][r5].res*z[r5]
[s].reac*z[r5][r5].reac)+(z[r][r5].reac*z[r5][s].res*z[r5][r5].reac))/
((z[r5][r5].res*z[r5][r5].res)+(z[r5][r5].reac));
z[r][s].reac=z[r][s].reac-((z[r][r5].reac*z[r5][s].reac*z[r5]
[r5].reac)-(z[r][r5].res*z[r5][s].res*z[r5][r5].reac)+(z[r]
[r5].reac*z[r5][s].res*z[r5][r5].res)+(z[r][r5].res*z[r5][s].reac*z[r5]
[r5].res))/((z[r5][r5].reac*z[r5][r5].reac)+(z[r5][r5].res));
}

}
}

OUTPUT:

Main Menu
1.Add new bus to ref bus
2.Add new bus to exist bus
3.Add exist bus to ref bus
4.Add exist bus to exist bus
5.display
6.exit
enter ur choice:1
enter total no of buses3
bus no:1
enter the resistance&reactance:0
1.2
0.0000 +j(1.2000)
enter ur choice:2
enter the existing bus no:1
enter the new bus no:2
enter the resistance&reactance:0
0.2
0.0000 +j(1.2000)
0.0000 +j(1.2000)
0.0000 +j(1.2000)
0.0000 +j(1.4000)
enter ur choice:2

enter the existing bus no:2


enter the new bus no:3
enter the resistance&reactance:0
0.15
0.0000 +j(1.2000)
0.0000 +j(1.2000)
0.0000 +j(1.2000)
0.0000 +j(1.4000)
0.0000 +j(1.2000)
0.0000 +j(1.4000)
enter ur choice:3
enter the existing bus no:3
enter the resistance&reactance:0
1.5
0.0000 +j(1.2000)
0.0000 +j(1.2000)
+j(1.2000)
0.0000 +j(1.2000)
0.0000 +j(1.4000)
+j(1.4000)
0.0000 +j(1.2000)
0.0000 +j(1.4000)
+j(1.5500)
0.0000 +j(1.2000)
0.0000 +j(1.4000)
+j(3.0500)
The reduced matrix is:
0.0000 +j(0.7279)
0.0000 +j(0.6492)
0.0000 +j(0.6492)
0.0000 +j(0.7574)
0.0000 +j(0.5902)
0.0000 +j(0.6885)
enter ur choice:4
enter the lower existing bus no:1
enter the upper existing bus no:3
enter the resistance&reactance:0
0.3
0.0000 +j(0.6968)
0.0000 +j(0.6581)
0.0000 +j(0.6581)
0.0000 +j(0.7548)
0.0000 +j(0.6290)
0.0000 +j(0.6774)
enter ur choce:6

0.0000 +j(1.2000)
0.0000 +j(1.4000)
0.0000 +j(1.5500)

0.0000 +j(1.2000) 0.0000


0.0000 +j(1.4000) 0.0000
0.0000 +j(1.5500) 0.0000
0.0000 +j(1.5500) 0.0000
0.0000 +j(0.5902)
0.0000 +j(0.6885)
0.0000 +j(0.7623)

0.0000 +j(0.6290)
0.0000 +j(0.6774)
0.0000 +j(0.7137)

PROGRAM FOR LOAD FLOW SOLUTION BY GAUSS SEIDAL METHOD:


clear all
clc
n=input('enter the no of buses');

z=zeros(n,n);
y=zeros(n,n);
display('enter the impedance');
for a=1:n
for b=1:n
z(a,b)=input('');
end
end
for a=1:n
for v=1:n
if z(a,v)~=0
y(a,a)=y(a,a)+(1/z(a,v));
end
end
for b=1:n
if(a~=b)
if(z(a,b)~=0)
y(a,b)=(-1/z(a,b));
end
end
end
end
v=zeros(n,n);
qmax=zeros(n);
qmin=zeros(n);
type=zeros(n);
q=zeros(n);
p=zeros(n);
for a=1:n
type(a)=menu('\n click type of bus','slack bus','pvbus','pqbus');
switch(type(a))
case 1
v(a,1)=input('enter the bus voltage:');
case 2
p(a)=input('enter the realpower of bus:');
v(a,1)=input('enter the bus voltage:');
qmax(a)=input('enter qmax:');
qmin(a)=input('enter qmin:');
case 3
p(a)=input('enter the real power of bus:');
q(a)=input('enter the reactive power of bus:');
v(a,1)=1;
end
end
alpha=input('enter value of acceleration factor:');
t=input('enter the tolerance limit:');
count=0;
for a=1:n
ip2=0;
ip=0;
ip1=0;
ip3=0;
del=zeros(n,n);
q1=zeros(n,n);
switch (type(a))
case 1
v(a,2)=v(a,1);

case 2
v(a,2)=v(a,1);
for b=1:n
if(b<a)
ip2=ip2+y(a,b)*v(b,2);
end
if(b>=a)
ip=ip+y(a,b)*v(b,1);
end
end
q1(a,1)=-imag(conj(v(a,1)*(ip2+ip)));
if(q1(a,1)<qmin(a))
q1(a,1)=qmin(a);
end
if(q1(a,1)>qmax(a))
q1(a,1)=qmax(a);
end
q1(a)=q1(a,1);
ip1=(p(a)-q1(a)*1i)/conj(v(a,1));
for b=1:n
if(b>a)
ip3=ip3+y(a,b)+v(b,1);
end
end
v(a,2)=(ip1-ip2-ip3)/y(a,a);
del(a,1)=angle(v(a,2));
v(a,2)=v(a,1)*(cos(del(a,1)+sin(del(a,1))*1i));
case 3
v(a,2)=v(a,1);
ip1=-(p(a)-q(a)*1i)/conj(v(a,1));
for b=1:n
if(b<a)
ip2=ip2+y(a,b)*v(b,2);
end
if(b>a)
ip3=ip3+y(a,b)+v(b,1);
end
end
v(a,2)=(ip1-ip2-ip3)/y(a,a);
dell(a,1)=angle(v(a,2));
v(a,2)=v(a,1)+alpha*(v(a,2)-v(a,1));

end
end
count=count+1;
fprintf('ybus');
display(y);
ct=0;
diff=zeros(n,n);
for a=1:count
b=2;
diff(b,a)=v(b,a)-v(b,a+1);
if(diff(b,a)>t)
ct=ct+1;
end
end
fprintf('calculate values of voltage after %d iteration:n',ct);
v1=zeros(n,n);

del=zeros(n,n);
dell=zeros(n,n);
for b=1:n
fprintf('iteration value ct %d bus n',b);
for c=2:ct+1
fprintf('%d iteration n',c-1);
disp(v(b,c))
v1(b,1)=v(b,c);
del(b,1)=angle(v1(b,1));
dell(b,1)=del(b,1);
end
end
fprintf('exact value of voltage angle are');
display(v1);
display(dell);
slack=0;
pqflow=zeros(n,n);
for a=1:n
for b=a+1:n
pqflow(a,b)=conj(v(a,1)-v(b,1)*y(a,b));
fprintf('\n Real and reactive power flow between %d bus to %d
bus is',a,b);
fprintf('%f,%f',real(pqflow(a,b)-imag(pqflow(a,b))));
if a==1
slack=slack+pqflow(a,b);
end
end
end

OUTPUT:
enter the no of buses:5
enter the impedance
0
0.05+0.15i
0
0
0.05+0.15i
0.05+0.15i
0
0.05+0.15i
0
0.05+0.15i
0
0.05+0.15i
0
0.05+0.15i
0
0
0
0.05+0.15i
0
0.05+0.15i
0.05+0.15i

0.05+0.15i
0
0.05+0.15i
0
enter the bus voltage:1.02
enter the realpower of bus:2
enter the bus voltage:1.02
enter qmax:0.6
enter qmin:0.4
enter the real power of bus:0.5
enter the reactive power of bus:0.2
enter the real power of bus:0.5
enter the reactive power of bus:0.2
enter the real power of bus:0.5
enter the reactive power of bus:0.2
enter value of acceleration factor:1
enter the tolerance limit:0
ybus
y =
Columns 1 through 4
0
0

4.0000 -12.0000i
-2.0000 + 6.0000i

-2.0000 + 6.0000i
6.0000 -18.0000i

0
-2.0000 + 6.0000i

0
-2.0000 + 6.0000i
-12.0000i
-2.0000 + 6.0000i
0
0
-2.0000 + 6.0000i
4.0000 -12.0000i
-2.0000 + 6.0000i
-2.0000 + 6.0000i
-2.0000 + 6.0000i

4.0000

Column 5
-2.0000
-2.0000
0
-2.0000
6.0000

+ 6.0000i
+ 6.0000i
+ 6.0000i
-18.0000i

calculate values of voltage after 1 iteration:niteration value ct 1 bus


n1 iteration n
1.0200
iteration value ct 2 bus n1 iteration n

1.0200 - 0.0034i

iteration value ct 3 bus n1 iteration n

0.9325 - 0.1842i

iteration value ct 4 bus n1 iteration n

0.9137 - 0.1996i

iteration value ct 5 bus n1 iteration n

0.9662 - 0.0893i

exact value of voltage angle are


v1 = Columns 1 through 4
1.0200
0
1.0200 - 0.0034i
0
0.9325 - 0.1842i
0

0
0

0
0

0.9137 - 0.1996i
0.9662 - 0.0893i

0
0

0
0

0
0

Column 5
0
0
0
0
0
dell = 0
-0.0034
-0.1950
-0.2151
-0.0922
Real
Real
Real
Real
Real
Real
Real
Real
Real
Real

and
and
and
and
and
and
and
and
and
and

0
0
0
0

reactive
reactive
reactive
reactive
reactive
reactive
reactive
reactive
reactive
reactive

power
power
power
power
power
power
power
power
power
power

0
0
0
0

flow
flow
flow
flow
flow
flow
flow
flow
flow
flow

0
0
0
0

between
between
between
between
between
between
between
between
between
between

1
1
1
1
2
2
2
3
3
4

0
0
0
0

bus
bus
bus
bus
bus
bus
bus
bus
bus
bus

to
to
to
to
to
to
to
to
to
to

2
3
4
5
3
4
5
4
5
5

bus
bus
bus
bus
bus
bus
bus
bus
bus
bus

is-3.060000,
is1.020000,
is1.020000,
is-2.980000,
is-2.980000,
is1.020000,
is-2.980000,
is-3.000000,
is1.000000,
is-3.000000,

PROGRAM FOR LOAD FLOW SOLUTION BY NEWTON RAPHSON METHOD:


clear all
clc
n=input('No of buses');
z=zeros(n,n);

y=zeros(n,n);
display('Enter the impedence');
for a=1:n
for b=1:n
z(a,b)=input('');
end
end
for a=1:n
for v=1:n
if(z(a,v)~=0)
y(a,a)=y(a,a)+(1/z(a,v));
end
end
for b=1:n
if(a~=b)
if(z(a,b)~=0)
y(a,b)=(-1/z(a,b));
end
end
end
end
display(y);
vold=[1.05+0j 1+0j 1+0j];
s1=[0+0j 0.9+0.2j -0.3-0.1j];
e=real(vold);
f=imag(vold);
ps=real(s1);
qs=imag(s1);
g=real(y);
b=imag(y);
a=1;
q=zeros(n);
p=zeros(n);
con=10;
for j=2:n
p(j)=0;
q(j)=0;
for k=1:n
p(j)=p(j)+(e(j)*((e(k)*g(j,k))+(f(k)+b(j,k)))
+f(j)*((f(k)*g(j,k))-(e(k)*b(j,k))));
q(j)=q(j)+(f(j)*((e(k)*g(j,k))+(f(k)+b(j,k)))e(j)*((f(k)*g(j,k))-(e(k)*b(j,k))));
end
end
for j=2:n
sumpe=0;
sumpf=0;
sumqe=0;
sumqf=0;
delpe=zeros(n,n);
for k=1:n
if(k~=j)
sumpe=sumpe+(e(k)*g(j,k))+(f(k)*b(j,k));
sumpf=sumpf+(f(k)*g(j,k))+(e(k)*b(j,k));
sumqe=sumqe+(f(k)*g(j,k))+(e(k)*b(j,k));
sumqf=sumqf+(e(k)*g(j,k))+(f(k)*b(j,k));
end

if(k~=1)&&(k~=j)
delpe(j,k)=(e(j)*g(j,k))-(f(j)*b(j,k));
delpf(j,k)=(e(j)*b(j,k))-(f(j)*b(j,k));
delqe(j,k)=(e(j)*b(j,k))-(f(j)*b(j,k));
delqf(j,k)=(e(j)*g(j,k))-(f(j)*b(j,k));
end
end
delpe(j,j)=(2*e(j)*g(j,j)+sumpe);
delpf(j,j)=(2*f(j)*g(j,j)+sumpf);
delqe(j,j)=(2*e(j)*b(j,j)+sumqe);
delqf(j,j)=(2*f(j)*b(j,j)+sumqf);

end
for j=1:n-1
for k=1:n-1
delpem(j,k)=delpe(j+1,k+1);
delpfm(j,k)=delpf(j+1,k+1);
delqem(j,k)=delqe(j+1,k+1);
delqfm(j,k)=delpf(j+1,k+1);
delqem(j,k)=delqem(j,k)+1.6320;
end
end
jacob=[-delpfm delpem;delqfm delqem];
display(jacob);
dels=[0.285;0];
cinv=inv(jacob)*dels;
display(cinv);
for j=2:n
e(j)=e(j)+cinv(j-1);
f(j)=f(j)+cinv(j-1);
a=a+1;
end

OUTPUT:

PROGRAM FOR ECONOMIC LOAD DISPATCH:


n=input('Enter the no.of.generating units');
display('a:co-efficent of X b:constant');
a=zeros(n);
b=zeros(n);
B=zeros(n);
for r=1:n

a(r)=input('co-efficient in pu:');
b(r)=input('constant:');
end
display('Enter the loss co-efficent in p.u:');
for m=1:n
for l=1:n
B(m,l)=input('i');
end
end
PD=input('Enter the power demand value:');
wx=0;
wy=0;
for i=1:n
wx=wx+(b(i)/(2*a(i)));
wy=wy+(1/(2*a(i)));
end
display('Lagrange Multiplier');
A=(PD+wx)/wy;
display(A);
display('Without losses');
PG=zeros(n,n);
pg=zeros(n,n);
for r=1:n
PG(r,1)=(A-b(r))/a(r);
PG(r,1)=PG(r,1)/2;
end
for r=1:n
pg(r,1)=0;
end
display(PG);
pg(2,1)=PG(2,1);
pg(1,1)=PG(1,1);
display('With Losses');
PG(1,1)=(A-b(1)-(2*A*B(1,2)*pg(2,1)))/(2*(a(1)+(A*B(1,1))));
PG(2,1)=(A-b(2)-(2*A*B(2,1)*pg(1,1)))/(2*(a(2)+(A*B(2,2))));
display('Power Distribution:');
display(PG);
display('Power loss');
PL=(B(1,1)*PG(1,1)^(2))+(B(2,2)*PG(2,1)^(2))+(2*B(1,2)*PG(1,1)*PG(2,1);
display(PL);

OUTPUT:
Enter the no.of.generating units2
a:co-efficent of X b:constant
co-efficient in pu:0.05
constant:23.5
co-efficient in pu:0.2
constant:20
Enter the loss co-efficent in p.u:
i0.01
i-.0005

i-.0005
i0.0024
Enter the power demand value:275
Lagrange Multiplier
A =
44.8000
Without losses
PG =
213.0000
62.0000

0
0

With Losses
Power Distribution:
PG =
24.1743
55.8377

0
0

Power loss
PL =
11.9770

PROGRAM FOR LOAD FREQUENCY DYNAMICS OF SINGLE AREA POWER SYSTEM:


r=input('Enter value of reg:');
f=input('enter frequency:');
pr=input('Enter freq and capacity:');
pd=input('Enter nominal generating load:');
h=input('enter inertia constant:');
m=input('Enter load change:');
display('Steady state change in freq is:');
d=(pd/pr)/f;

re=(r/100)*f;
beta=d+(1/re);
M=m/pr;
delfs=-(M/beta);
delfs
x=[0:0.2:20];
y=cos(x)./sqrt(x+1);
plot(x,y);

OUTPUT:
Enter value of reg:3
enter frequency:50
Enter freq and capacity:2000
Enter nominal generating load:1000
enter inertia constant:5
Enter load change:20
Steady state change in freq is:
delfs = -0.0148

0.5

-0.5

10

12

14

16

18

20

You might also like