Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyODESolver

Python package for solving ODEs

Installation

To install PyODESolver execute:

python3 -m pip install PyODESolver

This will make the package pyodesolver available for import. To this this launch python3

python3

and import the new package pyodesolver

import pyodesolver

Quickstart guide:

To get started with using PyODESolver include a solver method. In this example we will use the explicit euler method to solve the differential equation y'(t) = -2 * y(t), y(0) = pi. This differential equation has the exact solution

y(t) = pi * exp(-2 * t).

The right hand side in the expression

y'(t) = -2*y(t),
y(0) = pi

is called a RHSFunction. This example has been implemented in ExampleFunc01 in the file rhs_function.py. To use the explicit euler solver for this ODE we first import the required files

from method_explicit_euler import ExplicitEuler
from rhs_function import ExampleFunc01
import numpy as np

we can than construct a method object in our main function and call generate on it to get the solver object.

if __name__ == "__main__":
    N = 10**3
    t = np.linspace(0, 1, num=N)
    y0 = np.pi
    ee_solver = ExplicitEuler(N, y0, [0, 1], ExampleFunc01())
    solution = ee_solver.generate()

The generator object is useful in this instance as it very lean in term of required memory and puts full control to the user at it allows to generate new time steps as required. For example one thread can be used for updating a plot and a different thread can call next(solution) to match the framerate of the plot.

To extract the whole solution we can use:

numericSol = []
for (time, val) in solution:
    numericSol.append(val)

To plot the solution in this example we can use

import matplotlib.pyplot as plt
plt.plot(t, np.array(numericSol))
plt.show()

Solving arbitrary ODEs

To solve a customised ode the only two components required are the new RHSFunction and the Jacobian of this function. In cases where the Jacobian is unknown explicit methods will still function.

To implement a new RHSFunction the user can inherit from RHSFunction and define a new subclass

class NewFunction(RHSFunction):
...

RHSFunction has exposes three methods that raise NotImplementedErrors. The user can then implement these methods by providing

def eval(self, y_vec, time):
    ...

and

def jacobian(self, y_vec, time):
    ...

to provide everything required for explicit and implicit methods. The solution can be obtained as described in the Quick-start-guide.

Release files for PyODESolver 0.1.2.dev0

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

Source distribution (sdist)

Source distribution for PyODESolver 0.1.2.dev0
File Size Uploaded
PyODESolver-0.1.2.dev0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyODESolver 0.1.2.dev0
File Interpreter ABI Platform
PyODESolver-0.1.2.dev0-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / PyODESolver-0.1.2.dev0.tar.gz

Download URL PyODESolver-0.1.2.dev0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b4c46a1913cb91afed2e16feea38ff48991fd7883cc6511883b742524b62fae8
BLAKE2b-256 checksum
How to use checksums
417390dbe77c2c35df7c1a5747ea706612f09419fc10b512d76af72b4bd6970e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.6

Release files / PyODESolver-0.1.2.dev0-py3-none-any.whl

Download URL PyODESolver-0.1.2.dev0-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bde2b63bac79cdeb9ebba3ff9fe436195d8087ae08b704db181c67cc98060a4c
BLAKE2b-256 checksum
How to use checksums
62fdf57f35af5fbd55d38162053d144edd4c22a28bd8cfe4aa0a4b10836c2a4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.1.2.dev0 This release

2 release files

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