Continuing bugs for SecondOrderODE problem solvers

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:

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

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


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


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


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

Thanks for any info!


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.

Solved in . It’ll be available tomorrow.


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


Should be fixed on the latest releases

1 Like

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"),"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:

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]

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…

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

I have DiffEqBase v6.20.0.

I tried Pkg.add("DiffEqBase"),"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?

Are you on Julia v1.4?

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.

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

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}.)


Rodas5 or RadauIIA5

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.

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

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

# 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:

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

Relatedly, I have repeated problems installing ODEInterface.jl:

┌ 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:

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)

What happens if you do ]add DiffEqBase@6.36.4?

You need to have a Fortran compiler for ODEInterface to work. On Windows that requires doing (which is why I want to finish all of the pure Julia methods so that mess is gone)

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

(@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

On your 2nd suggestion, I went to “”, 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"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.