0% found this document useful (0 votes)
2 views

Bài tập 2

The document provides programming code for the formation of the Ybus matrix in power systems using both transformation and inspection methods, neglecting generator impedance. It includes input data for buses, generators, and branches, and outlines the structure of the Ybus matrix. The results of the Ybus calculations are also presented, showing the complex admittance values between buses.

Uploaded by

Việt Toàn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Bài tập 2

The document provides programming code for the formation of the Ybus matrix in power systems using both transformation and inspection methods, neglecting generator impedance. It includes input data for buses, generators, and branches, and outlines the structure of the Ybus matrix. The results of the Ybus calculations are also presented, showing the complex admittance values between buses.

Uploaded by

Việt Toàn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

c. Guess and describe the meaning of code.

I = [1 1 2 0.6 0 0
2 1 3 0.5 1 0 .1
3 3 4 0.5 0 0
4 1 2 0.4 1 0.2
5 2 4 0.2 0 0 ] % I matrix is input matrix
Ground = 1 % bus 1 is selected as a reference

Programming code for bus formulation

function[Ybus] = yformation(I,ground)
numele=length(I(:,1)) % number of element = length of column 1 of I matrix
idxbus = unique([I(:,2);I(:,3)])' % listing buses
numbus=length(idxbus) % number of buses
A=zeros(numele,numbus) % building  matrix with number of rows = number of
for k=1:numele % elements and number of columns = number of buses
a=find(idxbus==I(k,2)) % Updating  matrix by filling 1 if current go from bus
b=find(idxbus==I(k,3)) % (column 2 of I matrix) and -1 if current go to bus
A(k,a)=1 % (column 3 of I matrix)
A (k,b)=-1
end
r= find(idxbus==ground) % Choosing referenced bus
idxbus(r)=[]
A(:,r)=[] % deleting the column that is selected as a reference for A
zprim=diag(I(:,4)) % Building Zprim diagonalMatrix with self impedance from
for k=1:numele % column 4 of I matrix
if I(k,5)~=0 % finding element that is correlate with element 1 to fill
cp=I(k,5) % mutual impedance to correlate address in Zprim Matrix.
zprim(k,cp)=I(k,6) % Addresses come from column 5 of I matrix and value
zprim(cp,k)=I(k,6) % come from column 6 of I matrix.
end
end
yprim=inv(zprim) % Inverse Zprim to have Yprim
Ybus=A'*yprim*A % Calculate Ybus = AT*Yprim*A

Return
Exercise 2. Given input data of power system as follow:
%bus type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin

bus = [

1 1 40.0 15.0 0.0 0.0 1 1.0000 0.0000 230.0000 1 1.0500 0.9500;

2 3 25.0 10.0 0.0 0.0 1 1.0000 0.0000 230.0000 1 1.0500 0.9500;

3 2 60.0 30.0 0.0 0.0 1 1.0000 0.0000 230.0000 1 1.0500 0.9500;

4 1 70.0 25.0 0.0 0.0 1 1.0000 0.0000 230.0000 1 1.0500 0.9500 ];

%% generator data

% bus Pg Qg Qmax Qmin Vsp base status Pmax Pmin

gen = [

2 85.00 19.22 150.0000 -150.0000 1.050 100.0000 1 200.0000 50.0000;

3 110.00 67.43 150.0000 -150.0000 1.050 100.0000 1 200.0000 50.0000 ];

%% branch data

% fbus tbus r x b ratea rateb ratec ratio angle status

branch = [

1 2 0.20 0.60 0.0010 40.0000 40.0000 250.0000 0.0000 0.0000 1;

1 2 0.20 0.60 0.0010 40.0000 40.0000 250.0000 0.0000 0.0000 1;

1 3 0.10 0.20 0.0000 80.0000 80.0000 150.0000 0.0000 0.0000 1;

2 3 0.07 0.20 0.0000 60.0000 60.0000 150.0000 0.0000 0.0000 1;

2 4 0.05 0.25 0.0000 100.000 100.000 150.0000 0.0000 0.0000 1;

3 4 0.04 0.20 0.0010 50.0000 50.0000 150.0000 0.0000 0.0000 1;

3 4 0.04 0.20 0.0010 50.0000 50.0000 150.0000 0.0000 0.0000 1 ];

a. Draw a single line diagram of this power system.


b. Programming code for Ybus formulation of this power system by transformation method

This code neglect the impedance of generators

function [Ybus]= yformation3(branch)


c=0
numele=length(branch(:,1))
dem=0
for k=1:numele
if branch(k,5)~=0
c=c+1
end
end
sumele=numele+2*c
idxbus=unique([branch(:,1);branch(:,2)])'
numbus=length(idxbus)
A=zeros(sumele,numbus)
for k=1:numele
m=find(idxbus==branch(k,1))
n=find(idxbus==branch(k,2))
A(k,m)=1
A(k,n)=-1
end
Zprim=zeros(sumele,sumele)
for k=1:numele
Zprim(k,k)=branch(k,3)+i*branch(k,4)
end
for k=1:numele
if branch(k,5)~=0
m=find(idxbus==branch(k,1))
dem=dem+1
A((numele+dem),m)=-1
Zprim((numele+dem),(numele+dem))=2/(i*branch(k,5))
n=find(idxbus==branch(k,2))
dem=dem+1
A((numele+dem),n)=-1
Zprim((numele+dem),(numele+dem))=2/(i*branch(k,5))
end
end
Yprim=inv(Zprim)
Ybus=A'*Yprim*A

The Result Ybus =

3.0000 - 6.9990i -1.0000 + 3.0000i -2.0000 + 4.0000i 0.0000 + 0.0000i

-1.0000 + 3.0000i 3.3283 -11.2995i -1.5590 + 4.4543i -0.7692 + 3.8462i

-2.0000 + 4.0000i -1.5590 + 4.4543i 5.4821 -18.0687i -1.9231 + 9.6154i

0.0000 + 0.0000i -0.7692 + 3.8462i -1.9231 + 9.6154i 2.6923 -13.4605i


c. Programming code for Ybus formulation of this power system by inspection method

This code neglect the impedance of generators

function [Ybus] = yformation2(branch)


idxbus=unique([branch(:,1);branch(:,2)])';
numbus=length(idxbus);
numele=length(branch(:,1));
Ybus=zeros(numbus,numbus); % Building Ybus Matrix
for k=1:numele % Filling admittance between two buses
m=find(idxbus==branch(k,1));
n=find(idxbus==branch(k,2));
ymn=1/(branch(k,3)+i*branch(k,4));
Ybus(m,m)=Ybus(m,m)+ymn;
Ybus(n,n)=Ybus(n,n)+ymn;
Ybus(m,n)=Ybus(m,n)-ymn;
Ybus(n,m)=Ybus(m,n);
if branch(k,5)~=0 % adding admittance jb to addressed buses
Ybus(m,m)=Ybus(m,m)+i*branch(k,5)/2;
Ybus(n,n)=Ybus(n,n)+i*branch(k,5)/2;
end
end

Result Ybus =

3.0000 - 6.9990i -1.0000 + 3.0000i -2.0000 + 4.0000i 0.0000 + 0.0000i


-1.0000 + 3.0000i 3.3283 -11.2995i -1.5590 + 4.4543i -0.7692 + 3.8462i
-2.0000 + 4.0000i -1.5590 + 4.4543i 5.4821 -18.0687i -1.9231 + 9.6154i
0.0000 + 0.0000i -0.7692 + 3.8462i -1.9231 + 9.6154i 2.6923 -13.4605i

You might also like