braincell.quad.midpoint_step

Contents

braincell.quad.midpoint_step#

braincell.quad.midpoint_step(target, *args)[source]#

Advance one step with the explicit midpoint (modified Euler) method.

The midpoint method is a two-stage, second-order explicit Runge-Kutta scheme:

\[\begin{split}k_1 &= f(t_n, y_n), \\ k_2 &= f\!\left(t_n + \tfrac{\Delta t}{2},\ y_n + \tfrac{\Delta t}{2}\, k_1\right), \\ y_{n+1} &= y_n + \Delta t \, k_2.\end{split}\]

Local truncation error is \(O(\Delta t^3)\) and global error is \(O(\Delta t^2)\).

Parameters:
  • target (DiffEqModule) – Differential-equation module to advance.

  • *args – Extra positional arguments forwarded to target’s integration hooks.

Returns:

Updates target’s state in place.

Return type:

None

See also

euler_step

First-order explicit Euler.

rk2_step, heun2_step, ralston2_step

Notes

Butcher tableau (midpoint_tableau):

\[\begin{split}\begin{array}{c|cc} 0 & 0 & 0 \\ \tfrac{1}{2} & \tfrac{1}{2} & 0 \\ \hline & 0 & 1 \end{array}\end{split}\]

Examples

>>> import brainstate
>>> import brainunit as u
>>> from braincell.quad import midpoint_step
>>> with brainstate.environ.context(t=0. * u.ms, dt=0.01 * u.ms):
...     midpoint_step(my_neuron)