-
Notifications
You must be signed in to change notification settings - Fork 2
/
project2.m
139 lines (108 loc) · 4.39 KB
/
project2.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
% Project # 2
% Kathleen Williams
% ECE 557
% Determines Topology of the System
[baseMVA, bus, gen, branch, area, gencost] = wscc9bus;
% Determines the Swing Bus
D = size(bus);
swingbus = -1;
for i=1:D(1)
if bus(i,2) == 3;
swingbus = bus(i,1);
else
end;
end;
% swingbus is now a global variable storing the reference bus
%--------------------------------------------------------------------------
% Plan for Branch Out of Service
%--------------------------------------------------------------------------
% Print the Branch Topology
fprintf('\n=============================================');
fprintf('\n| Branch Setup Data |');
fprintf('\n=============================================');
fprintf('\n Branch # \t From Bus \t To Bus \t');
fprintf('\n -------- \t -------- \t -------- ');
for i=1:D(1)-1
fprintf('\n \t%1.0f \t\t\t%1.0f \t\t\t%1.0f ', i, branch(i,1), branch(i,2));
end;
fprintf('\n');
fprintf('\n');
% Ask for a branch to be taken out of service and perform error checking
branchout = -1;
while branchout <= 0 || branchout > 9
branchout = input('Enter the branch number to be taken out of service:');
fprintf('\n');
fprintf('Your have chosen branch number: ');
fprintf('%1.0f', branchout);
fprintf(' to be out of service.');
if branchout >=4 && branchout <= 9
else
fprintf('\n');
fprintf('Your have chosen an invalid branch number: ');
fprintf('\n');
branchout = input('Enter the branch number to be taken out of service:');
fprintf('\n');
fprintf('Your have chosen branch number: ');
fprintf('%1.0f', branchout);
fprintf(' to be out of service.');
end;
end;
% Make a new branch data based on the outaged branch
branchnew = branch;
branchnew(branchout,:)=[];
% branchnew now contains the eliminated branch
% Formulate branch info on out of service
D = size(branch);
branchout2 = [0 0 0];
for i=1:D(1)
if i == branchout
branchout2 = [i branch(i,1) branch(i,2)];
else
end;
end;
branchout = branchout2;
%--------------------------------------------------------------------------
% Set-Up B-Prime Matrix
%--------------------------------------------------------------------------
alg = 2; % BX Method
[Bp, Bpp] = makeB(baseMVA, bus, branchnew, alg);
%--------------------------------------------------------------------------
% LODF Factors
%--------------------------------------------------------------------------
[deltPflo,LODFvalues] = computeLODF(Bp, swingbus, branchout, branch);
fprintf('\n\n');
fprintf('\n=============================================');
fprintf('\n| Line Outage Distribution Factors |');
fprintf('\n=============================================');
fprintf('\n From Bus \tTo Bus \tValue ');
fprintf('\n -------- \t------ \t --------');
D = size(LODFvalues);
for i=1:D(1)
fprintf('\n %1.0f \t\t\t%1.0f \t\t\t%6f', LODFvalues(i,2), LODFvalues(i,3), LODFvalues(i,4));
end;
%--------------------------------------------------------------------------
% Run a Fast-Decoupled Power Flow for the 9-Bus system
%--------------------------------------------------------------------------
options = mpoption('PF_ALG', 2);
[baseMVA, bus, gen, newbranch, success] = runpf('wscc9bus',options);
%--------------------------------------------------------------------------
% Post-Contingency Branch Flows
%--------------------------------------------------------------------------
branchtemp = [];
for i=1:9
branchtemp(i,1) = i;
end;
% Determine the base MW flows taken at the FROM Bus
baseMW = [branchtemp newbranch(:,1) newbranch(:,2) newbranch(:,12)];
% Determines the branch flows
[newbranchflows] = determineBranchFlows2(LODFvalues, baseMW, branchout);
fprintf('\n\n');
fprintf('\n=============================================');
fprintf('\n| Post-Contingency MW branch flows |');
fprintf('\n=============================================');
fprintf('\n \tBranch \tFrom Bus \t To Bus \t MW ');
fprintf('\n \t-------- \t-------- \t--------- \t--------');
D = size(newbranchflows);
for i=1:D(1)
fprintf('\n \t\t%1.0f \t\t\t%1.0f \t\t\t%1.0f \t\t%6f', newbranchflows(i,1), newbranchflows(i,2), newbranchflows(i,3), newbranchflows(i,4));
end