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

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.1
File Size Uploaded Provenance Actions
runge_kutta-0.1.1.tar.gz 3.4 kB Without provenance Details for runge_kutta-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 7.0 kB

Release files / runge_kutta-0.1.1.tar.gz

Download URL runge_kutta-0.1.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4d661efaa7cc1536366af713ccc01a154b9ed987fddb6c08ec0ba65c2a9dec4c
BLAKE2b-256 checksum
How to use checksums
d25cd302d57958272d416c1b2c5653ac3c3513e916ae8414505400e2f5f92a01
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.1-py3-none-any.whl

Download URL runge_kutta-0.1.1-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
299bf473f98b34495f3aa000aa38efbf1f4cd342cb651d7e34228e8503f54e17
BLAKE2b-256 checksum
How to use checksums
221e3f6c7197e186b94754770795f8ec2b719057e19fafbe5bb478681816ceed
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.1

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