Skip to content

Commit d5038a4

Browse files
committed
ex goddard ok
1 parent 96f58fe commit d5038a4

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

examples/goddard.jl

+12-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ x0 = [ r0, v0, m0 ]
3737

3838
x(t0) == [ r0, v0, m0 ]
3939
0 u(t) 1
40-
r0 r(t) Inf, (1)
40+
r(t) r0, (1)
4141
0 v(t) vmax, (2)
4242
mf m(t) m0, (3)
4343

@@ -78,7 +78,7 @@ objective!(ocp_f, :mayer, (x0, xf, tf) -> xf[1], :max)
7878

7979
# Direct solve
8080
ocp = ocp_f
81-
N = 10
81+
N = 50
8282
direct_sol = solve(ocp, grid_size=N)
8383

8484
# Plot
@@ -90,17 +90,14 @@ md"![fig](goddard_fig1.png)"
9090
u0 = 0
9191
u1 = 1
9292

93-
H0 = Lift(F0)
94-
H1 = Lift(F1)
93+
H0(x, p) = Lift(F0)(x, p)
94+
H1(x, p) = Lift(F1)(x, p)
9595
H01 = @Poisson {H0, H1}
9696
H001 = @Poisson {H0, H01}
9797
H101 = @Poisson {H1, H01}
9898
us(x, p) = -H001(x, p) / H101(x, p)
9999

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[])
100+
g(x) = vmax - constraint(ocp, :eq2)(x, -1)
104101
ub(x) = -Lie(F0, g)(x) / Lie(F1, g)(x)
105102
μ(x, p) = H01(x, p) / Lie(F1, g)(x)
106103

@@ -115,7 +112,7 @@ shoot!(s, p0, t1, t2, t3, tf) = begin
115112
x2, p2 = fs(t1, x1, p1, t2)
116113
x3, p3 = fb(t2, x2, p2, t3)
117114
xf, pf = f0(t3, x3, p3, tf)
118-
s[1] = constraint(ocp, :eq4)(xf) - mf
115+
s[1] = xf[3] - mf # final mass constraint active
119116
s[2:3] = pf[1:2] - [ 1, 0 ]
120117
s[4] = H1(x1, p1)
121118
s[5] = H01(x1, p1)
@@ -128,12 +125,13 @@ end
128125
t = direct_sol.times
129126
x = direct_sol.state
130127
u = direct_sol.control
131-
p = direct_sol.adjoint
128+
p = direct_sol.costate
129+
H1(t) = H1(x(t), p(t))
132130

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))")
136-
display(plot(u_plot, H1_plot, g_plot, layout=(3,1), size=(400,300)))
131+
u_plot = plot(t, t -> u(t)[1], label = "u(t)")
132+
H1_plot = plot(t, H1, label = "H₁(x(t), p(t))")
133+
g_plot = plot(t, g x, label = "g(x(t))")
134+
display(plot(u_plot, H1_plot, g_plot, layout=(3,1), size=(700,600)))
137135
savefig("goddard_fig2.png")
138136
md"![fig](goddard_fig2.png)"
139137

examples/goddard_fig1.png

3.25 KB
Loading

examples/goddard_fig2.png

17.9 KB
Loading

examples/goddard_fig3.png

-2.95 KB
Loading

src/OptimalControl.jl

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export plot, plot!
4040
export *
4141

4242
# CTBase
43+
export Index
4344
export Autonomous, NonAutonomous
4445
export NonFixed, Fixed
4546
export ControlLaw, FeedbackControl, Multiplier

0 commit comments

Comments
 (0)