# Writting runge-kutta stages as an array of expression

**URL:** <https://discourse.julialang.org/t/writting-runge-kutta-stages-as-an-array-of-expression/105817>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization, dynamical-systems\
**Created:** [November 5, 2023, 11:54am UTC](https://discourse.julialang.org/t/writting-runge-kutta-stages-as-an-array-of-expression/105817 "2023-11-05T11:54:12Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [November 5, 2023, 7:24pm UTC](https://discourse.julialang.org/t/writting-runge-kutta-stages-as-an-array-of-expression/105817/3 "2023-11-05T19:24:39Z")

</div>

The error is because you are attempting to combine the new `NonlinearExpr` syntax in JuMP with the old `@NL` expression syntax.

See [ANN: JuMP v1.15 is released](https://discourse.julialang.org/t/ann-jump-v1-15-is-released/103875)

Here’s how I would write your model

```julia
using JuMP, Ipopt
const n = 80
const g = 9.81
const m = 1
const l = 1
f(θ, ω, u) = [ω, -g / l * sin(θ) + 1 / (m * l^2) * u]
A = [0 0; 1 0]
b = [0.5, 0.5]
model = Model(Ipopt.Optimizer)
@variables(model, begin
    x[1:n+1, 1:2]
    u[1:n]
    Δt[1:n]
end)
@expressions(model, begin
    k1[j in 1:n], f(x[j,1], x[j,2], u[j])
    y[j in 1:n, i in 1:2], x[j,i] + Δt[j] * A[2,1] * k1[j][i]
    k2[j in 1:n], f(y[j,1], y[j,2], u[j])
    xₕ[j in 2:n+1, i in 1:2],
        x[j-1, i] + Δt[j-1] * (b[1] * k1[j-1][i] + b[2] * k2[j-1][i])
end)
@constraint(model, [j in 2:n+1, i in 1:2], x[j,i] == xₕ[j,i])

```

---

_[View the full topic](https://discourse.julialang.org/t/writting-runge-kutta-stages-as-an-array-of-expression/105817)._
