A package for solving delay differential equations
Project description
DDE_IVP
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
RK23andRK45. - Compatible with SciPy's
solve_ivpinterface 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 (RK23orRK45).t_eval: Array. Time points to evaluate the solution.events: Callable or list of callables. Event functions for detecting zero-crossings.vectorized: Bool. Whetherfunis vectorized.
Returns:
- An
OptimizeResultobject containing the solution, events, and status.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and test them.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abe4825a532829c79b0123f2ee984ddd2d7f9f0b2f807c4254c0a5b296a0be67
|
|
| MD5 |
b9f7a687891ce56a5d5f87034d672f62
|
|
| BLAKE2b-256 |
410ec4db5c0109d5f6d9f853d0fec32e06b5dee911a4710f6edb2af39e97ecf5
|
Provenance
The following attestation bundles were made for dde_ivp-0.1.3.tar.gz:
Publisher:
main.yml on Menginventor/dde_ivp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dde_ivp-0.1.3.tar.gz -
Subject digest:
abe4825a532829c79b0123f2ee984ddd2d7f9f0b2f807c4254c0a5b296a0be67 - Sigstore transparency entry: 154761079
- Sigstore integration time:
-
Permalink:
Menginventor/dde_ivp@192a7de6cd827bde5fc002e68f7fa8a1e6ebe68e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Menginventor
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@192a7de6cd827bde5fc002e68f7fa8a1e6ebe68e -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae53b3c14522b99a0781946865d373a20f680d9011f6d54f202a838b9a7ecc7d
|
|
| MD5 |
5fa8f6592dce633383b74ed0e4e34b0a
|
|
| BLAKE2b-256 |
e615bda00e46a287422d39991c2b4974c44faef390bc59a3fb324077b5fe9bd9
|
Provenance
The following attestation bundles were made for dde_ivp-0.1.3-py3-none-any.whl:
Publisher:
main.yml on Menginventor/dde_ivp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dde_ivp-0.1.3-py3-none-any.whl -
Subject digest:
ae53b3c14522b99a0781946865d373a20f680d9011f6d54f202a838b9a7ecc7d - Sigstore transparency entry: 154761081
- Sigstore integration time:
-
Permalink:
Menginventor/dde_ivp@192a7de6cd827bde5fc002e68f7fa8a1e6ebe68e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Menginventor
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@192a7de6cd827bde5fc002e68f7fa8a1e6ebe68e -
Trigger Event:
push
-
Statement type: