-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject3.m
86 lines (66 loc) · 3.92 KB
/
project3.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
%==========================================================================
% Project # 3
% Kathleen E. Williams
% ECE 557
%==========================================================================
%--------------------------------------------------------------------------
% Run a Fast-Decoupled Power Flow for the 9-Bus system Base Case
%--------------------------------------------------------------------------
options = mpoption('PF_ALG', 2);
[baseMVA, bus, gen, branch, success] = runpf('wscc9bus',options);
%--------------------------------------------------------------------------
% Generator Outage - Ask for a generator to be out
%--------------------------------------------------------------------------
[gennew, genout] = genout(gen);
gen = gennew;
%--------------------------------------------------------------------------
% Setup Base Case Complex Voltage without Generator Outage
%--------------------------------------------------------------------------
Vm = bus(:,8); % This is the voltage magnitude column
Va = bus(:,9); % This is the column of voltage values
Va = Va.*pi/180; % Convert the bus angle to radians
V = Vm .* exp(sqrt(-1) * Va); % This is the complex voltage
%--------------------------------------------------------------------------
% Set-Up B-Prime Matrix, Sbus, Ybus
%--------------------------------------------------------------------------
branch(genout,4) = 100000000000;
branch(genout,3) = 100000000000;
alg = 2; % BX Method
[Bp, Bpp] = makeB(baseMVA, bus, branch, alg);
Sbus = makeSbus(baseMVA, bus, gen);
[Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch);
%--------------------------------------------------------------------------
% Retrieve bus type reference matrices
%--------------------------------------------------------------------------
[ref, pv, pq] = bustypes(bus, gen);
%-------------------------------------------------------------------------
% 1P half-iteration
%-------------------------------------------------------------------------
[V,Va] = Pit(V,Ybus,Sbus,pv,pq,bus,Bp,Vm,Va);
updatedvalues1P = [bus(:,1) abs(V) angle(V)]
%--------------------------------------------------------------------------
% 1Q half-iteration
%--------------------------------------------------------------------------
[V] = Qit(V,Ybus,Sbus,pv,pq,bus,Bpp,Vm,Va);
updatedvalues1Q = [bus(:,1) abs(V) angle(V)]
%-------------------------------------------------------------------------
% Compute Branch Flows
%-------------------------------------------------------------------------
[br, Sf, St] = computebranchflows(bus,gen,branch,V,Yf,Yt,baseMVA);
%--------------------------------------------------------------------------
% Display Branch Flows
%--------------------------------------------------------------------------
format short g;
D = size(Sf);
fprintf('\n');
fprintf('\n');
fprintf('\n=============================================================================================================================================');
fprintf('\n| Fast-Decoupled 1P1Q Estimated Branch flows |');
fprintf('\n=============================================================================================================================================');
fprintf('\n From Bus \t To Bus \t From Bus Real Power (MW) \t From Bus Reactive Power (MVAR) \t To Bus Real Power (MW) \t To Bus Reactive Power (MVAR)');
fprintf('\n --------- \t ------- \t ------------------------ \t ------------------------------ \t ---------------------- \t ----------------------------');
for i=1:D(1)
fprintf('\n \t%1.0f \t\t\t%1.0f \t\t\t\t%6f \t\t\t\t\t%6f \t\t\t\t\t\t%6f \t\t\t\t\t%6f', branch(i,1), branch(i,2), real(Sf(i,1)), imag(Sf(i,1)), real(St(i,1)), imag(St(i,1)));
end;
fprintf('\n');
fprintf('\n');