Skip to main content

Runge-Kutta ODE Solvers

Small Python implementations of classical fourth-order Runge-Kutta (RK4) and Runge-Kutta-Fehlberg (RK45) methods for numerically solving ordinary differential equations (ODEs).

Requirements

  • Python 3
  • NumPy
  • Matplotlib (for the example scripts)

Install the module and its dependencies:

python -m pip install .

Usage

Import a solver from runge_kutta. Each function advances the solution by one integration step for an equation of the form dy/dt = f(t, y).

import numpy as np
from runge_kutta import rk4

def rhs(t, y):
    return -y

t, y = rk4(rhs, t0=0.0, y0=np.array([1.0]), h=0.1)

Solvers

Function Description Returns
rk4(f, t0, y0, h) Performs one fixed-size classical fourth-order Runge-Kutta step. (t, y)
rk45(f, t0, y0, h) Performs one fixed-size Runge-Kutta-Fehlberg step using the fourth-order estimate. (t, y, error)
rk45_h_adj(f, t0, y0, h, epsilon) Performs an RK45 step and proposes a next step size from the embedded error estimate. (t, y, error, h_adj)

f must accept (t, y) and return the derivative at that point. y may be a scalar or a NumPy array.

Examples

The included scripts compare RK4 and RK45 while plotting solution trajectories and RK45 error estimates:

python test1.py  # Lorenz system
python test2.py  # damped second-order system

Both scripts open Matplotlib windows. test1.py integrates the Lorenz system for 500,000 steps and can take noticeably longer to run.

Metadata

Release files for runge-kutta 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for runge-kutta 0.1.0
File Size Uploaded Provenance Actions
runge_kutta-0.1.0.tar.gz 3.0 kB Without provenance Details for runge_kutta-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for runge-kutta 0.1.0
File Interpreter ABI Platform Actions
runge_kutta-0.1.0-py3-none-any.whl Python 3 none any Details for runge_kutta-0.1.0-py3-none-any.whl

Total release size: 6.2 kB

Release files / runge_kutta-0.1.0.tar.gz

Download URL runge_kutta-0.1.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
655c5cf85f6a1e83ab5c6ea3c31c119d7ca2dae0a00251d58a73ad85de020c8d
BLAKE2b-256 checksum
How to use checksums
9e933178a2998ef76041b61cd54b58f3996a55e56b9b179ba17681b0a6a9fa9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / runge_kutta-0.1.0-py3-none-any.whl

Download URL runge_kutta-0.1.0-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf53bce6cbf95d03a417dcd7afefc225d97bfafb0243a019b0d4c47e775e081b
BLAKE2b-256 checksum
How to use checksums
aba836ca438c28033a82e5ab1e60d40d56c9ba9169a4af000ca27d5385e3fc6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for runge-kutta 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page