From 01970f1826f9a0852e412a61ffaf41d8a36338cf Mon Sep 17 00:00:00 2001 From: Olivier Cots Date: Mon, 29 Sep 2025 13:13:46 +0200 Subject: [PATCH 1/2] initial guess --- docs/src/tutorial-goddard.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/src/tutorial-goddard.md b/docs/src/tutorial-goddard.md index e0df1d5..80098e2 100644 --- a/docs/src/tutorial-goddard.md +++ b/docs/src/tutorial-goddard.md @@ -253,7 +253,7 @@ println("\nNorm of the shooting function: ‖s‖ = ", norm(s), "\n") We aggregate the data to define the initial guess vector. ```@example main-goddard -ξ = [p0..., t1, t2, t3, tf] # initial guess +ξ_guess = [p0..., t1, t2, t3, tf] # initial guess ``` ### MINPACK.jl @@ -291,10 +291,10 @@ Let us define the problem to solve. ```@example main-goddard # auxiliary function with aggregated inputs -nle!(s, ξ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7]) +shoot!(s, ξ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7]) # Jacobian of the (auxiliary) shooting function -jnle!(js, ξ) = jacobian!(nle!, similar(ξ), js, backend, ξ) +jshoot!(js, ξ) = jacobian!(shoot!, similar(ξ), js, backend, ξ) nothing # hide ``` @@ -302,7 +302,7 @@ We are now in position to solve the problem with the `hybrj` solver from MINPACK ```@example main-goddard # resolution of S(ξ) = 0 -indirect_sol = fsolve(nle!, jnle!, ξ, show_trace=true) +indirect_sol = fsolve(shoot!, jshoot!, ξ_guess, show_trace=true) # we retrieve the costate solution together with the times ξ = indirect_sol.x @@ -326,8 +326,8 @@ println("\nNorm of the shooting function: ‖s‖ = ", norm(s), "\n") 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. ```@example main-goddard -nle!(s, ξ, λ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7]) -prob = NonlinearProblem(nle!, ξ) +shoot!(s, ξ, λ) = shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7]) +prob = NonlinearProblem(shoot!, ξ_guess) nothing # hide ``` @@ -359,7 +359,7 @@ println("\nNorm of the shooting function: ‖s‖ = ", norm(s), "\n") The results found for by the two solvers are extremely close, so now, lets benchmark these two resolutions to compare their performances. ```@example main-goddard -@benchmark fsolve(nle!, jnle!, ξ; tol=1e-8, show_trace=false) #MINPACK +@benchmark fsolve(shoot!, jshoot!, ξ_guess; tol=1e-8, show_trace=false) #MINPACK ``` ```@example main-goddard @@ -382,7 +382,7 @@ We plot the solution of the indirect solution (in red) over the solution of the f = f1 * (t1, fs) * (t2, fb) * (t3, f0) # concatenation of the flows flow_sol = f((t0, tf), x0, p0) # compute the solution: state, costate, control... -plot!(plt, flow_sol, label="indirect") +plot!(plt, flow_sol; label="indirect", color=2) ``` ## References From ea20f16f0f0a06a85e07f447a5b6c7b3a96753a4 Mon Sep 17 00:00:00 2001 From: Olivier Cots Date: Mon, 29 Sep 2025 13:44:51 +0200 Subject: [PATCH 2/2] push preview --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 61705a1..3c074bf 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -67,4 +67,4 @@ makedocs(; plugins=[links], ) -deploydocs(; repo=repo_url * ".git", devbranch="main") +deploydocs(; repo=repo_url * ".git", devbranch="main", push_preview=true)