-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget_Ybus.m
34 lines (26 loc) · 1.06 KB
/
get_Ybus.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
%%
%Function get_Ybus
%Creates admittance matrix given dataset of resistances, reactances, and
%susceptances.
%Inputs:
%data: matrix containing the given data
%R: Number of the column in 'data' containing Resistance
%X: Number of the column in 'data' containing Reactance
%B: Number of the column in 'data' containing Susceptance
%system_size: Number of buses in the system
function Ybus = get_Ybus(data, R, X, B, system_size)
Ybus = zeros(system_size, system_size);
i=1;
while(data(i, 1) ~= 0)
to = data(i, 1);
from = data(i, 2);
%Adds series + shunt admittances to diagonal component for TO bus
Ybus(to, to) = Ybus(to, to) + 1/(data(i, R) + 1i*data(i, X)) + 1i*0.5*data(i, B);
%Adds series + shunt admittances to diagonal component for FROM bus
Ybus(from, from) = Ybus(from, from) + 1/(data(i, R) + 1i*data(i, X)) + 1i*0.5*data(i, B);
%Creates mutual admittance entries
Ybus(to, from) = -1/(data(i, R) + 1i*data(i, X));
Ybus(from, to) = Ybus(to, from);
i=i+1;
end
end