ode_rk4_step

Contents

ode_rk4_step#

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

Classical fourth-order Runge–Kutta (RK4) step for ODEs.

The standard RK4 scheme uses four stages:

\[\begin{split}k_1 = f(y_n, t_n),\\ k_2 = f\big(y_n + \tfrac{\Delta t}{2}k_1,\ t_n + \tfrac{\Delta t}{2}\big),\\ k_3 = f\big(y_n + \tfrac{\Delta t}{2}k_2,\ t_n + \tfrac{\Delta t}{2}\big),\\ k_4 = f\big(y_n + \Delta t\,k_3,\ t_n + \Delta t\big),\\ y_{n+1} = y_n + \tfrac{\Delta t}{6}(k_1 + 2k_2 + 2k_3 + k_4).\end{split}\]
Parameters:
  • f (Callable[[PyTree, float | Quantity, ...], 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 RK4 step.

Return type:

PyTree

Notes

Fourth-order accurate with local truncation error \(\mathcal{O}(\Delta t^4)\).