Skip to content

Commit 9f3c4e6

Browse files
committed
hide and plot
1 parent 2b713f9 commit 9f3c4e6

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ CTDirect = "790bbbee-bee9-49ee-8912-a9de031322d5"
99
CTFlows = "1c39547c-7794-42f7-af83-d98194f657c2"
1010
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
1111
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
12+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
13+
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1214

1315
[compat]
1416
CTBase = "0.13"
1517
CTDirect = "0.12"
1618
CTFlows = "0.6"
1719
CommonSolve = "0.2"
1820
DocStringExtensions = "0.9"
21+
Plots = "1.40.9"
22+
Printf = "1.11.0"
1923
julia = "1.10"

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)