Formation of Z Bus Using Step by Step Method: Matlab Code

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

160060049

FORMATION OF Z BUS USING STEP BY STEP METHOD


Matlab Code:
%Formation of Z-bus
clc;
clear all;
close all;
ip=fopen('psa6.ip.m','r+');
op=fopen('psa6.op.m','w+');
data=fscanf(ip,'%g',[3,5]);
ld=transpose(data);
fprintf(op,'\n\tLine data \n\n');
for i=1:5
for j=1:3
fprintf(op,'%g\t',ld(i,j));
end
fprintf(op,'\n');
end
from=ld(:,1);
to=ld(:,2);
value=ld(:,3);
zbus=[];
maxi=0;
for i=1:5
a=value(i,1);
bus=max(from(i,1),to(i,1));
ref=min(from(i,1),to(i,1));
[p q]=size(zbus);
if(bus>maxi & ref==0)
zbus=[zbus zeros(p,1) zeros(1,q) a];
maxi=bus;
continue
end
if(bus>maxi & ref~=0)
zbus=[zbus zbus(:,ref)
zbus(ref,:) a+zbus(ref,ref)];
maxi=bus;
continue
end
if(bus<=maxi & ref==0)
zbus=zbus-1/(zbus(bus,bus)+a)*zbus(:,bus)*zbus(bus,:);
continue
end
if(bus<=maxi & ref~=0)
zbus=zbus-1/(a+zbus(bus,bus)+zbus(ref,ref)-
2*zbus(bus,ref))*(zbus(:,bus)-zbus(:,ref))*(zbus(bus,:)-zbus(ref,:));
continue
end
end

fprintf(op,'\n\n\tzbus is\n\n');
for i=1:maxi
for j=1:maxi
fprintf(op,'%g\t',zbus(i,j));
end
160060049

fprintf(op,'\n');
end
fclose(ip);
fclose(op);

Input:
1 0 0.25
2 1 0.1
3 1 0.1
2 0 0.25
2 3 0.1

Output:

Line data

1 0 0.25
2 1 0.1
3 1 0.1
2 0 0.25
2 3 0.1

zbus is

0.139706 0.110294 0.125


0.110294 0.139706 0.125
0.125 0.125 0.175

You might also like