# Soft question: What are good libraries for solving ordinary differential equations?

I am aware of a few:

But, I'd like to know which are the best tools that have been developed by professional physicists and mathematicians. The reason I ask is that I'd like to build an ODE solver myself from scratch but I'd like to be aware of the state of the art before getting started.

• Welcome to SciComp! As currently posed, this question is probably a bit too broad, and it really depends what you are looking for in an ODE solver, such as type of problem, stiff vs. non-stiff problems, choice of language, if parallelism (GPU, threading, message passing) matters at all, and so on. If you can supply more information and narrow the scope of your question, that would be very helpful. Oct 7 '14 at 2:01
• Well, not clear what you mean by a library? There are like zillions of different open source ODE/PDE/ADE projects out there in different languages. If I had to pick one then I would go with Modelica Laanguage and the open source implementations OpenModelica and JModelica. Maxima and scipy would be my next choices.
Dec 1 '17 at 0:08

In general, I'd say the following open source tools tend to be (roughly) best-of-breed, in the following order:

• PETSc has implemented a number of ODE solvers as part of TS, its time-stepping routines. There are a number of integrators implemented, including ARKIMEX, EIMEX, Rosenbrock-W, Crank-Nicolson, backward Euler, several Runge-Kutta methods (including the classic 4-5 variant, and SSP schemes), general linear methods, and an interface to CVODE in SUNDIALS, which is a BDF method. It's also a highly scalable parallel library with facilities for both message passing and GPU programming, although I haven't used the GPU side of things. They're currently working out trying to use threads. PETSc is written in C, and has Fortran and Python interfaces; for the implicit methods, a large variety of nonlinear solvers, linear solvers, nonlinear preconditioners, and linear preconditioners are available. PETSc has won an R&D 100 award, and has the best development practices for a scientific code that I am aware of. However, it is very complicated. It includes a huge number of examples and a large manual, along with good mailing lists. A significant number of PDE tools and frameworks build on PETSc, including many finite element codes.
• Trilinos has implemented in its Rythmos package forward Euler, backward Euler, explicit Runge-Kutta, implicit Runge-Kutta, and BDF methods. It is written in C++, and is also implemented in parallel. Like PETSc, Trilinos also contains linear and nonlinear solvers, along with some preconditioners. Trilinos tends to require more "buy-in" to its ecosystem, and is much more of a framework than PETSc.
• SUNDIALS currently implements a BDF method and an Adams-Bashforth method. It's written in very readable C code, and includes some examples. It contains serial and parallel implementations, and the internal development version has added threading and ARKIMEX methods. I'm very familiar with this code, and if you want to use an integrator without having to learn a huge framework, SUNDIALS is a reasonable choice. However, I find their development practices frustrating. They release infrequently, and if you find a bug in the code they release (of which there are many), they may have already fixed it internally without letting their mailing list know. There's no formal public repository for the code, although if you dig around enough, you can find informal Git repositories. If they post patches, the patch format is rather informal, instead of using a standard format readable by patch. Their mailing list also went dark for a few months this past year (disclosure: I work at the same institution as the authors of SUNDIALS, so I prodded them to fix this oversight). Use this code with some caution. There's also an official MATLAB interface, an official Fortran interface, and some unofficial interfaces in other languages, like Python.
• There are a number of Fortran codes out there, like Ernst Hairer's implementations (DOPRI5 - explicit Runge-Kutta 4(5) method, DOP853 - explicit Runge-Kutta 8(5,3) method, RADAU - Radau collocation, RODAS - Rosenbrock method), old versions of SUNDIALS-related codes (VODE, DASPK), and really old stiff solvers (DASAC, DASSL). Some of these have been wrapped in Python (via SciPy), some of them have been ported to other languages. Most of these are strictly serial codes, but they're well-trusted implementations.

I hesitate to recommend MATLAB because although the MATLAB solvers are generally good, they can only be used with MATLAB, which is proprietary. If you have MATLAB available, they're good to learn from in terms of using serial codes. Some of them are based on the Fortran codes I mentioned. If you don't have access to MATLAB, it's tough to play with the solver code (which I'm sure you could still find, but you wouldn't be able to execute it). You should be able to experiment with all of the open source code I mention above without worrying about licensing issues.

If you're using C++, the odeint library of boost seems to be fast and easy to use: http://www.boost.org/doc/libs/1_56_0/libs/numeric/odeint/doc/html/index.html. The boost libraries are known as high-quality software packages and are widely used.

As shown in this example they also have an ode45-like integrator.

Matlab has decent ODE solvers. ode45 is popular (4th order Runge-Kutta) but there are obviously more. See here for example.

I have been using octave for a while now. It is the open-source cousin of Matlab and it has many decent solvers lsode for odes and daspk for DAEs are the ones I use and they are pretty good.