utils.solver.rk4_method

utils.solver.rk4_method(f, t_span, y0, dt, si=None, args=(), post_step=None)

Fixed-step 4th-order Runge-Kutta integrator.

Parameters

f : callable

Derivative function with signature f(t, y, *args).

t_span : tuple of float

(t0, tf) integration bounds.

y0 : array - like

Initial state vector.

dt : float

Integration timestep.

si : float or None = None

Sampling interval — output is saved every si time units. Must be an integer multiple of dt. Defaults to dt (every step is saved).

args : tuple = ()

Extra positional arguments forwarded to f.

post_step : callable or None = None

Optional hook called after each accepted sub-step with signature post_step(t, y) -> y. The returned array replaces the current state, allowing post-step corrections (e.g. state nudging).

Returns

solution : Solution

Object with attributes t (time axis) and y (state trajectory).

Raises

: ValueError

If t_span is invalid, si is not an integer multiple of dt, or t_span length is not an integer multiple of si.