Dynamical, Hamiltonian and 2nd Order ODE Problems


Defines an dynamical ordinary differential equation (ODE) problem. Documentation Page: https://diffeq.sciml.ai/stable/types/dynamical_types/

Dynamical ordinary differential equations, such as those arising from the definition of a Hamiltonian system or a second order ODE, have a special structure that can be utilized in the solution of the differential equation. On this page we describe how to define second order differential equations for their efficient numerical solution.

Mathematical Specification of a Dynamical ODE Problem

These algorithms require a Partitioned ODE of the form:

\[\frac{dv}{dt} = f_1(u,t) \\ \frac{du}{dt} = f_2(v) \\\]

This is a Partitioned ODE partitioned into two groups, so the functions should be specified as f1(dv,v,u,p,t) and f2(du,v,u,p,t) (in the inplace form), where f1 is independent of v (unless specified by the solver), and f2 is independent of u and t. This includes discretizations arising from SecondOrderODEProblems where the velocity is not used in the acceleration function, and Hamiltonians where the potential is (or can be) time-dependent but the kinetic energy is only dependent on v.

Note that some methods assume that the integral of f2 is a quadratic form. That means that f2=v'*M*v, i.e. $\int f_2 = \frac{1}{2} m v^2$, giving du = v. This is equivalent to saying that the kinetic energy is related to $v^2$. The methods which require this assumption will lose accuracy if this assumption is violated. Methods listed make note of this requirement with "Requires quadratic kinetic energy".



Defines the ODE with the specified functions. isinplace optionally sets whether the function is inplace or not. This is determined automatically, but not inferred.

Parameters are optional, and if not given then a NullParameters() singleton will be used which will throw nice errors if you try to index non-existent parameters. Any extra keyword arguments are passed on to the solvers. For example, if you set a callback in the problem, then that callback will be added in every solve call.


  • f1 and f2: The functions in the ODE.
  • v0 and u0: The initial conditions.
  • tspan: The timespan for the problem.
  • p: The parameters for the problem. Defaults to NullParameters
  • kwargs: The keyword arguments passed onto the solves.

Defines a second order ordinary differential equation (ODE) problem. Documentation Page: https://diffeq.sciml.ai/stable/types/dynamical_types/

Mathematical Specification of a 2nd Order ODE Problem

To define a 2nd Order ODE Problem, you simply need to give the function $f$ and the initial condition $u_0$ which define an ODE:

\[u'' = f(u',u,p,t)\]

f should be specified as f(du,u,p,t) (or in-place as f(ddu,du,u,p,t)), and u₀ should be an AbstractArray (or number) whose geometry matches the desired geometry of u. Note that we are not limited to numbers or vectors for u₀; one is allowed to provide u₀ as arbitrary matrices / higher dimension tensors as well.

From this form, a dynamical ODE:

\[v' = f(v,u,p,t) \\ u' = v \\\]

is generated.



Defines the ODE with the specified functions.


  • f: The function for the second derivative.
  • du0: The initial derivative.
  • u0: The initial condition.
  • tspan: The timespan for the problem.
  • callback: A callback to be applied to every solver which uses the problem. Defaults to nothing.

Hamiltonian Problems

HamiltonianProblems are provided by DiffEqPhysics.jl and provide an easy way to define equations of motion from the corresponding Hamiltonian. To define a HamiltonianProblem one only needs to specify the Hamiltonian:


and autodifferentiation (via ForwardDiff.jl) will create the appropriate equations.




  • H: The Hamiltonian H(p,q,params) which returns a scalar.
  • p0: The initial momentums.
  • q0: The initial positions.
  • tspan: The timespan for the problem.
  • param: Defaults to nothing. param will be passed to H's params.