Skip to content

Commit 5b17875

Browse files
authored
Merge pull request #383 from control-toolbox/doc-minimal-action
hide and plot
2 parents 2b713f9 + 8a61168 commit 5b17875

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/src/oc_mam.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The system's deterministic dynamics are given by:
2121
# Define the vector field
2222
f(u, v) = [u - u^3 - 10*u*v^2, -(1 - u^2)*v]
2323
f(x) = f(x...)
24+
nothing # hide
2425
```
2526

2627
## Optimal Control Formulation
@@ -41,6 +42,7 @@ function ocp(T)
4142
end
4243
return action
4344
end
45+
nothing # hide
4446
```
4547

4648
## Initial Guess
@@ -61,6 +63,7 @@ u(t) = f(x(t))
6163
6264
# Initial guess
6365
init = (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
106109
objectives = []
107110
Ts = 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)
109112
println(" Time Objective Iterations")
110113
for T=Ts
111114
global sol = solve(ocp(T); display=false, init=sol, grid_size=1000)
@@ -115,8 +118,10 @@ end
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

Comments
 (0)