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).

The package is available on PyPI.

Requirements

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

Install the published package and its runtime dependency:

python -m pip install runge-kutta

For local development, install from a source checkout with 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 Derivative, State, rk4

def rhs(t: float, y: State) -> State:
    return -y

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

Types

The module provides these aliases for annotating equations and states:

State = float | NDArray[np.float64]
Derivative = Callable[[float, State], State]

State represents either a scalar or a float64 NumPy array. A Derivative accepts a scalar time and a State, then returns the derivative as a State.

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 be a Derivative.

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.2

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.2
File Size Uploaded Provenance Actions
runge_kutta-0.1.2.tar.gz 3.6 kB Without provenance Details for runge_kutta-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 7.8 kB

Release files / runge_kutta-0.1.2.tar.gz

Download URL runge_kutta-0.1.2.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7cb9350461545f5a03a34006a7ff281e524096ecf57b6c1b43458c07f9b71050
BLAKE2b-256 checksum
How to use checksums
1846ba427d4b0ab516c81cbca5513362e6fef91e376d65f95af11afdd8beadfa
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.2-py3-none-any.whl

Download URL runge_kutta-0.1.2-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
166ec308e7048c398c0df29cf3d4340dcee78a101ed1fae27d60573fa0cedc60
BLAKE2b-256 checksum
How to use checksums
ccf3651de40cd5499f53983acda79bc888e7c8d02a2c7c2689727e5029621875
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.2

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