-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathY_Bus_from_Impedance_diagram.m
84 lines (69 loc) · 2.57 KB
/
Y_Bus_from_Impedance_diagram.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
% This software will convert the impedance diagram to Y-Bus matrix
% Enter the data and this will prepare the Y-Bus matrix for you
% Down a sample of data should be entered in this fashion
% Coded by: RAHEEM ELSAYED
% From To R X Yc/2
Z = [1 2 0.05 0.15 0.01;
1 3 0.1 0.3 0.02;
2 3 0.15 0.45 0.03;
2 4 0.1 0.3 0.02;
3 4 0.05 0.15 0.01];
% Get the Y-Bus matrix dimensions
buses = max(max(Z(:,1)), max(Z(:,2))); % The max between From and To
% Create the Y-Bus matrix - Initialized to zeros
Y = zeros(buses, buses);
% Some variables used while forming the diagonal element of the Y-Bus matrix
bus = 1;
impedance = 0;
c = 1;
elements = [];
admittance = [];
% Forming the diagonal element
for zrow = 1:max(size(Z))
for irow = 1:max(size(Z))
if ((Z(irow, 1) == bus) || (Z(irow, 2) == bus))
for column = 3:5
if (column == 3)
impedance = Z(irow, 3);
elseif (column == 4)
impedance = impedance + j*Z(irow, 4);
else
admittance(c) = (1/impedance) + Z(irow, column)*j;
c = c + 1;
end
end
end
end
elements(zrow) = sum(admittance);
for k = 1:max(size(admittance))
admittance(k) = 0;
end
c = 1;
bus = bus + 1;
end
% Filter the diagonal elements from any zeros
diagonal = elements(elements~=0);
% Here we form the of-diagonal elements and fill the Y-Bus matrix
for row = 1:buses
for column = 1:buses
if (row == column)
Y(row, column) = diagonal(row);
else
for irow = 1:max(size(Z))
if (((Z(irow, 1) == row) || (Z(irow, 2) == row)) && ((Z(irow, 1) == column) || (Z(irow, 2) == column)))
for xcolumn = 3:5
if (xcolumn == 3)
impedance = Z(irow, 3);
elseif (xcolumn == 4)
impedance = impedance + j*Z(irow, 4);
end
end
Y(row, column) = -1*(1/impedance);
end
end
end
end
end
% Here we display the resulted Y-Bus matrix
disp('Y-Bus Matrix is:');
disp(Y);