Skip to content

Commit 6bdf512

Browse files
Merge branch 'main' into 0.10.0
2 parents 8cb486e + a9d072d commit 6bdf512

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ makedocs(
2020
prettyurls = false,
2121
size_threshold_ignore = [
2222
"api-ctbase/types.md",
23+
"tutorial-plot.md",
2324
],
2425
assets = [
2526
asset("https://control-toolbox.org/assets/css/documentation.css"),

docs/src/tutorial-iss.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Indirect simple shooting
1+
# [Indirect simple shooting](@id iss)
22

33
In this tutorial we present the indirect simple shooting method on a simple example.
44

@@ -160,7 +160,16 @@ end # hide
160160
nothing # hide
161161
```
162162

163-
We get:
163+
The solution can be plot calling first the flow.
164+
165+
```@example main
166+
sol = φ( (t0, tf), x0, p0_sol )
167+
plot(sol, size=(800, 600))
168+
```
169+
170+
In the indirect shooting method, the research of the optimal control is replaced by the computation
171+
of its associated extremal. This computation is equivalent to finding the initial covector solution
172+
to the shooting function.
164173

165174
```@example main
166175
exp(p0; saveat=[]) = φ((t0, tf), x0, p0, saveat=saveat).ode_sol # hide

docs/src/tutorial-plot.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ plot(sol;
6666
control_style = (color=:red, linewidth=2))
6767
```
6868

69+
## From Flow
70+
71+
The previous resolution of the optimal control problem was done with the `solve` function.
72+
If you use an indirect shooting method and solve shooting equations, you may want to plot the
73+
associated solution. To do so, you need to use the `Flow` function to
74+
reconstruct the solution. See the [Indirect Simple Shooting](@ref iss) tutorial for an example.
75+
In our example, you must provide the maximising control $(x, p) \mapsto p_2$ together with the
76+
optimal control problem.
77+
78+
```@example main
79+
t0 = 0
80+
tf = 1
81+
x0 = [ -1, 0 ]
82+
p0 = sol.costate(t0)
83+
f = Flow(ocp, (x, p) -> p[2])
84+
sol_flow = f( (t0, tf), x0, p0 )
85+
plot(sol_flow)
86+
```
87+
88+
You can notice that the time grid has very few points. To have a better visualisation (the accuracy
89+
won't change), you can give a finer grid.
90+
91+
```@example main
92+
sol_flow = f( (t0, tf), x0, p0; saveat=range(t0, tf, 100) )
93+
plot(sol_flow)
94+
```
95+
6996
## Split versus group layout
7097

7198
If you prefer to get a more compact figure, you can use the `layout` optional keyword argument with `:group` value. It will group the state, costate and control trajectories in one subplot for each.

0 commit comments

Comments
 (0)