Skip to main content
Odecast logo

odecast

PyPI version Tests Documentation

odecast is a Python library for solving ordinary differential equations of arbitrary order. Equations are written in their natural form, e.g. y'' + 0.3 y' + y = 0, and odecast performs the reduction to a first-order system that numerical integrators require. Numerical solutions are computed with SciPy, closed-form solutions with SymPy.

Full documentation: https://maroba.github.io/odecast

Installation

pip install odecast

This installs NumPy, SciPy and SymPy. Python 3.10 or later is required. The example scripts additionally need Matplotlib (pip install "odecast[examples]").

Example

The damped harmonic oscillator y'' + 0.3 y' + y = 0 with y(0) = 1, y'(0) = 0:

from odecast import var, Eq, solve

y = var("y")
eq = Eq(y.d(2) + 0.3 * y.d() + y, 0)

sol = solve(eq, ivp={y: 1.0, y.d(): 0.0}, tspan=(0, 10))

sol.t          # time points
sol[y]         # y(t)
sol[y.d()]     # y'(t)
sol.eval(y, 5.0)

For comparison, the same problem written directly against scipy.integrate.solve_ivp requires the state vector to be set up by hand:

def rhs(t, z):
    y, dy = z
    return [dy, -0.3 * dy - y]

solve_ivp(rhs, (0, 10), [1.0, 0.0])

This is manageable for a single equation but becomes tedious and error-prone for coupled systems of mixed order, which is the case odecast is designed for.

Features

  • Arbitrary order. The order of each variable is inferred from the equations; no manual reduction is needed.
  • Coupled systems of mixed order. Pass a list of equations; each variable may appear with a different highest derivative.
  • Nonlinear equations. Powers and functions of the unknowns, such as y**2 or sp.sin(y) (or np.sin(y)), can be used directly.
  • Vector and matrix variables. var("u", shape=2) or var("M", shape=(2, 2)) declares an array-valued unknown. Equations such as Eq(u.d(2) + u, 0) are expanded component-wise.
  • Initial and boundary value problems. Two-point boundary value problems are solved with scipy.integrate.solve_bvp.
  • Symbolic solutions. The SymPy backend returns closed-form solutions, with initial or boundary conditions applied.
  • Validation. Missing, superfluous or inconsistent conditions are reported before solving, with a message naming the offending condition.

Coupled systems

x, y = var("x"), var("y")
eqs = [
    Eq(x.d() - x * (1 - y), 0),
    Eq(y.d() - y * (x - 1), 0),
]
sol = solve(eqs, ivp={x: 1.0, y: 0.5}, tspan=(0, 15))

Nonlinear and time-dependent terms

The independent variable is available as odecast.t:

import sympy as sp
from odecast import t

theta = var("theta")
eq = Eq(theta.d(2) + 0.1 * theta.d() + sp.sin(theta), 0.5 * sp.cos(2 * t))

Vector and matrix variables

u = var("u", shape=2)
eq = Eq(u.d(2) + 0.1 * u.d() + u, 0)
sol = solve(eq, ivp={u: [1.0, 0.0], u.d(): [0.0, 1.0]}, tspan=(0, 10))

sol[u]      # array of shape (2, n)
sol[u[0]]   # array of shape (n,)

Boundary value problems

from odecast import BC

y = var("y")
sol = solve(
    Eq(y.d(2) + y, 0),
    bvp=[BC(y, t=0, value=0), BC(y, t=1, value=1)],
    tspan=(0, 1),
)
sol.eval(y, 0.5)

For nonlinear problems an initial guess can be passed, e.g. guess={y: lambda t: t * (1 - t)}.

Symbolic solutions

sol = solve(Eq(y.d(2) + y, 0), backend="sympy", ivp={y: 1, y.d(): 0})
sol.as_expr(y)       # cos(t)
sol.eval(y, 1.0)     # 0.5403...

Without conditions the general solution is returned, e.g. C1*sin(t) + C2*cos(t).

Solver options

Additional keyword arguments to solve are passed to scipy.integrate.solve_ivp (or solve_bvp for boundary value problems):

solve(eq, ivp=ic, tspan=(0, 10), method="LSODA", rtol=1e-9, max_step=0.01)

Limitations

odecast is at an early stage (alpha). In particular:

  • Boundary value problems must be two-point problems: all conditions lie at the end points of tspan. Problems with unknown parameters, such as eigenvalue problems, are not supported.
  • Functions must be applied to components of vector variables (sp.sin(u[0])), not to the vector as a whole. Operations on vector and matrix variables are element-wise; matrix products are not supported.
  • The SymPy backend can solve what sympy.dsolve can solve: single equations and linear systems, but generally not nonlinear coupled systems.

Examples

The examples/ directory contains runnable scripts, e.g.

python examples/01_ivp_damped_oscillator.py

More examples with plots are in the documentation.

Development

git clone https://github.com/maroba/odecast.git
cd odecast
pip install -e ".[dev]"
pytest
ruff check .
black --check .

See the contributing guide for details. Bug reports and pull requests are welcome.

License

MIT. See LICENSE.

Metadata

Release files for odecast 0.2.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 odecast 0.2.0
File Size Uploaded Provenance Actions
odecast-0.2.0.tar.gz 35.1 kB With provenance Details for odecast-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for odecast 0.2.0
File Interpreter ABI Platform Actions
odecast-0.2.0-py3-none-any.whl Python 3 none any Details for odecast-0.2.0-py3-none-any.whl

Total release size: 66.2 kB

Release files / odecast-0.2.0.tar.gz

Download URL odecast-0.2.0.tar.gz
Size 35.1 kB
Tags Source
SHA-256 checksum
How to use checksums
64f98575dfe9036884c4958a5f1adacde7a377f50f76fdfbb244fca799d61c8a
BLAKE2b-256 checksum
How to use checksums
23c9a6fbc74d763cf24bcbc6d15e9b25f5b0146120d2ecb97d8e7c585b139e04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / odecast-0.2.0-py3-none-any.whl

Download URL odecast-0.2.0-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b92769580dc62874bd8a3b5d16812dab5f50720017f74eb79c7023faa2ba5395
BLAKE2b-256 checksum
How to use checksums
a0f417f5739b065875b9115d6eb341c39b4e30db9ad463ddb44c57b6c5f893e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for odecast 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for odecast-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

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