2program For Formation of y
2program For Formation of y
2program For Formation of y
clear all
r=0;
v=0;
l=0;
w=0;
x=0;
k=0;
display('menu:');
display('1. y-bus formation:');
display('2. y-bus modification');
display('3. exit');
while(x~=3)
ch=input('enter choice:');
if ch==1
n=input('enter 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 continue:');
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
display('exit');
pause;
end
end
elseif ch==3
display('complete');
pause;
end
end
OUTPUT:
menu:
1. y-bus formation:
2. y-bus modification
3. exit
enter choice:1
enter no of buses:4
enter the impedance:
0
2i
2.5i
2.5i
2i
0
1.667i
0
2.5i
1.667i
0
2i
2.5i
0
2i
0
y=
0 - 1.3000i
0 + 0.5000i
0 + 0.4000i
0 + 0.4000i
enter choice:2
0 + 0.5000i
0 - 1.0999i
0 + 0.5999i
0
0 + 0.4000i
0 + 0.5999i
0 - 1.4999i
0 + 0.5000i
0 + 0.4000i
0
0 + 0.5000i
0 - 0.9000i
submenu :
1. adding and removal of element
2. removal of bus node:
3. complete
s:enter choice:2
node to be eliminated:4
y=
0 - 1.1222i
0 + 0.5000i
0 + 0.6222i
s:enter choice:3
exit
enter choice:3
complete
0 + 0.5000i
0 - 1.0999i
0 + 0.5999i
0 + 0.6222i
0 + 0.5999i
0 - 1.2221i