Skip to main content

A package for solving delay differential equations

Project description

DDE_IVP

PyPI version License: MIT

A Python package for solving Delay Differential Equations (DDEs) with custom event handling and interpolation. This package provides a simple and efficient interface for DDE problems using advanced numerical methods.

Inspired by the ddeint package, this implementation builds upon scipy.integrate.solve_ivp, which offers modern numerical solvers such as RK23 and RK45 with adaptive step size. The package also allows configurable maximum step size. (Note: the step size should not exceed the minimum delay to avoid extrapolation and instability).


Features

  • Solve delay differential equations with ease.
  • Event handling for detecting zero-crossings and termination.
  • Built-in support for numerical methods like RK23 and RK45.
  • Compatible with SciPy's solve_ivp interface for familiarity.
  • Adaptive step size and configurable maximum step size for precision and stability.

Installation

Install the package directly from PyPI:

pip install dde_ivp

Or install the latest development version from GitHub:

pip install git+https://https://github.com/Menginventor/dde_ivp.git

Usage

Example: Solving a Delay Differential Equation

Here's an example of solving an IPDT (Integrating Plus Dead Time) model with proportional control:

import numpy as np
from dde_ivp import solve_ddeivp

import matplotlib.pyplot as plt


# System parameters
K = 1.0  # Process gain
T = 1.0  # Process time constant
L = 1.0  # Dead time
Kp = np.pi/2.0*L  # Proportional gain

# Reference input (step response)
R = 1.0

# Define the DDE

def ipdt_with_p_control(t, Y):
    y_delayed = Y(t - L)
    u = Kp * (R - y_delayed)
    return (K * u) / T


# History function
def history(t):
    return np.array([0])   # Assume initial output is zero

def zc_event(t,y):
    return y[0]-1
# Time span

t_span = (0,60)
t = np.linspace(t_span[0], t_span[1], 1000)
# Solve the DDE
solution = solve_ddeivp(ipdt_with_p_control, t_span, history,max_step=1.0,method='RK23',events=zc_event)

print(solution)

# Plot results
plt.figure(figsize=(10, 6))
plt.plot(t, solution.sol(t)[0], label="System Output (y(t))")
plt.plot(solution.t, solution.y[0],'.', label="System Output (y(t))")
plt.plot(solution.t_events[0],solution.y_events[0],'x')
plt.axhline(R, color='r', linestyle='--', label="Reference Input (R)")
plt.title("IPDT Model with Proportional Control")
plt.xlabel("Time")
plt.ylabel("Output")
plt.legend()
plt.grid()
plt.show()

API Reference

solve_ddeivp

solve_ddeivp(fun, t_span, history_func, method='RK45', t_eval=None, max_step=None, events=None, vectorized=False, args=None, **options)

Solve delay differential equations with event handling.

  • fun: Callable. The system of differential equations.
  • t_span: Tuple. Start and end times.
  • history_func: Callable. Provides the initial condition or history.
  • method: String. Numerical method to use (RK23 or RK45).
  • t_eval: Array. Time points to evaluate the solution.
  • events: Callable or list of callables. Event functions for detecting zero-crossings.
  • vectorized: Bool. Whether fun is vectorized.

Returns:

  • An OptimizeResult object containing the solution, events, and status.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes and test them.
  4. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgements

This package leverages numerical methods and optimizations from SciPy's solve_ivp and related tools.


Contact

For questions or feedback, open an issue on the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dde_ivp-0.1.3.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dde_ivp-0.1.3-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file dde_ivp-0.1.3.tar.gz.

File metadata

  • Download URL: dde_ivp-0.1.3.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dde_ivp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 abe4825a532829c79b0123f2ee984ddd2d7f9f0b2f807c4254c0a5b296a0be67
MD5 b9f7a687891ce56a5d5f87034d672f62
BLAKE2b-256 410ec4db5c0109d5f6d9f853d0fec32e06b5dee911a4710f6edb2af39e97ecf5

See more details on using hashes here.

Provenance

The following attestation bundles were made for dde_ivp-0.1.3.tar.gz:

Publisher: main.yml on Menginventor/dde_ivp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dde_ivp-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: dde_ivp-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dde_ivp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ae53b3c14522b99a0781946865d373a20f680d9011f6d54f202a838b9a7ecc7d
MD5 5fa8f6592dce633383b74ed0e4e34b0a
BLAKE2b-256 e615bda00e46a287422d39991c2b4974c44faef390bc59a3fb324077b5fe9bd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dde_ivp-0.1.3-py3-none-any.whl:

Publisher: main.yml on Menginventor/dde_ivp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page