Professional Documents
Culture Documents
OUTPUT:
OUTPUT:
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
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
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
-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
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
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
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
#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
0.0000 +j(1.2000)
0.0000 +j(1.4000)
0.0000 +j(1.5500)
0.0000 +j(0.6290)
0.0000 +j(0.6774)
0.0000 +j(0.7137)
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
1.0200 - 0.0034i
0.9325 - 0.1842i
0.9137 - 0.1996i
0.9662 - 0.0893i
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,
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:
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
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