-
Notifications
You must be signed in to change notification settings - Fork 2
/
computeLODF.m
167 lines (140 loc) · 4.61 KB
/
computeLODF.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
function [deltPflo,LODFvalues] = computeLODF(Bp, swingbus, branchout, branch)
%computeLODF Computes the Line Outage Distribution Factors
% Description: Computes the LODF (line outage distribution factors) on each
% branch
% Inputs: Admittance Matrix (with the swing bus), swingbus identifier, a
% 1X3 matrix called branchout [branchno frombus tobus], and the branch
% matrix given from wcc9bus
% Outputs: deltPlflo is the LODF matrix without the outage bus eliminated
% LODFvalues contain the final values for the effect of a branch outage on
% all other branches
%------------------------------------
% Formulate the P Matrix
%------------------------------------
D = size(Bp);
P = zeros(D(1),1);
for i=1:D(1)
if i == branchout(1,2) % Add +1 to the from bus
P(i,1) = 1;
else
if i == branchout(1,3) % Add -1 to the to bus
P(i,1) = -1;
else
end;
end;
end;
% Reduce the matrix for the swing bus
Ptemp = zeros(D(1)-1,1);
for i=1:D(1)
if i < swingbus
Ptemp(i,1) = P(i,1) ;
else
if i > swingbus
Ptemp(i-1,1) = P(i,1);
else
end;
end;
end;
P = Ptemp;
%--------------------------------------------------------------------------
% Set-Up B-Prime Matrix Minus Swing Bus
%--------------------------------------------------------------------------
bprimematrixnoswing = zeros(8,8);
for i=1:9
for j = 1:9
if (i ~= swingbus & j ~= swingbus)
if (i < swingbus & j < swingbus)
bprimematrixnoswing(i,j) = Bp(i,j);
else
if (i > swingbus & j < swingbus)
bprimematrixnoswing(i-1,j) = Bp(i,j);
else
if (i < swingbus & j > swingbus)
bprimematrixnoswing(i,j-1) = Bp(i,j);
else
if (i > swingbus & j > swingbus)
bprimematrixnoswing(i-1,j-1) = Bp(i,j);
else
end;
end;
end;
end;
end;
end;
end;
% bprimematrixnoswing holds the matrix with the swing bus removed
%----------------------------------------------------
% Solve for the Theta Values
%----------------------------------------------------
% P = B'*Theta
% Computes the Theta Matrix
thetavalues = bprimematrixnoswing\P;
D = size(thetavalues);
thetavalues2 = zeros(D(1)+1,1);
for i=1:D(1)+1
if i < swingbus
thetavalues2(i,1) = thetavalues(i,1);
else
if i > swingbus
thetavalues2(i,1) = thetavalues(i-1,1);
else
if i == swingbus
thetavalues2(i,1) = 0;
else
end;
end;
end;
end;
% this holds all the delta thetas for each bus including the zero value for
% the swing bus
thetavalues = thetavalues2;
D = size(thetavalues);
thetavalues2 = zeros(D(1),2);
for i=1:D(1)
for j=1:2
if j==1
thetavalues2(i,j) = i;
else
thetavalues2(i,j) = thetavalues(i,1);
end;
end;
end;
thetavalues = thetavalues2;
%----------------------------------------------------
% Calculates the LODF's
%----------------------------------------------------
% Find the Branch Series Reactance
D = size(branch);
branchr = [branch(:,1) zeros(D(1),1) branch(:,2) zeros(D(1),1) branch(:,4)];
D = size(branchr);
F = size(thetavalues);
LODFvalues = [branchr zeros(D(1),1)];
% This part assigns the theta values to the columns corresponding to the
% branch t, from
for i=1:D(1)
for m=1:F(1)
if LODFvalues(i,1) == thetavalues(m,1)
LODFvalues(i,2) = thetavalues(m,2);
else
if LODFvalues(i,3) == thetavalues(m,1)
LODFvalues(i,4) = thetavalues(m,2);
else
end;
end;
end;
end;
% This calculates the LODF in the final column
D = size(LODFvalues);
for i=1:D(1)
LODFvalues(i,6) = (LODFvalues(i,2) - LODFvalues(i,4))/LODFvalues(i,5);
end;
%-----------------------------------------------------------------------
% Final Results
%-----------------------------------------------------------------------
% This is the LODF (nbranch x 1) vector per the assignment
deltPflo = [LODFvalues(:,6)];
i = [1 2 3 4 5 6 7 8 9]';
% This is the LODF (nbranch x 3) including the from bus, to bus, and LODF
LODFvalues = [i LODFvalues(:,1) LODFvalues(:,3) LODFvalues(:,6) ];
LODFvalues(branchout(1),4) = -1;
return;