# How to implement hermite-simpson collocation method?

**URL:** <https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization\
**Created:** [March 11, 2024, 8:43am UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448 "2024-03-11T08:43:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Coral](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@Coral](https://discourse.julialang.org/u/Coral)\
**Post date:** [March 11, 2024, 8:43am UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/1 "2024-03-11T08:43:45Z")

</div>

Hello everyone.

I am trying to do a trajectory optimization using Hermite-Simpson collocation method. I want to know if in the package jump or in other package exist a function call hermite-simpson or if i have to create by myself.

Thank you so much

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 11, 2024, 5:54pm UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/2 "2024-03-11T17:54:32Z")

</div>

Hi @Coral, welcome to the forum.

Take a look at InfiniteOpt.jl

- [infiniteopt/InfiniteOpt.jl · JuMP](https://jump.dev/JuMP.jl/stable/packages/InfiniteOpt/)
- [GitHub - infiniteopt/InfiniteOpt.jl: An intuitive modeling interface for infinite-dimensional optimization problems.](https://github.com/infiniteopt/InfiniteOpt.jl)

Otherwise there are a couple of optimal-control related tutorials in the documentation:

- [Rocket Control · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/rocket_control/)
- [Optimal control for a Space Shuttle reentry trajectory · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/space_shuttle_reentry_trajectory/)

---

<div class="post-metadata">

**Author:** ![Coral](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@Coral](https://discourse.julialang.org/u/Coral)\
**Post date:** [March 12, 2024, 7:35am UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/3 "2024-03-12T07:35:08Z")

</div>

Thanks!!

---

<div class="post-metadata">

**Author:** ![Coral](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@Coral](https://discourse.julialang.org/u/Coral)\
**Post date:** [March 12, 2024, 9:34am UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/4 "2024-03-12T09:34:25Z")

</div>

Hi @odow again! I have been looking in the documentation that you sent and any of them reply to my question. In the examples that you provide they are doing the discretization for every function. My idea is to make a function that you can use in every case to do the discretization, i mean, create a function to which I pass a variable and it returns it to me discretized. Do you have any idea of how to do that? I was trying to do it using the trapezoidal integration method

---

<div class="post-metadata">

**Author:** ![A\_C](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@A\_C](https://discourse.julialang.org/u/A_C)\
**Post date:** [March 12, 2024, 3:21pm UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/5 "2024-03-12T15:21:53Z")

</div>

Hi…here is a script using JuMP for hermite-simpson. You can modify it for your example.

> **Hermit-Simpson**
>
> ```julia
> using JuMP
> import Ipopt
> using GLMakie
> 
> dubins = Model(Ipopt.Optimizer)
> vm = 1.0 # Max forward speed
> um = 1.0 # Max turning speed
> ns = 3 # Number of states
> nu = 1 # Number of inputs
> n = 200 # Time steps
> 
> # System dynamics
> function f(x, u)
> return [vm*cos(x[3]), vm*sin(x[3]), u[1]]
> end
> 
> # Objective Function
> function obj_f(x, u, Δt)
> return Δt
> end
> 
> # Decision variables
> @variables(dubins, begin
> 0 <= Δt <= 0.05 # Time step
> # State variables
> x[1:3,1:n] # Velocity
> # Control variables
> -um ≤ u[1:1,1:n] ≤ um # Thrust
> end)
> 
> # Objective
> @objective(dubins, Min, obj_f(x[1:3,1:n], u[1,1:n], Δt))
> #Initial conditions
> @constraint(dubins, x[1:3, 1] .== [0, 0, -π/2] )
> # Final conditions
> @constraint(dubins, x[1:3, n] == [5.0, 5.0, π/2 + π/4])
> 
> # Dynamic constraints: hermite_simpson
> for j in 1:n-1
> ub = (u[1:nu, j] + u[1:nu, j+1]) / 2
> 
> f1 = f(x[1:ns, j], u[1:nu, j])
> f2 = f(x[1:ns, j+1], u[1:nu, j+1])
> xb = (x[1:ns, j] + x[1:ns, j+1]) / 2 + Δt * (f1 - f2) / 8
> fb = f(xb, ub)
> 
> @constraint(dubins, x[1:ns, j+1] == x[1:ns, j] + Δt * (f1 + 4 * fb + f2) / 6)
> end
> 
> # Solve for the control and state
> println("Solving...")
> JuMP.optimize!(dubins)
> solution_summary(dubins)
> 
> # Display results
> println("Min time: ", objective_value(dubins)*n)
> 
> fig = Figure()
> ax = Axis(fig[1,1], autolimitaspect = 1)
> lines!(ax, value.(x[1,1:n]), value.(x[2, 1:n]))
> fig
> 
> ```

I have an experimental package [DirectOptimalControl.jl](https://a-c1.github.io/DirectOptimalControl.jl/stable/rocket.html) which allows you to define the problem similar to GPOPS. However, the documentation is limited and there are some limitations with large problems.

---

<div class="post-metadata">

**Author:** ![Coral](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@Coral](https://discourse.julialang.org/u/Coral)\
**Post date:** [March 12, 2024, 6:45pm UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/6 "2024-03-12T18:45:06Z")

</div>

Thank you so much, i would try to use it for my example!

---

<div class="post-metadata">

**Author:** ![Coral](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@Coral](https://discourse.julialang.org/u/Coral)\
**Post date:** [March 13, 2024, 8:46am UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/7 "2024-03-13T08:46:47Z")

</div>

Hi again! How can you implement hermite-simpson as a function? My goal in my project is to make a function to which I pass the state space and return it directly discretized using hermite-simpson or trapezoidal integration. Basically a function using direct placement methods to be able to do the discretization.

Thank you so much for your help

---

<div class="post-metadata">

**Author:** ![Coral](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@Coral](https://discourse.julialang.org/u/Coral)\
**Post date:** [March 13, 2024, 10:55am UTC](https://discourse.julialang.org/t/how-to-implement-hermite-simpson-collocation-method/111448/8 "2024-03-13T10:55:09Z")

</div>

Also if you can add in a message the information about the problem like the dynamics equations, a definition of the problem it would be really helpful to understand the code

Thank you
