You are on page 1of 3

%program for building zbus

%eg 5.1 in M.A.PAI


clc;
clear all;
z=[ 1
1
0
0.25j;
2
2
1
0.08j;
3
3
1
0.13j;
4
3
0
0.2j;
5
2
3
0.03j];
nbus=max(max(z(:,2)),max(z(:,3)))
[elements columns]=size(z);
%to begin with [zbus] is a null matrix
zbus=[]
%current bus no. indicates the maximum no. of buses added till now
currentbusno=0
%Process each row of z
for count=1:elements,
[rows cols]=size(zbus)
from=z(count,2)
to=z(count,3)
value=z(count,4)
%newbus variable indicates the maximum no. of the two buses-frombus and tobus
%newbus bus may or may not be a part of existing zbus
newbus=max(from,to);
%ref variable indicates the minimum no. of the two buses-frombus and tobus
%and it is not necessarily the reference bus
%ref bus must always exist in the existing bus
ref=min(from,to)
%Modification of type1
%A new element is added from new bus to reference bus
if newbus>currentbusno & ref ==0
zbus=[zbus zeros(rows,1)
zeros(1,cols) value];
currentbusno=newbus
continue
end
%Modification of type2
%A new bus is added from new bus to old bus other than reference bus
if newbus>currentbusno & ref~=0
zbus=[zbus zbus(:,ref)
zbus(ref,:) value+zbus(ref,ref)]
currentbusno=newbus
continue
end
%Modification of type3
%A new element is added between an old bus and reference bus
if newbus <= currentbusno & ref==0
zbus=zbus-1/(zbus(newbus,newbus)+value)*zbus(:,newbus)*zbus(newbus,:)
continue
end

%Modification of type4
%A new element is added between two old buses
if newbus <= currentbusno & ref~=0
zbus=zbus-1/(value+zbus(from,from)+zbus(to,to)2*zbus(from,to))*((zbus(:,from)-zbus(:,to))*((zbus(from,:)-zbus(to,:))));
continue
end
end
disp('[Zbus]:')
disp(zbus)
%Calculation of symmetrical fault bus voltages and line currents
zf=input('Enter the fault impedance:');
vf=1+0j
ter=1;
for i=1:nbus
fc(i)=(vf/(zbus(i,i)+zf));
end
fc
while ter==1
bn=input('Enter fault bus number:');
bv(bn)=zf*fc(bn);
for i=1:nbus
if i~=bn
bv(i)=vf-(zbus(i,bn)*fc(bn));
end
end
bv
from=z(:,2);
to=z(:,3);
nlength=length(from);
for i=1:nlength
if to(i)==0
linech(from(i))=((vf-bv(from(i)))/(z(i,4)));
end
if to(i)~=0
linec(from(i),to(i))=((bv(from(i))-bv(to(i)))/(z(i,4)));
end
end
for i=1:nlength
if to(i)==0
fprintf('line current %d - %d',from(i),to(i));
linech(from(i))
end
end
for i=1:nlength
if to(i)~=0
fprintf('line current %d - %d',from(i),to(i));
linec(from(i),to(i))
end
end
fprintf('\n if you want fault at various bus yes=1,no=0');
ter=input('');
end

You might also like