You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Rename variables for clarity: indirect_sol → minpack_sol, sol → sciml_sol, flow_sol → indirect_sol
- Move BenchmarkTools import to benchmarking section
- Add cross-reference to tutorial-iss for indirect shooting introduction
- Add @extref links to differential geometry tools and singular control example
- Explain transversality conditions (r(tf) and v(tf) free)
- Document shooting function structure (7 unknowns, 7 equations)
- Add summary of optimal structure (bang → singular → boundary → off)
- Replace benchmarking conclusion with neutral text
- Add @Assert for shooting function norm validation
- Add comparison between MINPACK and NonlinearSolve solver results
- Add L2 norm comparison between direct and indirect solutions in collapsible note
# [Direct and indirect methods for the Goddard problem](@id tutorial-goddard)
2
2
3
+
```@meta
4
+
Draft = false
5
+
```
6
+
3
7
## Introduction
4
8
5
9
```@raw html
@@ -32,7 +36,6 @@ and subject to the control constraint $u(t) \in [0,1]$ and the state constraint
32
36
We import the [OptimalControl.jl](https://control-toolbox.org/OptimalControl.jl) package to define the optimal control problem and [NLPModelsIpopt.jl](https://jso.dev/NLPModelsIpopt.jl) to solve it. We import the [Plots.jl](https://docs.juliaplots.org) package to plot the solution. The [OrdinaryDiffEq.jl](https://docs.sciml.ai/OrdinaryDiffEq) package is used to define the shooting function for the indirect method and the [MINPACK.jl](https://github.com/sglyon/MINPACK.jl) package permits to solve the shooting equation.
33
37
34
38
```@example main-goddard
35
-
using BenchmarkTools
36
39
using OptimalControl # to define the optimal control problem and more
37
40
using NLPModelsIpopt # to solve the problem via a direct method
38
41
using OrdinaryDiffEq # to get the Flow function from OptimalControl
## [Structure of the solution](@id tutorial-goddard-structure)
109
112
110
-
We first determine visually the structure of the optimal solution which is composed of a bang arc with maximal control, followed by a singular arc, then by a boundary arc and the final arc is with zero control. Note that the switching function vanishes along the singular and boundary arcs.
113
+
We first determine visually the structure of the optimal solution which is composed of a bang arc with maximal control, followed by a singular arc, then by a boundary arc and the final arc is with zero control. In summary, the structure is: **bang** ($u=1$) → **singular** → **boundary** ($v=v_{\max}$) → **off** ($u=0$). Note that the switching function vanishes along the singular and boundary arcs.
111
114
112
115
```@example main-goddard
113
116
t = time_grid(direct_sol) # the time grid as a vector
We are now in position to solve the problem by an indirect shooting method. We first define the four control laws in feedback form and their associated flows. For this we need to compute some Lie derivatives, namely [Poisson brackets](https://en.wikipedia.org/wiki/Poisson_bracket) of Hamiltonians (themselves obtained as lifts to the cotangent bundle of vector fields), or derivatives of functions along a vector field. For instance, the control along the *minimal order* singular arcs is obtained as the quotient
132
+
We are now in position to solve the problem by an indirect shooting method. For an introduction to the indirect simple shooting method, see the [Indirect simple shooting](@ref tutorial-indirect-simple-shooting) tutorial. We first define the four control laws in feedback form and their associated flows. For this we need to compute some Lie derivatives, namely [Poisson brackets](https://en.wikipedia.org/wiki/Poisson_bracket) of Hamiltonians (themselves obtained as lifts to the cotangent bundle of vector fields), or derivatives of functions along a vector field. For instance, the control along the *minimal order* singular arcs is obtained as the quotient
130
133
131
134
```math
132
135
u_s = -\frac{H_{001}}{H_{101}}
@@ -172,7 +175,7 @@ as well as the associated multiplier for the *order one* state constraint on the
172
175
173
176
which is the reason why we use the `@Lie` macro to compute Poisson brackets below.
174
177
175
-
With the help of differential geometry primitives, these expressions are straightforwardly translated into Julia code:
178
+
With the help of differential geometry primitives, these expressions are straightforwardly translated into Julia code. For more details on the differential geometry tools, see [Differential geometry tools](@extref OptimalControl manual-differential-geometry). For a simpler example involving a minimal order singular arc, see [Singular control](@extref OptimalControl example-singular-control).
176
179
177
180
```@example main-goddard
178
181
# Controls
@@ -198,7 +201,7 @@ nothing # hide
198
201
199
202
## Shooting function
200
203
201
-
Then, we define the shooting function according to the optimal structure we have determined, that is a concatenation of four arcs.
204
+
Then, we define the shooting function according to the optimal structure we have determined, that is a concatenation of four arcs. The shooting function has 7 unknowns (3 components of the initial costate `p0` and 4 times: `t1`, `t2`, `t3`, `tf`) and 7 equations.
MINPACK.jl (fsolve) is much faster than NonlinearSolve.jl (solve) on this problem. It also uses less memory. Both methods have a similar GC overhead, but MINPACK.jl is overall more efficient here.
400
+
There exist different alternatives to solve the shooting equation, as shown in the benchmarks above.
376
401
377
402
## [Plot of the solution](@id tutorial-goddard-plot)
378
403
379
404
We plot the solution of the indirect solution (in red) over the solution of the direct method (in blue).
380
405
381
406
```@example main-goddard
382
407
f = f1 * (t1, fs) * (t2, fb) * (t3, f0) # concatenation of the flows
We now compare numerically the direct and indirect solutions. The comparison includes L2 norms for the state and control variables, as well as absolute and relative errors for the variable (final time) and the objective. The L2 norm is computed using the trapezoidal rule over the time grid of the direct solution.
0 commit comments