@@ -21,6 +21,7 @@ The system's deterministic dynamics are given by:
2121# Define the vector field
2222f(u, v) = [u - u^3 - 10*u*v^2, -(1 - u^2)*v]
2323f(x) = f(x...)
24+ nothing # hide
2425```
2526
2627## Optimal Control Formulation
@@ -41,6 +42,7 @@ function ocp(T)
4142 end
4243 return action
4344end
45+ nothing # hide
4446```
4547
4648## Initial Guess
@@ -61,6 +63,7 @@ u(t) = f(x(t))
6163
6264# Initial guess
6365init = (state=x, control=u)
66+ nothing # hide
6467```
6568
6669## Solving the Problem
@@ -105,7 +108,7 @@ To find the maximum likelihood path, we also need to minimize the transient time
105108``` @example oc_mam
106109objectives = []
107110Ts = range(1,100,100)
108- sol = solve(ocp(Ts[1]); init=init, grid_size=50)
111+ sol = solve(ocp(Ts[1]); display=false, init=init, grid_size=50)
109112println(" Time Objective Iterations")
110113for T=Ts
111114 global sol = solve(ocp(T); display=false, init=sol, grid_size=1000)
115118```
116119
117120``` @example oc_mam
118- @show Ts[argmin(objectives)]
119- plt1 = scatter(Ts, log10.(objectives))
120- plt2 = scatter(Ts[20:100], log10.(objectives[20:100]))
121- plot(plt1,plt2)
121+ T_min = Ts[argmin(objectives)]
122+ plt1 = scatter(Ts, log10.(objectives), xlabel="Time", label="Objective (log10)")
123+ vline!(plt1, [T_min], label="Minimum", z_order=:back)
124+ plt2 = scatter(Ts[20:100], log10.(objectives[20:100]), xlabel="Time", label="Objective (log10)")
125+ vline!(plt2, [T_min], label="Minimum", z_order=:back)
126+ plot(plt1, plt2, layout=(2,1), size=(800,800))
122127```
0 commit comments