{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "*This notebook contains course material from [CBE30338](https://jckantor.github.io/CBE30338)\n", "by Jeffrey Kantor (jeff at nd.edu); the content is available [on Github](https://github.com/jckantor/CBE30338.git).\n", "The text is released under the [CC-BY-NC-ND-4.0 license](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode),\n", "and code is released under the [MIT license](https://opensource.org/licenses/MIT).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Frequency Domain Control Design](http://nbviewer.jupyter.org/github/jckantor/CBE30338/blob/master/notebooks/05.00-Frequency-Domain-Control-Design.ipynb) | [Contents](toc.ipynb) | [Closed-Loop Transfer Functions for Car Cruise Control](http://nbviewer.jupyter.org/github/jckantor/CBE30338/blob/master/notebooks/05.02-Closed--Loop-Transfer-Functions-for-Car-Cruise-Control.ipynb) >
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting Started with Transfer Functions\n",
"\n",
"The [Python Control Systems Library](https://github.com/python-control/python-control) provides basic tools for the analysis and design of linear feedback control systems. The library provides tools to specify transfer function and state space models, manipulate models using block diagram algebra, stability analysis, and perform time and frequency domain simulation.\n",
"\n",
"The purpose of these notes is to provide a quick start with the Python Control Systems Library. Consult the [Python Control Systems Documentation](http://python-control.readthedocs.io/en/latest/) for more details."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installation\n",
"\n",
"The [Python Control Systems Library](https://github.com/python-control/python-control) is not, unfortunately, a standard part of most standard Python distributions. On most systems, the following commands will perform the required one-time installation of the necessary software."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: slycot in /Users/jeff/anaconda/lib/python3.5/site-packages\n",
"Requirement already satisfied: control in /Users/jeff/anaconda/lib/python3.5/site-packages\n",
"Requirement already satisfied: matplotlib in /Users/jeff/anaconda/lib/python3.5/site-packages (from control)\n",
"Requirement already satisfied: numpy in /Users/jeff/anaconda/lib/python3.5/site-packages (from control)\n",
"Requirement already satisfied: scipy in /Users/jeff/anaconda/lib/python3.5/site-packages (from control)\n",
"Requirement already satisfied: six>=1.10 in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)\n",
"Requirement already satisfied: python-dateutil in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)\n",
"Requirement already satisfied: pytz in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)\n",
"Requirement already satisfied: cycler>=0.10 in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)\n",
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)\n"
]
}
],
"source": [
"!pip install slycot\n",
"!pip install control"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Library Usage\n",
"\n",
"The control systems library is designed to work with a simplified syntax where libraries are imported without the standard prefixes. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"import control.matlab as control"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Demonstration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step Response of Transfer Functions\n",
"\n",
"The following cells demonstrate the use of two functions in the control systems library, `tf` and `step`. Suppose a signal $y(s)$ is related to an input $u(s)$ by the formula\n",
"\n",
"$$y(s) = \\underbrace{\\frac{4.3}{3.2s + 1}}_{G(s)} u(s)$$\n",
"\n",
"The transfer function\n",
"\n",
"$$G(s) = \\frac{4.3}{3.2 s + 1}$$\n",
"\n",
"is represented in the control system libary using `tf(num,den)` where `num` and `den` list the coefficients of the numerator and denominator polynomials. "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" 4.3\n",
"---------\n",
"3.2 s + 1\n",
"\n"
]
}
],
"source": [
"G = control.tf([4.3],[3.2, 1])\n",
"print(G)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The step response is created and plotted as"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" "
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}