# Continuing bugs for SecondOrderODE problem solvers

**URL:** <https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559>\
**Category:** Numerics\
**Created:** [June 16, 2020, 11:01pm UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559 "2020-06-16T23:01:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 16, 2020, 11:01pm UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/1 "2020-06-16T23:01:05Z")

</div>

Hi, working in `DiffferentialEquations.jl`, I find that a bunch of solvers don’t work with `SecondOrderODE`. This seems to be a bug at least a couple of years old, is there any way to use these solvers without reducing the problem to two first-order problems? (I am concerned that treating a 2nd-order problem as coupled first-order problems would not be “symplectic”, in terms of conserving “energy”, and thus be less accurate.)

This is the error message I get each time:  
`DimensionMismatch("parent has 4 elements, which is incompatible with length 2")`

Here is some sample code:

```julia
function SinCosDiffEqToSolve!(ddu,du,u,p,t)
    ddu[1] = -u[1]
end

prob = SecondOrderODEProblem(SinCosDiffEqToSolve!,[2.0],[3.0],(0.0,1.0))
sol = solve(prob, AutoVern9(Rodas4()), dense=true, reltol=1e-12, abstol=1e-12)

```

OR:

```julia
sol = solve(prob, AutoVern9(Rodas5()), dense=true, reltol=1e-12, abstol=1e-12)

```

OR:

```julia
sol = solve(prob, AutoVern9(KenCarp4()), dense=true, reltol=1e-12, abstol=1e-12)

```

OR:

```julia
sol = solve(prob, AutoTsit5(Rosenbrock23()), dense=true, reltol=1e-12, abstol=1e-12)

```

Thanks for any info!

---

<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:** [June 16, 2020, 11:27pm UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/2 "2020-06-16T23:27:25Z")

</div>

[oops]

---

<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:** [June 16, 2020, 11:38pm UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/3 "2020-06-16T23:38:15Z")

</div>

I thought I solved this problem, I figured out the answer, but realized I never released it. Let me go do that and close a bunch of issues.

---

<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:** [June 17, 2020, 12:14am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/4 "2020-06-17T00:14:29Z")

</div>

Solved in [https://github.com/SciML/DiffEqBase.jl/pull/536](https://github.com/SciML/DiffEqBase.jl/pull/536) . It’ll be available tomorrow.

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 17, 2020, 1:41am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/5 "2020-06-17T01:41:30Z")

</div>

Thanks, that’s great news!  
Will I have to re-compile DifferentialEquations somehow after the updates?

---

<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:** [June 17, 2020, 2:17am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/6 "2020-06-17T02:17:02Z")

</div>

> [@CosmoProf](#):
>
> Will I have to re-compile DifferentialEquations somehow after the updates?

yeah…

---

<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:** [June 17, 2020, 10:28am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/7 "2020-06-17T10:28:21Z")

</div>

Should be fixed on the latest releases

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 17, 2020, 11:58pm UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/8 "2020-06-17T23:58:06Z")

</div>

Thanks for your efforts Chris, but it still isn’t working for me.  
I get the same error message as before, `DimensionMismatch("parent has 4 elements, which is incompatible with length 2")`.

I tried to update and recompile the code with `Pkg.add("DiffEqBase")`, `Pkg.build("DiffEqBase")`, `"using DiffEqBase"`; plus all the same things with `DifferentialEquations` and `OrdinaryDiffEq`; and exiting and restarting Julia multiple times. The error doesn’t go away.

To be precise, here’s how I’m trying to run it:

```julia
using DifferentialEquations
using OrdinaryDiffEq
using DiffEqBase
using SpecialFunctions
using Plots

<Initial Conditions>

function OrdBesselDiffEqToSolve!(ddu,du,u,p,t)
    OrderParam = p[1]
    ddu[1] = -(du[1]/t) - (1 - ((OrderParam/t)^2))*u[1]
end

probFor = SecondOrderODEProblem(OrdBesselDiffEqToSolve!,vInit,xInit,tspanForward,FnOrder)

@time solFor = solve(probFor, AutoVern9(Rodas4P()), dense=true, reltol=1e-12, abstol=1e-12)

```

And besides `Rodas4P()`, it also didn’t work for `Rodas5()`, `Kvaerno5()`, or `KenCarp4()` either.

Not sure what’s going wrong…

---

<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:** [June 18, 2020, 2:34am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/9 "2020-06-18T02:34:16Z")

</div>

> [@CosmoProf](#):
>
> `"using DiffEqBase"` ; plus all the same things with `DifferentialEquations` and `OrdinaryDiffEq` ; and exiting and restarting Julia multiple times. The error doesn’t go away.

Do you have DiffEqBase v6.38.4? Check `]st -m`

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 18, 2020, 3:22am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/10 "2020-06-18T03:22:56Z")

</div>

I have DiffEqBase v6.20.0.

I tried `Pkg.add("DiffEqBase")`, `Pkg.build("DiffEqBase")`, and `using DiffEqBase`, and Julia said it was compiling again due to a stale cache. Those are the only ways I know how to recompile. Is there some other way to recompile packages, so I can get the latest DiffEqBase?

---

<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:** [June 18, 2020, 4:36am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/11 "2020-06-18T04:36:51Z")

</div>

Are you on Julia v1.4?

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 18, 2020, 4:47am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/12 "2020-06-18T04:47:03Z")

</div>

No, Julia 1.0.5, the Long-term support release.

I originally started trying the current stable release, 1.4.2, but had continual problems installing packages.

---

<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:** [June 18, 2020, 5:08am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/13 "2020-06-18T05:08:04Z")

</div>

> [@CosmoProf](#):
>
> I originally started trying the current stable release, 1.4.2, but had continual problems installing packages.

Interesting. DiffEq’s newest versions only support \>=v1.3 due to multithreading. If you post about your v1.4 issues in a thread we can probably help you sort them out: I think the vast majority of users are on v1.4

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 18, 2020, 5:30am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/14 "2020-06-18T05:30:04Z")

</div>

I did post about the issues, that’s where I started on this discussion board; getting Julia up and running in the first place was a nightmare. It’s too bad that I can’t use the latest DiffEq packages on 1.0, I’m going to have to think about whether it’s worth starting over.

The whole point of this is to get a high-precision, strict tolerance (\< 1e-12) solver that can replace `Vern9()` when the differential equation turns out to be stiff. Could you recommend the best stiff solver for me to try in `AutoVern9`?

(The Julia doc page on solvers says that `Rodas4`, `KenCarp4`, and `Rodas5` are meant for medium tolerances, \> 1e-8. That isn’t good enough. I’ve got Vern9 tolerances down to 1e-14 already. The page also mentions `radau` with `Vector{Float64}`, and I’m using `Float64`, but I don’t know if that is the same thing as `Vector{Float64}`.)

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:** [June 18, 2020, 2:51pm UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/15 "2020-06-18T14:51:44Z")

</div>

> [@CosmoProf](#):
>
> The whole point of this is to get a high-precision, strict tolerance (\< 1e-12) solver that can replace `Vern9()` when the differential equation turns out to be stiff. Could you recommend the best stiff solver for me to try in `AutoVern9` ?

`Rodas5` or `RadauIIA5`

---

<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:** [June 18, 2020, 3:05pm UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/16 "2020-06-18T15:05:15Z")

</div>

Though I will add that for very strict tolerances, if you know for a fact that it’s stiff, pure `radau` can’t be beat right now. We’re working on a pure Julia solution for it, but benchmarks are pretty clear that it’s the currently the best stiff ODE solver for extremely strict tolerances.

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 19, 2020, 12:57am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/17 "2020-06-19T00:57:45Z")

</div>

Hi again Chris, I installed Julia 1.4 on my office computer, and STILL the stiff solvers don’t work, each giving different errors. Also, apparently I can only update to DiffEqBase v6.36.3, not DiffEqBase v6.38.4, no matter what I tried with `Pkg.add` and `Pkg.build`.

Here’s some info on the system and error messages:

```julia
# Running on Windows 10, Version 10.0.18362 Build 18362

# Julia Version 1.4.2 (2020-05-23)

] st -m
	[2b5f629d] DiffEqBase v6.36.3

sol1 = solve(prob, RadauIIA5()) -- MethodError: no method matching getindex(::Tuple{UniformScaling{Bool},UniformScaling{Bool}}, ::Int64, ::Int64)

sol2 = solve(prob, Rodas4P()) {or Rodas4P() or Rodas5()} -- DimensionMismatch("W: (Base.OneTo(2), Base.OneTo(2)), mass matrix: (Base.OneTo(2),)")

sol3 = solve(prob, radau()) -- UndefVarError: radau not defined

```

but sometimes if I keep trying to recompile the packages again and again to get `radau` to work, I instead get:

```julia
sol3 = solve(prob, radau()) -- UndefVarError: This solver must use full or banded mass matrices.

```

Relatedly, I have repeated problems installing `ODEInterface.jl`:

```julia
┌ Error: Error building `ODEInterface`:
│ INFO: Could not find files for the given pattern(s).
│ ERROR: LoadError: Currently only gfortran is supported.
│ Stacktrace:
│ [1] error(::String) at .\error.jl:33
│ [2] top-level scope at C:\Users\name\.juliapro\JuliaPro_v1.4.2-1\packages\ODEInterface\xIa64\deps\build.jl:250
│ [3] include(::String) at .\client.jl:439
│ [4] top-level scope at none:5
│ in expression starting at C:\Users\name\.juliapro\JuliaPro_v1.4.2-1\packages\ODEInterface\xIa64\deps\build.jl:249
└ @ Pkg.

```

Here is the preliminary code leading up to those errors:

```julia
Using DifferentialEquations
using OrdinaryDiffEq
using DiffEqBase
using ODEInterface
using SpecialFunctions

xInit = [2.35]
vInit = [1.07]
FnOrder = [1.27]
tspan = (5.0, 20.0)

prob = SecondOrderODEProblem(OrdBesselDiffEqToSolve!,vInit,xInit,tspan,FnOrder)

```

---

<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:** [June 19, 2020, 1:11am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/18 "2020-06-19T01:11:33Z")

</div>

> [@CosmoProf](#):
>
> Also, apparently I can only update to DiffEqBase v6.36.3, not DiffEqBase v6.38.4, no matter what I tried with `Pkg.add` and `Pkg.build` .

What happens if you do `]add DiffEqBase@6.36.4`?

> [@CosmoProf](#):
>
> Relatedly, I have repeated problems installing `ODEInterface.jl` :

You need to have a Fortran compiler for ODEInterface to work. On Windows that requires doing [GitHub - SciML/ODEInterfaceDiffEq.jl: Adds the common API onto ODEInterface classic Fortran methods for the SciML Scientific Machine Learning organization](https://github.com/SciML/ODEInterfaceDiffEq.jl#installation) (which is why I want to finish all of the pure Julia methods so that mess is gone)

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 19, 2020, 1:23am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/19 "2020-06-19T01:23:24Z")

</div>

Didn’t know I could add it by hand like that, but sadly still doesn’t work:

```julia
(@v1.4) pkg> add DiffEqBase@6.36.4
   Updating registry at `C:\Users\phybdb\.juliapro\JuliaPro_v1.4.2-1\registries\JuliaPro`
  Resolving package versions...
ERROR: Unsatisfiable requirements detected for package DiffEqBase [2b5f629d]:
 DiffEqBase [2b5f629d] log:
 ├─possible versions are: [3.13.2-3.13.3, 4.0.0-4.0.1, 4.1.0, 4.2.0, 4.3.0-4.3.1, 4.4.0, 4.5.0, 4.6.0, 4.7.0, 4.8.0, 4.9.0, 4.10.0-4.10.1, 4.11.0-4.11.1, 4.12.0, 4.13.0, 4.14.0-4.14.1, 4.15.0, 4.16.0, 4.17.0, 4.18.0, 4.19.0, 4.20.0-4.20.3, 4.21.0, 4.21.2-4.21.3, 4.22.0-4.22.2, 4.23.0, 4.23.2-4.23.4, 4.24.0-4.24.3, 4.25.0-4.25.1, 4.26.0-4.26.3, 4.27.0-4.27.1, 4.28.0-4.28.1, 4.29.0-4.29.2, 4.30.0-4.30.2, 4.31.0-4.31.2, 4.32.0, 5.0.0-5.0.1, 5.1.0, 5.2.0-5.2.3, 5.3.0-5.3.2, 5.4.0-5.4.1, 5.5.0-5.5.2, 5.6.0-5.6.4, 5.7.0, 5.8.0-5.8.1, 5.9.0, 5.10.0-5.10.3, 5.11.0-5.11.1, 5.12.0, 5.13.0, 5.14.0-5.14.2, 5.15.0, 5.16.0-5.16.5, 5.17.0-5.17.1, 5.18.0, 5.19.0, 5.20.0-5.20.1, 6.0.0, 6.1.0, 6.2.0-6.2.4, 6.3.0-6.3.6, 6.4.0-6.4.2, 6.5.0-6.5.1, 6.6.0, 6.7.0, 6.8.0, 6.9.0-6.9.4, 6.10.0-6.10.2, 6.11.0, 6.12.0-6.12.5, 6.13.0-6.13.3, 6.14.0-6.14.2, 6.15.0-6.15.2, 6.16.0, 6.17.0-6.17.3, 6.18.0-6.18.1, 6.19.0, 6.20.0, 6.21.0-6.21.1, 6.22.0-6.22.2, 6.23.0, 6.24.0, 6.25.0-6.25.2, 6.26.0, 6.27.0, 6.28.0, 6.29.0-6.29.3, 6.30.0-6.30.4, 6.31.0-6.31.1, 6.32.0-6.32.2, 6.33.0-6.33.1, 6.34.0-6.34.3, 6.35.0-6.35.2, 6.36.0-6.36.3] or uninstalled
 └─restricted to versions 6.36.4 by an explicit requirement — no versions left

```

---

<div class="post-metadata">

**Author:** ![CosmoProf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cosmoprof/32/15516_2.png) [@CosmoProf](https://discourse.julialang.org/u/CosmoProf)\
**Post date:** [June 19, 2020, 1:50am UTC](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559/20 "2020-06-19T01:50:00Z")

</div>

On your 2nd suggestion, I went to “[https://github.com/SciML/ODEInterfaceDiffEq.jl#installation](https://github.com/SciML/ODEInterfaceDiffEq.jl#installation)”, downloaded & extracted the zip file, added the top `mingw-w64` directory to my Path, and in Julia did “`] add ODEInterface`”.

I still got the same error on `Pkg.build("ODEInterface")`, and I still got the solver error, “`UndefVarError: radau not defined`”.

I’m not sure if there was something specific I had to do to install MingW32 besides extracting the files and adding the folder to the Path. There was no installer executable to click on, just a bunch of makefiles and script files everywhere. I’m beginning to think that Windows users are not invited to this party.

[Next page](https://discourse.julialang.org/t/continuing-bugs-for-secondorderode-problem-solvers/41559.md?page=2)
