How to use DifferentialEquations with complicated equations

You can always pass additional parameters to a functional interface by using lexical scoping. (This seems to be a FAQ for libraries that do integration, optimization, root-finding, etcetera.)

For example, the QuadGK package package lets you integrate a function of the form f(x) via quadgk(x, a, b). But suppose you have a function g(x, α, β) that depends on two additional parameters α,β — does that mean you can’t use it with QuadGK, unless you rewrite it to use global variables? No! You would just call quadgk(x -> g(x, α, β), a, b), constructing an anonymous function x -> ... that “captures” the values of α, β from e.g. local variables.

Because of this, I think DifferentialEquations didn’t really need an explicit p argument f(x, p, t) in its basic ODE interface, since parameters could have been passed using closures. My guess is that @ChrisRackauckas defined it this way to make it easier to support parameter estimation and adjoint/sensitivity analysis.

If what you really mean is that you have ODEs coupled to other systems of non-ODE equations that are expressed implicitly, this is known as a differential algebraic equation (DAE) and is also supported by DifferentialEquations.jl.

6 Likes