Skip to content

Commit e0f2cbe

Browse files
committed
docs: improve flow documentation formatting
- Clean up line breaks and spacing in manual-flow-ocp.md - Remove unnecessary blank lines and improve readability - Consolidate multiline text for better formatting
1 parent 88b97d5 commit e0f2cbe

1 file changed

Lines changed: 14 additions & 32 deletions

File tree

docs/src/manual-flow-ocp.md

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ where $p^0 = -1$ since we are in the normal case. From the Pontryagin maximum pr
4545
u(x, p) = p_v
4646
```
4747

48-
since $\partial^2_{uu} H = p^0 = - 1 < 0$.
48+
since $\partial^2_{uu} H = p^0 = - 1 < 0$.
4949

5050
```@example main
5151
u(x, p) = p[2]
5252
nothing # hide
5353
```
5454

55-
Actually, if $(x, u)$ is a solution of the optimal control problem,
56-
then, the Pontryagin maximum principle tells us that there exists a costate $p$ such that $u(t) = u(x(t), p(t))$
57-
and such that the pair $(x, p)$ satisfies:
55+
Actually, if $(x, u)$ is a solution of the optimal control problem, then, the Pontryagin maximum principle tells us that there exists a costate $p$ such that $u(t) = u(x(t), p(t))$ and such that the pair $(x, p)$ satisfies:
5856

5957
```math
6058
\begin{array}{l}
@@ -81,9 +79,7 @@ julia> f = Flow(ocp, u)
8179
ERROR: ExtensionError. Please make: julia> using OrdinaryDiffEq
8280
```
8381

84-
As you can see, an error occurred since we need the package [OrdinaryDiffEq.jl](https://docs.sciml.ai/DiffEqDocs).
85-
This package provides numerical integrators to compute solutions of the ordinary differential equation
86-
$\dot{z}(t) = \vec{\mathbf{H}}(z(t))$.
82+
As you can see, an error occurred since we need the package [OrdinaryDiffEq.jl](https://docs.sciml.ai/DiffEqDocs). This package provides numerical integrators to compute solutions of the ordinary differential equation $\dot{z}(t) = \vec{\mathbf{H}}(z(t))$.
8783

8884
!!! note "OrdinaryDiffEq.jl"
8985

@@ -110,9 +106,7 @@ sol = f((t0, tf), x0, p0)
110106
nothing # hide
111107
```
112108

113-
In this case, you obtain a data that you can plot exactly like when solving the optimal control problem
114-
with the function [`solve`](@ref). See for instance the [basic example](@ref example-double-integrator-energy-solve-plot) or the
115-
[plot tutorial](@ref manual-plot).
109+
In this case, you obtain a data that you can plot exactly like when solving the optimal control problem with the function [`solve`](@ref). See for instance the [basic example](@ref example-double-integrator-energy-solve-plot) or the [plot tutorial](@ref manual-plot).
116110

117111
```@example main
118112
using Plots
@@ -136,11 +130,7 @@ sol = f((t0, tf), x0, p0; saveat=range(t0, tf, 100))
136130
plot(sol)
137131
```
138132

139-
The argument `saveat` is an option from OrdinaryDiffEq.jl. Please check the
140-
[list of common options](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#solver_options).
141-
For instance, one can change the integrator with the keyword argument `alg` or the absolute tolerance with
142-
`abstol`. Note that you can set an option when declaring the flow or set an option in a particular call of the flow.
143-
In the following example, the integrator will be `BS5()` and the absolute tolerance will be `abstol=1e-8`.
133+
The argument `saveat` is an option from OrdinaryDiffEq.jl. Please check the [list of common options](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#solver_options). For instance, one can change the integrator with the keyword argument `alg` or the absolute tolerance with `abstol`. Note that you can set an option when declaring the flow or set an option in a particular call of the flow. In the following example, the integrator will be `BS5()` and the absolute tolerance will be `abstol=1e-8`.
144134

145135
```@example main
146136
f = Flow(ocp, u; alg=BS5(), abstol=1) # alg=BS5(), abstol=1
@@ -179,7 +169,7 @@ The pseudo-Hamiltonian of this problem is
179169
H(t, x, p, u) = p\, u\, (1+\tan\, t) + p^0 u^2 /2,
180170
```
181171

182-
where $p^0 = -1$ since we are in the normal case. We can notice that the pseudo-Hamiltonian is non-autonomous since it explicitly depends on the time $t$.
172+
where $p^0 = -1$ since we are in the normal case. We can notice that the pseudo-Hamiltonian is non-autonomous since it explicitly depends on the time $t$.
183173

184174
```@example main
185175
is_autonomous(ocp)
@@ -191,15 +181,14 @@ From the Pontryagin maximum principle, the maximising control is given in feedba
191181
u(t, x, p) = p\, (1+\tan\, t)
192182
```
193183

194-
since $\partial^2_{uu} H = p^0 = - 1 < 0$.
184+
since $\partial^2_{uu} H = p^0 = - 1 < 0$.
195185

196186
```@example main
197187
u(t, x, p) = p * (1 + tan(t))
198188
nothing # hide
199189
```
200190

201-
As before, the `Flow` function aims to compute $(x, p)$ from the optimal control problem `ocp` and the control in feedback form `u(t, x, p)`.
202-
Since the problem is non-autonomous, we must provide a control law that depends on time.
191+
As before, the `Flow` function aims to compute $(x, p)$ from the optimal control problem `ocp` and the control in feedback form `u(t, x, p)`. Since the problem is non-autonomous, we must provide a control law that depends on time.
203192

204193
```@example main
205194
f = Flow(ocp, u)
@@ -239,8 +228,7 @@ end
239228
nothing # hide
240229
```
241230

242-
As you can see, the variable is the final time `tf`. Note that the dynamics depends on `tf`.
243-
From the Pontryagin maximum principle, the solution is given by:
231+
As you can see, the variable is the final time `tf`. Note that the dynamics depends on `tf`. From the Pontryagin maximum principle, the solution is given by:
244232

245233
```@example main
246234
tf = (3/2)^(1/4)
@@ -262,8 +250,7 @@ f = Flow(ocp, u)
262250
xf, pf = f(t0, x0, p0, tf, tf)
263251
```
264252

265-
The usage of the flow `f` is the following: `f(t0, x0, p0, tf, v)` where `v` is the variable. If one wants
266-
to compute the state at time `t1 = 0.5`, then, one must write:
253+
The usage of the flow `f` is the following: `f(t0, x0, p0, tf, v)` where `v` is the variable. If one wants to compute the state at time `t1 = 0.5`, then, one must write:
267254

268255
```@example main
269256
t1 = 0.5
@@ -278,8 +265,7 @@ x1, p1 = f(t0, x0, p0, t1, tf)
278265
xf, pf = f(t0, x0, p0, tf)
279266
```
280267

281-
Since the variable is the final time, we can make the time-reparameterisation $t = s\, t_f$ to normalise
282-
the time $s$ in $[0, 1]$.
268+
Since the variable is the final time, we can make the time-reparameterisation $t = s\, t_f$ to normalise the time $s$ in $[0, 1]$.
283269

284270
```@example main
285271
ocp = @def begin
@@ -334,7 +320,6 @@ yf, pf = f(0, [x0, tf], [p0, 0], 1)
334320

335321
In the [Goddard problem](https://control-toolbox.org/Tutorials.jl/stable/tutorial-goddard.html#tutorial-goddard-structure), you may find other constructions of flows, especially for singular and boundary arcs.
336322

337-
338323
## Concatenation of arcs
339324

340325
In this part, we present how to concatenate several flows. Let us consider the following problem.
@@ -362,8 +347,7 @@ end
362347
nothing # hide
363348
```
364349

365-
From the Pontryagin maximum principle, the optimal control is a concatenation of an off arc ($u=0$) followed by a
366-
positive bang arc ($u=1$). The initial costate is
350+
From the Pontryagin maximum principle, the optimal control is a concatenation of an off arc ($u=0$) followed by a positive bang arc ($u=1$). The initial costate is
367351

368352
```math
369353
p_0 = \frac{1}{x_0 - (x_f-1) e^{t_f}}
@@ -420,7 +404,7 @@ plot!(plt, t, t->abs(ψ(t)-x0), label="Classical")
420404

421405
## State constraints
422406

423-
We consider an optimal control problem with a state constraints of order 1.[^1]
407+
We consider an optimal control problem with a state constraints of order 1.[^1]
424408

425409
[^1]: B. Bonnard, L. Faubourg, G. Launay & E. Trélat, Optimal Control With State Constraints And The Space Shuttle Re-entry Problem, J. Dyn. Control Syst., 9 (2003), no. 2, 155–199.
426410

@@ -457,7 +441,6 @@ The pseudo-Hamiltonian of this problem is
457441

458442
where $ p^0 = -1 $ since we are in the normal case, and where $c(x) = x - l_b$. Along a boundary arc, when $c(x(t)) = 0$, we have $x(t) = l_b$, so $ x(\cdot) $ is constant. Differentiating, we obtain $\dot{x}(t) = u(t) = 0$. Hence, along a boundary arc, the control in feedback form is:
459443

460-
461444
```math
462445
u(x) = 0.
463446
```
@@ -534,7 +517,6 @@ The pseudo-Hamiltonian of this problem is
534517

535518
where $ p^0 = -1 $ since we are in the normal case, and where the constraint is $c(x) = l - x_1 \ge 0$. Along a boundary arc, when $c(x(t)) = 0$, we have $x_1(t) = l$, so $\dot{x}_1(t) = x_2(t) = 0$. Differentiating again, we obtain $\dot{x}_2(t) = u(t) = 0$ (the constraint is of order 2). Hence, along a boundary arc, the control in feedback form is:
536519

537-
538520
```math
539521
u(x, p) = 0.
540522
```
@@ -584,4 +566,4 @@ plot(direct_sol; label="direct", size=(800, 700))
584566
585567
flow_sol = f((t0, tf), x0, p0; saveat=range(t0, tf, 100))
586568
plot!(flow_sol; label="flow", state_style=(color=3,), linestyle=:dash)
587-
```
569+
```

0 commit comments

Comments
 (0)