Skip to content

Commit f90b570

Browse files
authored
Merge pull request #52 from control-toolbox/fix-goddard
Initial guess
2 parents f2bd27f + ea20f16 commit f90b570

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ makedocs(;
6767
plugins=[links],
6868
)
6969

70-
deploydocs(; repo=repo_url * ".git", devbranch="main")
70+
deploydocs(; repo=repo_url * ".git", devbranch="main", push_preview=true)

docs/src/tutorial-goddard.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ println("\nNorm of the shooting function: ‖s‖ = ", norm(s), "\n")
253253
We aggregate the data to define the initial guess vector.
254254

255255
```@example main-goddard
256-
ξ = [p0..., t1, t2, t3, tf] # initial guess
256+
ξ_guess = [p0..., t1, t2, t3, tf] # initial guess
257257
```
258258

259259
### MINPACK.jl
@@ -291,18 +291,18 @@ Let us define the problem to solve.
291291

292292
```@example main-goddard
293293
# auxiliary function with aggregated inputs
294-
nle!(s, ξ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7])
294+
shoot!(s, ξ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7])
295295
296296
# Jacobian of the (auxiliary) shooting function
297-
jnle!(js, ξ) = jacobian!(nle!, similar(ξ), js, backend, ξ)
297+
jshoot!(js, ξ) = jacobian!(shoot!, similar(ξ), js, backend, ξ)
298298
nothing # hide
299299
```
300300

301301
We are now in position to solve the problem with the `hybrj` solver from MINPACK.jl through the `fsolve` function, providing the Jacobian. Let us solve the problem and retrieve the initial costate solution.
302302

303303
```@example main-goddard
304304
# resolution of S(ξ) = 0
305-
indirect_sol = fsolve(nle!, jnle!, ξ, show_trace=true)
305+
indirect_sol = fsolve(shoot!, jshoot!, ξ_guess, show_trace=true)
306306
307307
# we retrieve the costate solution together with the times
308308
ξ = indirect_sol.x
@@ -326,8 +326,8 @@ println("\nNorm of the shooting function: ‖s‖ = ", norm(s), "\n")
326326
Alternatively, we can use the [NonlinearSolve.jl](https://docs.sciml.ai/NonlinearSolve) package to solve the shooting equation. The code is similar, but we use the `solve` function instead of `fsolve`. Let us define the problem.
327327

328328
```@example main-goddard
329-
nle!(s, ξ, λ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7])
330-
prob = NonlinearProblem(nle!, ξ)
329+
shoot!(s, ξ, λ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7])
330+
prob = NonlinearProblem(shoot!, ξ_guess)
331331
nothing # hide
332332
```
333333

@@ -359,7 +359,7 @@ println("\nNorm of the shooting function: ‖s‖ = ", norm(s), "\n")
359359
The results found for by the two solvers are extremely close, so now, lets benchmark these two resolutions to compare their performances.
360360

361361
```@example main-goddard
362-
@benchmark fsolve(nle!, jnle!, ξ; tol=1e-8, show_trace=false) #MINPACK
362+
@benchmark fsolve(shoot!, jshoot!, ξ_guess; tol=1e-8, show_trace=false) #MINPACK
363363
```
364364

365365
```@example main-goddard
@@ -382,7 +382,7 @@ We plot the solution of the indirect solution (in red) over the solution of the
382382
f = f1 * (t1, fs) * (t2, fb) * (t3, f0) # concatenation of the flows
383383
flow_sol = f((t0, tf), x0, p0) # compute the solution: state, costate, control...
384384
385-
plot!(plt, flow_sol, label="indirect")
385+
plot!(plt, flow_sol; label="indirect", color=2)
386386
```
387387

388388
## References

0 commit comments

Comments
 (0)