- #1
Fatima Hasan
- 319
- 14
- Homework Statement
- Find the Z bus Matrix using Z building algorithm method, using MATLAB code; where the Line data matrix and Bus data are given.
- Relevant Equations
- -
I tried to write to the code, but I got confused in line 46 & 59.Every new added bus increases the dimension of the Z matrix, and since we have 3 busses, the dimension of Z should be [3x3]. I formed a for loop in case of adding a new bus to add a new row and new column (increases the dimension), I kept the limits of b from 1 to max. # of busses (Which is 3) to not add the 4th row and 4th column. However, I do not know how to get the last element of the matrix (which is element (3x3)). So, could someone please help me with?
Here's my code:
The result:
However, element (3x3) should be 1+0.2 = 1.2 (Zd (3) + element (1,1) of z matrix = 0.2)
Here's my code:
Matlab:
clc;
clear all;
% | From | To | R | X | gsh | B | T|ysh
% | Bus | Bus | pu | pu | pu | pu | ph-sh
LD= [ 1 2 0 0.8 0 0
1 3 0 0.4 0 0
2 3 0 0.4 0 0];
r=1.05;
angle=5*(pi/180);
[x,y]=pol2cart(angle,r) ;
t=x+i*y;
fbus=LD(:,1); % Reading from bus
tbus=LD(:,2); % Reading to bus
r = LD(:,3); % Resistance, R...
x = LD(:,4); % Reactance, X...
gsh=LD(:,5);
B = 1i*LD(:,6); % Ground Admittance
%T=LD(:,7);
Zl=1/(r+(1i*x));
% fb tb Eg Xg Zd
BD = [1 0 0 inf 0.2i
2 0 0 inf 0.4i
3 1 0 inf 1]
fb=BD(:,1);
tb=BD(:,2);
Eg=BD(:,3);
Xg=1i*BD(:,4);
Zd=BD(:,5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
busses=max(max(fbus),max(tbus));
mb=busses;
%zold=zeros(busses,busses)
%for b=1:busses
% z(b,b) = Zd(b) ; %diagonal matrix
%end
for b=1:busses
z(b,b)=[Zd(b)] %diagonal elements
%if the new bus isn't connected to GND
if tb(b)~=0 && b==busses-1 %to not exceed 3 rows and 3 columns
nrow=z(fb(b),:) %repeat row# (the old bus)
ncol=nrow' %new column
ns=length(z) %new size
zz=zeros(ns,ns) %set a zero matrix [ns,ns]
zz(ns,:)=nrow %add the new row to the zero matrix
zz(:,ns) %add the new col to the zero matrix
z(ns,ns)=Zd(b)+ z(fb(b),fb(b)) %the last element of the modified matrix
%= the added Z (Zd) + Z(#of old Bus,#of old Bus)
zz+z %add zz matrix which has the new col and new row,
%with the diagonal matrix
end
%special case: the new bus is connected to GND
if tb(b)==0 && b<busses %b<busses -> to avoid adding the 4th row and col
ncol=zeros(b+1,1); %add a column of zero elements
nrow=zeros(1,b+1); %add a row of zero elements
ns=length(z); %to get the new size
zz=zeros(ns,ns); %the last element of the modified matrix
z(ns,ns)=Zd(b) %if the bus is connected directly to GND,
%the last element is only Zdd (the added one)
z+zz;
end
end
z
The result:
However, element (3x3) should be 1+0.2 = 1.2 (Zd (3) + element (1,1) of z matrix = 0.2)