PRACTICAL
Aim:-To obtain Z bus using Z bus algorithm method.
Program:-
clc
clear all
zprimary=[1 1 0 0.25;
         2 2 1 0.1;
         3 3 1 0.1;
         4 2 0 0.25;
         5 3 2 0.1 ]
[elements columns]=size(zprimary)
zbus=[ ]
currentbusno=0
for count=1:elements
   [rows cols]=size(zbus)
   from = zprimary(count,2)
   to=zprimary(count,3)
   value=zprimary(count,4)
   newbus=max(from,to)
   ref=min(from,to)
   if newbus > currentbusno & ref==0        %type1modification
       zbus=[zbus zeros(rows,1)
            zeros(1,cols) value]
       currentbusno=newbus
       continue
   end
   if newbus > currentbusno & ref~=0 %type2modification
      zbus=[zbus zbus(:,ref)
           zbus(ref,:) value+zbus(ref,ref)]
        currentbusno=newbus
        continue
   end
   if newbus <= currentbusno & ref==0 %type3modification
       zbus=zbus-1/(zbus(newbus,newbus)+value)*zbus(:,newbus)*zbus(newbus,:)
       continue
   end
   if newbus <= currentbusno & ref~=0 %type4modification
       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
Results:-
zprimary =
  1.0000        1.0000     0      0.2500
  2.0000 2.0000          1.0000     0.1000
  3.0000        3.0000   1.0000     0.1000
  4.0000        2.0000     0      0.2500
  5.0000        3.0000   2.0000     0.1000
elements =
         5
columns =
        4
zbus =
        []
currentbusno =
        0
rows =
        0
cols =
        0
from =
        1
to =
        0
value =
       0.2500
newbus =
        1
ref =
       0
zbus =
   0.2500
currentbusno =
       1
rows =
        1
cols =
        1
from =
        2
to =
       1
value =
  0.1000
newbus =
   2
ref =
   1
zbus =
  0.2500        0.2500
  0.2500        0.3500
currentbusno =
            2
rows =
            2
cols =
            2
from =
         3
to =
         1
value =
       0.1000
newbus =
         3
ref =
         1
zbus =
  0.2500 0.2500          0.2500
  0.2500        0.3500   0.2500
  0.2500        0.2500   0.3500
currentbusno =
         3
rows =
          3
cols =
          3
from =
         2
to =
         0
value =
         0.2500
newbus =
         2
ref =
         0
zbus =
  0.1458   0.1042   0.1458
  0.1042   0.1458   0.1042
  0.1458   0.1042   0.2458