# Solving an optimal control problem with JuMP

**URL:** <https://discourse.julialang.org/t/solving-an-optimal-control-problem-with-jump/36570>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization, forwarddiff\
**Created:** [March 26, 2020, 10:18pm UTC](https://discourse.julialang.org/t/solving-an-optimal-control-problem-with-jump/36570 "2020-03-26T22:18:43Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [March 28, 2020, 10:11am UTC](https://discourse.julialang.org/t/solving-an-optimal-control-problem-with-jump/36570/16 "2020-03-28T10:11:18Z")

</div>

This is a great idea. I tried to define another state like this

```julia
dx[5] = :(1.0)

```

But I get the following error:

```julia
MethodError: Cannot `convert` an object of type Float64 to an object of type Expr
This may have arisen from a call to the constructor Expr(...),
since type constructors fall back to convert methods.

Stacktrace:
 [1] setindex!(::Array{Expr,1}, ::Float64, ::Int64) at ./array.jl:578
 [2] include_string(::String, ::String) at ./loading.jl:522

```

I tried e.g. converting to an Abstract type

```julia
dx[5] = :(convert(Real, 1.0))

```

and this if fine, but then when I do `configure` I get

```julia
julia> configure!(n;(:Nck=>[50]),(:finalTimeDV=>false), (:tf=>tplan))

Unrecognized function "convert" used in nonlinear expression.

Stacktrace:
 [1] macro expansion at /Users/roi/.julia/v0.6/JuMP/src/parsenlp.jl:96 [inlined]
 [2] macro expansion at /Users/roi/.julia/v0.6/JuMP/src/macros.jl:1412 [inlined]
 [3] macro expansion at /Users/roi/.julia/v0.6/NLOptControl/src/diffeq.jl:87 [inlined]
 [4] anonymous at ./<missing>:?
 [5] NLExpr(::NLOptControl.NLOpt, ::Expr, ::Array{Any,2}, ::Vararg{Any,N} where N) at /Users/roi/.julia/v0.6/NLOptControl/src/diffeq.jl:89
 [6] DiffEq(::NLOptControl.NLOpt, ::Array{Any,2}, ::Array{Any,2}, ::Int64, ::Int64) at /Users/roi/.julia/v0.6/NLOptControl/src/diffeq.jl:36
 [7] OCPdef!(::NLOptControl.NLOpt) at /Users/roi/.julia/v0.6/NLOptControl/src/setup.jl:305
 [8] #configure!#52(::Array{Any,1}, ::Function, ::NLOptControl.NLOpt) at /Users/roi/.julia/v0.6/NLOptControl/src/setup.jl:474
 [9] (::NLOptControl.#kw##configure!)(::Array{Any,1}, ::NLOptControl.#configure!, ::NLOptControl.NLOpt) at ./<missing>:0
 [10] anonymous at ./<missing>:?
 [11] include_string(::String, ::String) at ./loading.jl:522

```

So I am not sure how to implement this.

---

_[View the full topic](https://discourse.julialang.org/t/solving-an-optimal-control-problem-with-jump/36570)._
