-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pit.m
104 lines (86 loc) · 2.93 KB
/
Pit.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
function [V,Va,swingbus] = Pit(V,Ybus,Sbus,pv,pq,bus,Bp,Vm,Va)
%Pit Performs 1P
% Input: complex voltage V vector, Ybus, Sbus, pv, pq, bus, Bpp,Vm,Va
% Outputs:complex voltage V vector, the voltage angle Va, the swing bus
%--------------------------------------------------------------------------
% Compute the Real Power MisMatch
%--------------------------------------------------------------------------
mis = V .* conj(Ybus * V) - Sbus;
delP=-real(mis([pv; pq]));
%--------------------------------------------------------------------------
% Set-Up B-Prime Matrix Minus Swing Bus
%--------------------------------------------------------------------------
% 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;
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
% Reduce the Vm matrix for the swing bus
Vmtemp = zeros(8,1);
for i=1:9
if i < swingbus
Vmtemp(i,1) = Vm(i,1) ;
else
if i > swingbus
Vmtemp(i-1,1) = Vm(i,1);
else
end;
end;
end;
%-------------------------------------------------------------------------
% Computes the delTheta
%-------------------------------------------------------------------------
delTheta = bprimematrixnoswing\(delP./Vmtemp);
%-------------------------------------------------------------------------
% Augment the delTheta matrix for the swing bus
%-------------------------------------------------------------------------
delTheta2 = zeros(9,1);
for i=1:9
if i < swingbus
delTheta2(i,1) = delTheta(i,1);
else
if i > swingbus
delTheta2(i,1) = delTheta(i-1,1);
else
if i == swingbus
delTheta2(i,1) = 0;
else
end;
end;
end;
end;
delTheta = delTheta2;
%-------------------------------------------------------------------------
% Update Complex Voltage
%-------------------------------------------------------------------------
Va = Va + delTheta;
V = Vm .* exp(sqrt(-1) * Va); % This is the complex voltage
return;