Metadata-Version: 2.4
Name: dysys
Version: 0.1.11
Summary: A package for working with system dynamics symbolically and numerically
License: BSD-3-Clause
License-File: LICENSE
Author: Rico Picone
Author-email: rpicone@stmartin.edu
Requires-Python: >=3.11,<4.0
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: control (>=0.10.2)
Requires-Dist: engcom (>=0.2.0)
Requires-Dist: matplotlib (>=3.8.3,<4.0.0)
Requires-Dist: numpy (>=2.4.0)
Requires-Dist: scipy (>=1.12.0,<2.0.0)
Requires-Dist: sympy (>=1.12,<2.0)
Description-Content-Type: text/markdown

![PyPI](https://img.shields.io/pypi/v/dysys?label=pypi%20package)
![](https://readthedocs.org/projects/dysys/badge/?version=latest&style=flat)

# DySys

A Python package for system dynamics and control systems utilities (using numpy, sympy, and control)

# Installation

This package now published on PyPI and can be installed with

```python
pip install dysys
```

# Usage

To import the package into a script, use

```python
import dysys as ds
```

## Symbolic State-Space Models

Create a symbolic state-space model:

```python
A = [[-4, -3, 0], [0, -8, 4], [0, 0, -1]]
B = [[0], [1], [0]]
C = [[0, 1, 0]]
D = [[0]]
sys = ds.sss(A, B, C, D)  # Create a symbolic state-space model
```

## Factoring a Transfer Function

```python
import dysys as ds
import control
import matplotlib.pyplot as plt
```

Define a transfer function using the `dysys` package as follows:

```python
H = ds.tf(
    [1_000_000, 300_000_000],  # Numerator coef's
    [1, 1030, 40200, 10_300_000, 100_000_000]  # Denominator coef's
)
```

Get a list of transfer functions that are the canonical factors of `H`{.py}:

```python
factors = H.factor_canonical(check=True)  # Check that the factors are correct
```

Print the factors:

```python
for factor in factors:
    print(factor)
```

$\frac{3}{1}$  
$\frac{0.003333 s + 1}{1}$  
$\frac{1 \times 10^{4}}{s^2 + 20 s + 1 \times 10^{4}}$  
$\frac{1}{0.1 s + 1}$  
$\frac{1}{0.001 s + 1}$

Generate a Bode plot:

```python
control.bode_plot([H] + factors, dB=True, wrap_phase=True)
plt.gcf().legend(
    list(map(lambda x: x._repr_latex_()[1:-1], [H] + factors)), 
    loc="outside center right",
)
plt.show()
```

![A Bode plot of each factor and the composite.](examples/factor-transfer-function/bode.svg)

# Issues

If you have issues, please report them on the [issues page](https://github.com/ricopicone/dysys/issues).

