I am trying to solve a differential equation with discretized variable coefficients which are calculated from a time serie. In this case the Runge-Kutta step size is fixed by the frequency in the time serie.

Is there any Python Runge-Kutta RK4, RK5 solvers suitable for fixed step?

  • $\begingroup$ Why not use interpolation on the coefficients and just set the max. step size to the sampling interval? The stages of the method need values at intermediate points, so you need to do some interpolation anyway, so why not do something more sensible than a step function. $\endgroup$ Dec 1, 2019 at 20:25
  • $\begingroup$ It is not necessary because the frequency of the time serie is one millisecond which gives a very good numerical accuracy. $\endgroup$ Dec 1, 2019 at 20:45
  • $\begingroup$ Then contemplate the use of a multi-step method, as that uses only data from the sampling points. In a one-step method, you introduce errors of $O(h)$ when using piecewise constant functions, which contributes an $O(h)$ error in the solution. $\endgroup$ Dec 1, 2019 at 21:02
  • $\begingroup$ Could you add an example situation? As I understand it, you have an ODE like $y'(t)=a(t)y(t)$ where $a(t)$ is given as a function table $a(t_0+k\Delta t)$ without knowing the expression for $a(t)$. This severely restricts the packaged methods you can use, as they all assume that the ODE function depends only on $t$ and the state, so that you need to translate $t$ into an index into the function table. Or you code your method yourself, adapted to the function table. $\endgroup$ Dec 2, 2019 at 7:39
  • $\begingroup$ Thank you i am going with diffeqpy. $\endgroup$ Dec 2, 2019 at 15:26

1 Answer 1


If you use diffeqpy you can use the commands adaptive=false,dt=... to specify fixed time stepping. The following is for using the Dormand-Prince RK45 method with fixed time stepping on the Lorenz equation:

from diffeqpy import de
import matplotlib.pyplot as plt

def f(u,p,t):
    x, y, z = u
    sigma, rho, beta = p
    return [sigma * (y - x), x * (rho - z) - y, x * y - beta * z]

u0 = [1.0,0.0,0.0]
tspan = (0., 100.)
p = [10.0,28.0,8/3]
prob = de.ODEProblem(f, u0, tspan, p)
sol = de.solve(prob,de.DP5(),adaptive=false,dt=0.1)


For a multistep method, one can use de.VCABM() where de.DP5() sits.

  • $\begingroup$ I am working on a jupyterhub/lab environment and will try to install all the necessary Julia packages. $\endgroup$ Dec 1, 2019 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.