# DifferentialEquations.jl default options for a solver

**URL:** <https://discourse.julialang.org/t/differentialequations-jl-default-options-for-a-solver/19937>\
**Category:** Numerics\
**Tags:** diffeq\
**Created:** [January 22, 2019, 4:15pm UTC](https://discourse.julialang.org/t/differentialequations-jl-default-options-for-a-solver/19937 "2019-01-22T16:15:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelkyu](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@michaelkyu](https://discourse.julialang.org/u/michaelkyu)\
**Post date:** [January 22, 2019, 4:15pm UTC](https://discourse.julialang.org/t/differentialequations-jl-default-options-for-a-solver/19937/1 "2019-01-22T16:15:09Z")

</div>

In DifferentialEquations.jl, how can I find out the default options for a specific solver? In particular, I’d like to know the default options for the ODE solver [DP5](http://docs.juliadiffeq.org/latest/solvers/ode_solve.html). I see a [description of options](http://docs.juliadiffeq.org/latest/basics/common_solver_opts.html) in the docs, but I don’t see what are the defaults.

I’m asking because I’m trying to recapitulate results that I’ve previously calculated in Matlab with the ode45 function, which I believe is the same solver as DP5. The default options in Matlab are [documented here](https://www.mathworks.com/help/matlab/ref/ode45.html#bu00_4l_sep_shared-options).

I find the results in DifferentialEquations.jl do not exactly match Matlab’s [ode45](https://www.mathworks.com/help/matlab/ref/ode45.html) because different time steps are chosen. I’ve attempted to make the time steps the same by setting the same abstol and reltol parameters as in Matlab, but this does not seem sufficient as DifferentialEquation.jl still tends to use less time steps. In some problem instances, I have to set abstol and reltol to be much more sensitive at 1e-8 to more closely match the final solutions generated using only 1e-4 in Matlab, but then the running time becomes slower. I suspect that changing other options like the maximum time step (qmax) in DifferentialEquations.jl may help in equalizing the results.

---

<div class="post-metadata">

**Author:** ![freemint](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freemint/32/20013_2.png) [@freemint](https://discourse.julialang.org/u/freemint)\
**Post date:** [May 16, 2019, 11:04pm UTC](https://discourse.julialang.org/t/differentialequations-jl-default-options-for-a-solver/19937/2 "2019-05-16T23:04:14Z")

</div>

I am not that familiar with DE.jl but have you tried to pass the Julia implementation the same “collection” of time steps used in MatLab?  
The `tstops` option might be helpfull.

---

<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 13, 2019, 1:45am UTC](https://discourse.julialang.org/t/differentialequations-jl-default-options-for-a-solver/19937/3 "2019-06-13T01:45:54Z")

</div>

> [@michaelkyu](#):
>
> I find the results in DifferentialEquations.jl do not exactly match Matlab’s [ode45](https://www.mathworks.com/help/matlab/ref/ode45.html) because different time steps are chosen. I’ve attempted to make the time steps the same by setting the same abstol and reltol parameters as in Matlab, but this does not seem sufficient as DifferentialEquation.jl still tends to use less time steps. In some problem instances, I have to set abstol and reltol to be much more sensitive at 1e-8 to more closely match the final solutions generated using only 1e-4 in Matlab, but then the running time becomes slower. I suspect that changing other options like the maximum time step (qmax) in DifferentialEquations.jl may help in equalizing the results.

Could you share an example? DifferentialEquations.jl’s `DP5` “exactly” (to floating point error because of muladd) matches the time stepping behavior of the classic `dopri5` Fortran code. The tests for this can be found here: [https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/master/test/odeinterface/odeinterface\_regression.jl](https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/master/test/odeinterface/odeinterface_regression.jl) .

> [@michaelkyu](#):
>
> I have to set abstol and reltol to be much more sensitive at 1e-8 to more closely match the final solutions generated using only 1e-4 in Matlab

What about the MATLAB results at 1e-8? They may be different 😉. To more accurately check the difference in behavior, I suggest constructing a work-precision diagram to directly show accuracy and time at the same time, as in done in the MATLABDiffEq.jl repository [GitHub - SciML/MATLABDiffEq.jl: Common interface bindings for the MATLAB ODE solvers via MATLAB.jl for the SciML Scientific Machine Learning ecosystem](https://github.com/JuliaDiffEq/MATLABDiffEq.jl).

> [@michaelkyu](#):
>
> I see a [description of options](http://docs.juliadiffeq.org/latest/basics/common_solver_opts.html) in the docs, but I don’t see what are the defaults.

The defaults are either mentioned there, or can always be known by directly looking at the defaults: [https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/master/src/solve.jl#L16-L60](https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/master/src/solve.jl#L16-L60)

> [@michaelkyu](#):
>
> I suspect that changing other options like the maximum time step (qmax) in DifferentialEquations.jl may help in equalizing the results.

There are two things that are going on. For one, what MATLAB returns to you are not the actual steps. It lies. Well, it doesn’t lie, it is explained in the MATLAB ODE Suite paper [https://www.mathworks.com/help/pdf\_doc/otherdocs/ode\_suite.pdf](https://www.mathworks.com/help/pdf_doc/otherdocs/ode_suite.pdf) that the steps of a 5th order method are generally too large, so it would make bad plots. Therefore, a 4th order interpolation is used to fill in 2 intermediate points at 1/3 and 2/3 of the step. If you’re trying to match the stepping behavior of DiffEq to the output behavior of MATLAB, you can see why this is doomed to fail. Nonetheless, DiffEq just returns a continuous solution `sol(t)` instead, so 🤷‍♂️ it’s just an API difference here.

The second thing is that MATLAB sets `dtmax` to be the total time divided by 100, so you’re guaranteed 100 steps. We don’t care if you solve it in 5 steps as long as its to tolerance. So you’d need to change that to match MATLAB more closely.

As the other commenter mentioned, you could just do `adaptive=false,tstops=my_times` in order to exactly specify all of the `dt`s for the integration. That said, you’ll want to only step to every 3rd timestep of MATLAB’s output of course 😛.

Moral of the story, trying to make the time stepping behavior exactly the same between a closed source code and DiffEq is going to be hard because there are a lot of variables going on. We haven’t even mentioned the PI-adaptivity going on yet which could be different, but we cannot know without breaking the license… Instead of benchmarking like this, do it fairly with a work-precision plot:

1. Generate a reference solution with `abstol=reltol=1e-14`
2. Solve both with a range of tolerances, and calculate the error according to some norm against the reference.
3. Plot time vs error

Then the efficiency is seen by what methods get what times at the same error. When you do that, like is seen in [GitHub - SciML/MATLABDiffEq.jl: Common interface bindings for the MATLAB ODE solvers via MATLAB.jl for the SciML Scientific Machine Learning ecosystem](https://github.com/JuliaDiffEq/MATLABDiffEq.jl), you’ll see between a 10x-100x efficiency difference.
