You are on page 1of 2

%formation of Y bus

clc;
clear all;
%Getting line datas
% from to r x
zdata =[ 1 2 .025 .1
2 3 .02 .08
3 4 .05 .2
1 4 .04 .16];
n1=zdata(: ,1);
nr=zdata(: ,2);
r=zdata(: ,3);
x=zdata(: ,4);
nbr=length(zdata (: ,1));
nbus=max(max(n1),max(nr));
z=r+j*x;
y=ones(nbr,1)./z;
ybus=zeros(nbus,nbus); % initialize ybus to zero
for k=1:nbr; % formation of the off diagonal element
if n1(k)>0&nr(k)>0
ybus(n1(k),nr(k))=ybus(n1(k),nr(k))-y(k);
ybus(nr(k),n1(k))=ybus(n1(k),nr(k));
end
end
for n=1:nbus
for k=1:nbr
if n1(k)==n |nr(k) ==n
ybus (n,n) =ybus (n,n) +y(k);
else, end
end
end
ybus













output
ybus =
3.8235 -15.2941i -2.3529 + 9.4118i 0 -1.4706 + 5.8824i
-2.3529 + 9.4118i 5.2941 -21.1765i -2.9412 +11.7647i 0
0 -2.9412 +11.7647i 4.1176 -16.4706i -1.1765 +4.7059i
-1.4706 + 5.8824i 0 -1.1765 + 4.7059i 2.6471 -10.5882i