ode_rk2_step

Contents

ode_rk2_step#

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

Second-order Runge–Kutta (RK2) step for ODEs.

The classical RK2 (Heun/midpoint) method performs two function evaluations:

\[\begin{split}k_1 = f(y_n, t_n),\\ k_2 = f\big(y_n + \Delta t\,k_1,\ t_n + \Delta t\big),\\ y_{n+1} = y_n + \tfrac{\Delta t}{2}\,(k_1 + k_2).\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 RK2 step.

Return type:

PyTree

Notes

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