ode_rk4
Solve an initial value problem y'(x)=f(x,y) with Runge-Kutta 4; get a step-by-step table, per-step errors, exact solution when available, and an optional plot.
Instructions
Solve an initial value problem y'(x) = f(x, y) with the Runge-Kutta 4 method.
Args: ecuacion_str: Right-hand side f(x, y), e.g. "y" or "-2xy". x0: Initial x. y0: Initial y(x0). xf: Final x (must be > x0). h: Step size (must be positive). The endpoint xf is always reached. tol: Optional tolerance to flag whether the final error meets it. precision: Rounding digits. plot: When True, also return a PNG plot of the solution.
Returns:
Dict with the numerical solution table, exact solution (when SymPy can
solve it) and per-step errors. With plot=True a list
[dict, Image] is returned instead.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| h | Yes | ||
| x0 | Yes | ||
| xf | Yes | ||
| y0 | Yes | ||
| tol | No | ||
| plot | No | ||
| precision | No | ||
| ecuacion_str | Yes |