# ModelingToolkit, initial data for second order ODE with state vector

**URL:** <https://discourse.julialang.org/t/modelingtoolkit-initial-data-for-second-order-ode-with-state-vector/68907>\
**Category:** General Usage\
**Tags:** package, modelingtoolkit\
**Created:** [September 29, 2021, 7:11am UTC](https://discourse.julialang.org/t/modelingtoolkit-initial-data-for-second-order-ode-with-state-vector/68907 "2021-09-29T07:11:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 29, 2021, 7:11am UTC](https://discourse.julialang.org/t/modelingtoolkit-initial-data-for-second-order-ode-with-state-vector/68907/1 "2021-09-29T07:11:52Z")

</div>

I don’t get why this doesn’t work:

```nohighlight
@variables t z[1:2,1:2](t)
z = collect(z)
Dt = Differential(t)

eqs = Dt.(Dt.(z[:])) .~ 1

u0 = vcat(z[:] .=> 0., Dt.(z[:]) .=> 1.0)
tspan = (0.0, 10.0)

@named sys = ODESystem(eqs)
prob = ODEProblem(sys, u0, tspan)

```

The error message is

```julia
ERROR: ArgumentError: A differentiated state's operation must be a `Sym`, so states like `D(u + u)` are disallowed. Got `z[1, 1]`.
Stacktrace:
  [1] diff2term(O::Term{Real, Nothing})
    @ Symbolics C:\Users\steff\.julia\packages\Symbolics\mFWWM\src\utils.jl:114
  [2] (::ModelingToolkit.var"#10#11"{typeof(Symbolics.diff2term)})(k::Num)
    @ ModelingToolkit .\none:0
  [3] iterate
    @ .\generator.jl:47 [inlined]
  [4] _all(f::Base.var"#282#284", itr::Base.Generator{Base.KeySet{Any, Dict{Any, Any}}, ModelingToolkit.var"#10#11"{typeof(Symbolics.diff2term)}}, #unused#::Colon)
    @ Base .\reduce.jl:930
  [5] all
    @ .\reduce.jl:918 [inlined]
  [6] Dict(kv::Base.Generator{Base.KeySet{Any, Dict{Any, Any}}, ModelingToolkit.var"#10#11"{typeof(Symbolics.diff2term)}})
    @ Base .\dict.jl:131
  [7] _varmap_to_vars(varmap::Dict{Num, Float64}, varlist::Vector{Term{Real, Base.ImmutableDict{DataType, Any}}}; defaults::Dict{Any, Any}, check::Bool, toterm::typeof(Symbolics.diff2term))
    @ ModelingToolkit C:\Users\steff\.julia\packages\ModelingToolkit\eSpDL\src\variables.jl:69
  [8] varmap_to_vars(varmap::Vector{Pair{Num, Float64}}, varlist::Vector{Term{Real, Base.ImmutableDict{DataType, Any}}}; defaults::Dict{Any, Any}, check::Bool, toterm::Function)
    @ ModelingToolkit C:\Users\steff\.julia\packages\ModelingToolkit\eSpDL\src\variables.jl:52
  [9] process_DEProblem(constructor::Type, sys::ODESystem, u0map::Vector{Pair{Num, Float64}}, parammap::SciMLBase.NullParameters; implicit_dae::Bool, du0map::Nothing, version::Nothing, tgrad::Bool, jac::Bool, checkbounds::Bool, sparse::Bool, simplify::Bool, linenumbers::Bool, parallel::Symbolics.SerialForm, eval_expression::Bool, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:has_difference,), Tuple{Bool}}})
    @ ModelingToolkit C:\Users\steff\.julia\packages\ModelingToolkit\eSpDL\src\systems\diffeqs\abstractodesystem.jl:467
 [10] (ODEProblem{true, tType, isinplace, P, F, K, PT} where {tType, isinplace, P, F, K, PT})(sys::ODESystem, u0map::Vector{Pair{Num, Float64}}, tspan::Tuple{Float64, Float64}, parammap::SciMLBase.NullParameters; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ModelingToolkit C:\Users\steff\.julia\packages\ModelingToolkit\eSpDL\src\systems\diffeqs\abstractodesystem.jl:557

```

If I do the same where `z` is just a scalar, then it works.

```julia
@variables t z(t)
Dt = Differential(t)
eqs = [Dt(Dt(z)) ~ 1]
u0 = [z => 0., Dt(z) => 1.0]
@named sys = ODESystem(eqs)
prob = ODEProblem(sys, u0, tspan)

```

(I’m posting this here, since the last time I though something is an issue, it was just me being stupid 😃 )

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 29, 2021, 10:10am UTC](https://discourse.julialang.org/t/modelingtoolkit-initial-data-for-second-order-ode-with-state-vector/68907/2 "2021-09-29T10:10:19Z")

</div>

It looks like a missing heuristic on array variables. Worth an issue.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 29, 2021, 10:16am UTC](https://discourse.julialang.org/t/modelingtoolkit-initial-data-for-second-order-ode-with-state-vector/68907/3 "2021-09-29T10:16:30Z")

</div>

Thanks. I will open an issue!

[https://github.com/SciML/ModelingToolkit.jl/issues/1283](https://github.com/SciML/ModelingToolkit.jl/issues/1283)
