Why am I going to use Python instead of Matlab? Well, I hate Matlab with passion, yet sadly, nearly everyone uses it. I'm a fan of Python and open source stuff so, it is natural to use it in the course. And, What is Jupyther notebook? Jupyter Notebook is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. This was intended to run Python code, although it currently supports other languages.
First, you have to set the working environment:
Observe and execute the following code:
In [ ]:
import sympy
from sympy import *
sympy.init_printing()
s = Symbol('s')
With this it is now possible to define transfer functions, for example:
In [ ]:
G1 = 1/(s+1)
Unlike Matlab, nothing is presented here if we do not explicitly ask for it, for example:
In [ ]:
G1
Let's look at another example:
In [ ]:
G2 = 10*s/(s+10)
In [ ]:
G2
In [ ]:
G = G1*G2
In [ ]:
G
We can expand the bottom using the .expand() method:
In [ ]:
G.expand()
As an annotation: G.expand() = expand(G)
And factorize it again with the .factor() method:
In [ ]:
Out[8].factor()
We can do something more complex like:
In [ ]:
G = 0.30*(s+0.05)*(s**2+1600.0)/((s**2+0.05*s+16.0)*(s+70.0))
In [ ]:
G
In [ ]:
G.expand()
Which is really nice because it does all the multiplication for us... and it’s much prettier than Matlab!
Note: Use floats (number including a decimal) for all values you insert!