Bài tập 2
Bài tập 2
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
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 = [
%% generator data
gen = [
%% branch data
branch = [
Result Ybus =