A package for linear, time invariant control systems for symbolic python. This is very new and has only basic functionality as transforming StateSpaceModels and TransferFunctionModels into one another and evaluating the systems symbolicaly and numericaly. Furthermore the utils
module provides some basic tools the models
module uses.
There is a python installer for this package. You can download the .zip file in the dist
folder (which may not be up-to-date) or clone the whole repository using
git clone https://github.com/m3zz0m1x/LTI-Systems-for-Sympy.gitd
After extracting, cd in the direcory and run
python setup.py install
Include the modules in your program using:
from lti_systems import *
You can create a 'StateSpaceModel' object using four matrices (state space representation) or a or 'TransferFunctionModel' using a transfer matrix:
from sympy import * # needed for matrix class
var('a:d')
A, B, C, D = Matrix([a]), Matrix([b]), Matrix([c]), Matrix([d])
var('s, num, denom')
T = Matrix([num /denom], s)
ssm = StateSpaceModel([A, B, C, D])
tfm = TransferFunctionModel(T)
You can also create the models from one another:
ssm2 = StateSpaceModel(tfm)
tfm2 = TransferFunctionModel(ssm, s)
Models are always evaluated using the evaluate
method. It is done numercialy or symbolicaly, depending on the parameters of the call:
# symbolic evaluation:
var('t')
u = Matrix([Heaviside(t)])
x0 = zeros(1, 1)
t0 = 0
y = ssm.evaluate(u, x0, t, t0)
# numerical evaluation
import numpy as np
y_list = ssm.evaluate(u, x0, (t, np.arange(0, 10, 0.1)), t0)
Note that the only difference between the calls is that in the second one, t is substituted by (t, np.arange(0, 10, 0.1))
; a tuple of the symbol t and a list of times to evaluate for.
The first call will return a matrix valued expression in terms of t.
The second call will return a list of matrix valued outputs, matching the time input.
For details on syntax and additional methods, see the docstings of each class and its methods.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D