-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pstate.m
129 lines (122 loc) · 4.23 KB
/
Pstate.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
function Psat = Pstate(Ps, Pr, Ec, Ecshift, tfe, v_pre, v, dirv_pre, dirv, Pstate_pre, Es, TUV, TDV, PUP, PDP, TU_Size, TD_Size, TU_Size_eff, TD_Size_eff, flagu, flagd)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
Eafe = v / tfe;
try
if dirv == 1
if dirv_pre == dirv
if Eafe < TUV(TU_Size) && flagu == 1
TUV(TU_Size + 1) = Eafe;
PUP(TU_Size + 1) = Pstate_pre;
TU_Size = TU_Size + 1;
TU_Size_eff = TU_Size - 1;
TD_Size_eff = TD_Size;
flagu = -1;
elseif TU_Size > 1 && Eafe < TUV(TU_Size - 1)
TUV(TU_Size) = Eafe;
PUP(TU_Size) = Pstate_pre;
TU_Size_eff = TU_Size - 1;
TD_Size_eff = TD_Size;
else
TUV(TU_Size) = 0;
TUV(TU_Size - 1) = 0;
PUP(TU_Size) = 0;
PUP(TU_Size - 1) = 0;
TU_Size = TU_Size - 2;
TDV(TD_Size) = 0;
PDP(TD_Size) = 0;
TD_Size = TD_Size - 1;
TUV(TU_Size + 1) = Eafe;
PUP(TU_Size + 1) = Pstate_pre;
TU_Size = TU_Size + 1;
TU_Size_eff = TU_Size - 1;
TD_Size_eff = TD_Size;
end
flagd = 1;
end
elseif dirv == -1
if dirv_pre == dirv
if Eafe > TDV(TD_Size) && flagd == 1
TDV(TD_Size + 1) = Eafe;
PDP(TD_Size + 1) = Pstate_pre;
TD_Size = TD_Size + 1;
TD_Size_eff = TD_Size - 1;
TU_Size_eff = TU_Size;
flagd = -1;
elseif TD_Size > 1 && Eafe > TDV(TD_Size - 1)
TDV(TD_Size) = Eafe;
PDP(TD_Size) = Pstate_pre;
TD_Size_eff = TD_Size - 1;
TU_Size_eff = TU_Size;
else
TDV(TD_Size) = 0;
TDV(TD_Size - 1) = 0;
PDP(TD_Size) = 0;
PDP(TD_Size - 1) = 0;
TD_Size = TD_Size - 2;
TUV(TU_Size) = 0;
PUP(TU_Size) = 0;
TU_Size = TU_Size-1;
TDV(TD_Size + 1) = Eafe;
PDP(TD_Size + 1) = Pstate_pre;
TD_Size = TD_Size + 1;
TD_Size_eff = TD_Size - 1;
TU_Size_eff = TU_Size;
end
flagu = 1;
end
end
catch
Es = 20e6;
TUV = [Es];
TDV = [-Es];
PUP = [Ps];
PDP = [-Ps];
TU_Size = 1;
TD_Size = 1;
TU_Size_eff = TU_Size;
TD_Size_eff = TD_Size;
flagu = 1;
flagd = 1;
end
if sign(v) == 1 && sign(v_pre) == -1
TUV = [Es];
TDV = [-Es];
PUP = [Ps];
PDP = [-Ps];
TU_Size = 1;
TD_Size = 1;
TU_Size_eff = TU_Size;
TD_Size_eff = TD_Size;
flagu = 1;
flagd = -1;
elseif sign(v) == -1 && sign(v_pre) == 1
TUV = [Es];
TDV = [-Es];
PUP = [Ps];
PDP = [-Ps];
TU_Size = 1;
TD_Size = 1;
TU_Size_eff = TU_Size;
TD_Size_eff = TD_Size;
flagu = -1;
flagd = 1;
end
try
if dirv == 1
Psat = Psub(Ps, Pr, Ec, Ecshift, TUV(TU_Size_eff), TDV(TD_Size), PUP(TU_Size_eff), PDP(TD_Size), Eafe, dirv);
else
Psat = Psub(Ps, Pr, Ec, Ecshift, TUV(TU_Size), TDV(TD_Size_eff), PUP(TU_Size), PDP(TD_Size_eff), Eafe, dirv);
end
catch
Psat = Pstate_pre;
end
% if abs(Psat - Pstate_pre) > 1e-7
% dirv = -dirv;
% if dirv == 1
% Psat = Psub(Ps, Pr, Ec, Ecshift, TUV(TU_Size_eff), TDV(TD_Size), PUP(TU_Size_eff), PDP(TD_Size), Eafe, dirv);
% else
% Psat = Psub(Ps, Pr, Ec, Ecshift, TUV(TU_Size), TDV(TD_Size_eff), PUP(TU_Size), PDP(TD_Size_eff), Eafe, dirv);
% end
% end
end