# ModelingToolkit second derivative only gives first derivative

**URL:** <https://discourse.julialang.org/t/modelingtoolkit-second-derivative-only-gives-first-derivative/70703>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit\
**Created:** [October 31, 2021, 8:37pm UTC](https://discourse.julialang.org/t/modelingtoolkit-second-derivative-only-gives-first-derivative/70703 "2021-10-31T20:37:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctessum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctessum/32/19444_2.png) [@ctessum](https://discourse.julialang.org/u/ctessum)\
**Post date:** [October 31, 2021, 8:37pm UTC](https://discourse.julialang.org/t/modelingtoolkit-second-derivative-only-gives-first-derivative/70703/1 "2021-10-31T20:37:14Z")

</div>

Hello,

I’m running into an issue that has left me confused. Using ModelingToolkit v6.7.1, I (for example) want to simulate a falling object. So:

```julia
@variables t [unit = u"s"] x(t) [unit = u"m"] v(t) [unit = u"m/s"]
@parameters g=-9.8 [unit = u"m/s^2"]
Dt = Differential(t)
Dt2 = Differential(t)^2

```

I would think that I could just set the second derivative of `x` equal to `g`:

```julia
@named eqs = ODESystem([
	Dt2(x) ~ g,
])
prob = ODEProblem(structural_simplify(eqs), [x => 0.0], (0.0,10.0))
sol = solve(prob, saveat=1)

```

Then when I plot `x` vs `t`, I would expect to get a parabola, but instead I get a straight line:

![image](https://global.discourse-cdn.com/julialang/original/3X/a/3/a318934c70a2fb71d247344648b4471459c2814b.png)

If I only use first derivatives, however, and introduce another variable `v`, it does work:

```julia
@named eqs = ODESystem([
	Dt(v) ~ g,
	Dt(x) ~ v,
])
prob = ODEProblem(structural_simplify(eqs), [x => 0.0, v => 0.0], (0.0,10.0))
sol = solve(prob, saveat=1)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/e/2/e253f4dae82eff22be8596787a43c1581769554f.png)

Is this the expected behavior? If so, why doesn’t my first attempt work, or what is the proper way to define a second derivative? Thanks!

---

<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:** [October 31, 2021, 10:35pm UTC](https://discourse.julialang.org/t/modelingtoolkit-second-derivative-only-gives-first-derivative/70703/2 "2021-10-31T22:35:47Z")

</div>

Does `ode_order_lowering` fix it? Anyways, this should be an issue in the MTK repo, not a Discourse post.

---

<div class="post-metadata">

**Author:** ![ctessum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctessum/32/19444_2.png) [@ctessum](https://discourse.julialang.org/u/ctessum)\
**Post date:** [January 3, 2022, 3:31am UTC](https://discourse.julialang.org/t/modelingtoolkit-second-derivative-only-gives-first-derivative/70703/3 "2022-01-03T03:31:47Z")

</div>

Thanks, that works! I also opened an issue [here](https://github.com/SciML/ModelingToolkit.jl/issues/1417) regarding the possibility of this type of user error being caught and thrown rather than passing silently.
