0
$\begingroup$

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?

$\endgroup$
  • $\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$ – Dr. Lutz Lehmann Dec 1 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$ – Bouarfa Mahi Dec 1 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$ – Dr. Lutz Lehmann Dec 1 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$ – Dr. Lutz Lehmann Dec 2 at 7:39
  • $\begingroup$ Thank you i am going with diffeqpy. $\endgroup$ – Bouarfa Mahi Dec 2 at 15:26
3
$\begingroup$

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)

plt.plot(sol.t,sol.u)
plt.show()

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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