19
19
vmax = 0.1
20
20
m0 = 1
21
21
mf = 0.6
22
+
23
+ # Initial state
22
24
x0 = [ r0, v0, m0 ]
23
25
24
26
# Abstract model
@@ -35,9 +37,9 @@ x0 = [ r0, v0, m0 ]
35
37
36
38
x (t0) == [ r0, v0, m0 ]
37
39
0 ≤ u (t) ≤ 1
38
- r0 ≤ r (t) ≤ Inf , (1 )
39
- 0 ≤ v (t) ≤ vmax, (2 )
40
- mf ≤ m (t) ≤ m0, (3 )
40
+ r0 ≤ r (t) ≤ Inf , (1 )
41
+ 0 ≤ v (t) ≤ vmax, (2 )
42
+ mf ≤ m (t) ≤ m0, (3 )
41
43
42
44
ẋ (t) == F0 (x (t)) + u (t) * F1 (x (t))
43
45
48
50
F0 (x) = begin
49
51
r, v, m = x
50
52
D = Cd * v^ 2 * exp (- β* (r - 1 ))
51
- F = [ v, - D/ m - 1 / r^ 2 , 0 ]
52
- return F
53
+ return [ v, - D/ m - 1 / r^ 2 , 0 ]
53
54
end
54
55
55
56
F1 (x) = begin
56
57
r, v, m = x
57
- F = [ 0 , Tmax/ m, - b* Tmax ]
58
- return F
58
+ return [ 0 , Tmax/ m, - b* Tmax ]
59
59
end
60
60
61
61
# Functional model
@@ -87,27 +87,27 @@ savefig("goddard_fig1.png")
87
87
md " "
88
88
89
89
# Shooting function
90
- u0 (x, p) = 0.
91
- u1 (x, p) = 1.
92
-
93
- H0 (x, p) = p ' * F0 (x )
94
- H1 (x, p) = p ' * F1 (x )
95
- H01 = Poisson ( H0, H1)
96
- H001 = Poisson ( H0, H01)
97
- H101 = Poisson ( H1, H01)
90
+ u0 = 0
91
+ u1 = 1
92
+
93
+ H0 = Lift (F0 )
94
+ H1 = Lift (F1 )
95
+ H01 = @ Poisson { H0, H1}
96
+ H001 = @ Poisson { H0, H01}
97
+ H101 = @ Poisson { H1, H01}
98
98
us (x, p) = - H001 (x, p) / H101 (x, p)
99
99
100
- remove_constraint! (ocp, :eq1 )
101
- remove_constraint! (ocp, :eq3 )
102
- constraint! (ocp, :final , Index (3 ), mf, :eq4 )
103
- g (x) = vmax - constraint (ocp, :eq2 )(x)
104
- ub (x, _) = - Ad (F0, g)(x) / Ad (F1, g)(x)
105
- μb (x, p) = H01 (x, p) / Ad (F1, g)(x)
100
+ # remove_constraint!(ocp, :eq1)
101
+ # remove_constraint!(ocp, :eq3)
102
+ # constraint!(ocp, :final, Index(3), mf, :eq4)
103
+ g (x) = vmax - constraint (ocp, :eq2 )(x, Real[] )
104
+ ub (x) = - Lie (F0, g)(x) / Lie (F1, g)(x)
105
+ μ (x, p) = H01 (x, p) / Lie (F1, g)(x)
106
106
107
- f0 = Flow (ocp, u0)
108
- f1 = Flow (ocp, u1)
109
- fs = Flow (ocp, us )
110
- fb = Flow (ocp, ub , (x, _ ) -> g (x), μb )
107
+ f0 = Flow (ocp, (x, p, tf) -> u0)
108
+ f1 = Flow (ocp, (x, p, tf) -> u1)
109
+ fs = Flow (ocp, (x, p, tf) -> us (x, p) )
110
+ fb = Flow (ocp, (x, p, tf) -> ub (x) , (x, u, tf ) -> g (x), (x, p, tf) -> μ (x, p) )
111
111
112
112
shoot! (s, p0, t1, t2, t3, tf) = begin
113
113
@@ -129,11 +129,10 @@ t = direct_sol.times
129
129
x = direct_sol. state
130
130
u = direct_sol. control
131
131
p = direct_sol. adjoint
132
- H1 (t) = H1 (x (t), p (t))
133
132
134
- u_plot = plot (t, t -> u (t)[ 1 ], xlabel = " t " , ylabel = " u " , legend = false )
135
- H1_plot = plot (t, H1, xlabel = " t " , ylabel = " H1 " , legend = false )
136
- g_plot = plot (t, g ∘ x, xlabel = " t " , ylabel = " g " , legend = false )
133
+ u_plot = plot (t, u, label = " u(t) " )
134
+ H1_plot = plot (t, t -> H1 ( x (t), p (t)), label = " H₁(x(t), p(t)) " )
135
+ g_plot = plot (t, g ∘ x, label = " g(x(t)) " )
137
136
display (plot (u_plot, H1_plot, g_plot, layout= (3 ,1 ), size= (400 ,300 )))
138
137
savefig (" goddard_fig2.png" )
139
138
md " "
0 commit comments