{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Creating Sliders in Jupyter Notebooks\n",
"\n",
"This notebook illustrates how to create sliders using `ipywidgets` for interactive plots.\n",
"\n",
"### Credits:\n",
"Some materials developed in this notebook were inspired by https://github.com/jckantor/CBE30338"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Simple Slider"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We'll start by creating a plot to visualize the step response of a transfer function. We'll use an ipywidgets slider to manipulate process parameters and see how the response changes with $K_p$ and $\\tau_I$."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Import the libraries we'll need\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_formats = {'svg',} # svg makes the figures look nicer\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import control\n",
"import warnings\n",
"warnings.filterwarnings('ignore') #suppress all warnings"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Define the transfer function\n",
"def tf(K_p, tau_I, print_variables=False):\n",
" G = control.tf([1],[1,0]) # Transfer function for the process\n",
" G_c = K_p*control.tf([tau_I,1],[tau_I*1,0]) # Transfer function for the controller\n",
" sys = G_c*G/(1+G_c*G) # The closed loop transfer function\n",
" if print_variables:\n",
" print('Process TF: ', G)\n",
" print('Controller TF: ', G_c)\n",
" print('Closed-Loop TF: ', sys)\n",
" return sys, T"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Process TF: \n",
"1\n",
"-\n",
"s\n",
"\n",
"Controller TF: \n",
"s + 1\n",
"-----\n",
" s\n",
"\n",
"Closed-Loop TF: \n",
" s^3 + s^2\n",
"---------------\n",
"s^4 + s^3 + s^2\n",
"\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"