Coding (1)
Coding (1)
clc;
clear all;
n=input('Enter number of buses');
l=input('Number of lines');
s=input('1.Impedance or 2:Admittance');
for i=1:l
a=input('Starting bus:');
b=input('Ending bus:');
t=input('Admittance or Impedance of line:');
lca=input('Line charging admittance:')
if(s==1)
y(a,b)=1/t;
else
y(a,b)=t;
end
y(b,a)=y(a,b);
lc(a,b)=lca;
lc(b,a)=lc(a,b);
end
ybus=zeros(n,n);
for i=1:n
for j=1:n
if i==j
for k=1:n
ybus(i,j)=ybus(i,j)+y(i,k)+lc(i,k)/2;
end
else
ybus(i,j)=-y(i,j);
end
ybus(j,i)=ybus(i,j);
end
end
ybus
zbus=(ybus)^(-1);
zbus
Z BUS FORMATION USING BUS BUILDING ALGORITHM
clc;
clear all;
n=input('Enter the number of ele present in the system');
data=zeros(n,4);
for a=1:n
data(a,1)=input('Enter the element number');
data(a,2)=input('Enter the sending end bus');
data(a,3)=input('Enter the receiving end bus');
data(a,4)=input('Enter the element value');
end
data
[ele columns]=size(data);
zbus=[];
currentbusno=0;
for count=1:ele
[rows cols]=size(zbus);
from=data(count,2)
to=data(count,3)
value=data(count,4)
newbus=max(from,to)
ref=min(from,to)
if newbus>currentbusno & ref==0
zbus=[zbus zeros(rows,1)
zeros(1,cols) value]
currentbusno=newbus
continue
end
if newbus>currentbusno & ref~=0
zbus=[zbus zbus(:,ref)
zbus(ref,:) value+zbus(ref,ref)]
currentbusno=newbus
continue
end
if newbus<=currentbusno & ref==0
zbus=zbus-1 /(zbus(newbus,newbus)+value)*zbus(:,newbus)*zbus(newbus,:)
continue
end
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