ode_ralston4_step

ode_ralston4_step#

class braintools.quad.ode_ralston4_step(f, y, t, *args, **kwargs)#

Ralston’s 4th-order Runge–Kutta method (minimum truncation-error bound).

A four-stage, fourth-order explicit scheme whose free parameters are chosen to minimise the bound on the local truncation error (Ralston, 1962) [1]. The coefficients are exact closed forms in \(\sqrt{5}\):

  • \(c = (0,\ 2/5,\ (14 - 3\sqrt{5})/16,\ 1)\) \(\approx (0, 0.4, 0.45573725, 1)\)

  • \(b \approx (0.17476028, -0.55148066, 1.20553560, 0.17118478)\)

Parameters:
  • f (Callable[..., PyTree]) – Right-hand side function f(y, t, *args) -> PyTree.

  • y (PyTree) – Current state at time t.

  • t (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Current time.

  • *args – Additional positional arguments forwarded to f.

Returns:

The updated state after one Ralston RK4 step.

Return type:

PyTree

See also

ode_rk4_step

Classical fourth-order Runge–Kutta.

ode_ralston3_step

Ralston’s third-order method.

References

Examples

>>> import brainstate
>>> from braintools.quad import ode_ralston4_step
>>> with brainstate.environ.context(dt=0.1):
...     y1 = ode_ralston4_step(lambda y, t: -y, 1.0, 0.0)
>>> round(float(y1), 6)  # exp(-0.1) = 0.904837...
0.904837