# Optimizing a function in optimal control problem

**URL:** <https://discourse.julialang.org/t/optimizing-a-function-in-optimal-control-problem/125483>\
**Category:** Optimization (Mathematical)\
**Tags:** optimization, sciml, differentialequation\
**Created:** [February 2, 2025, 9:34pm UTC](https://discourse.julialang.org/t/optimizing-a-function-in-optimal-control-problem/125483 "2025-02-02T21:34:14Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![jbcaillau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbcaillau/32/206767_2.png) [@jbcaillau](https://discourse.julialang.org/u/jbcaillau)\
**Post date:** [February 6, 2025, 11:33pm UTC](https://discourse.julialang.org/t/optimizing-a-function-in-optimal-control-problem/125483/15 "2025-02-06T23:33:22Z")

</div>

Hi there; `JuMP.jl` and `InfiniteOpt.jl` will sure do.

@yhchang you can also have a look at `OptimalControl.jl` for a combination of direct (= JuMP like) and shooting method approaches. The Goddard example cited by @odow (with an additional state constraint) reads like that:

```julia
ocp = @def begin # definition of the optimal control problem

    tf ∈ R, variable
    t ∈ [t0, tf], time
    x = (r, v, m) ∈ R³, state
    u ∈ R, control

    x(t0) == [r0, v0, m0]
    m(tf) == mf, (1)
    0 ≤ u(t) ≤ 1
    r(t) ≥ r0
    0 ≤ v(t) ≤ vmax

    ẋ(t) == F0(x(t)) + u(t) * F1(x(t))

    r(tf) → max

end

F0(x) = begin
    r, v, m = x
    D = Cd * v^2 * exp(-β*(r - 1)) # Drag force
    return [v, -D/m - 1/r^2, 0]
end

F1(x) = begin
    r, v, m = x
    return [0, Tmax/m, -b*Tmax]
end

```

Check out below for the complete example:

> **[Goddard: direct, indirect · OptimalControl.jl](https://control-toolbox.org/OptimalControl.jl/stable/tutorial-goddard.html)**
>
> Documentation for OptimalControl.jl.

---

_[View the full topic](https://discourse.julialang.org/t/optimizing-a-function-in-optimal-control-problem/125483)._
