{ "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", "< [Linear Approximation of a Multivariable Model](http://nbviewer.jupyter.org/github/jckantor/CBE30338/blob/master/notebooks/03.03-Linear-Approximation-of-a-Multivariable-Model.ipynb) | [Contents](toc.ipynb) | [One Compartment Pharmacokinetics](http://nbviewer.jupyter.org/github/jckantor/CBE30338/blob/master/notebooks/03.05-One-Compartment-Pharmacokinetics.ipynb) >
"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"# Fitting First Order plus Time Delay to Step Response"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"## Summary\n",
"\n",
"Linear first order plus time delay (FOPTD) models are often good approximations to process dynamics for process control applications. This notebook demonstrates the fitting of FOPTD models to step response data."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"## Initializations"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import control\n",
"from scipy.optimize import minimize"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"## First Order plus Time Delay Models"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### First Order Models\n",
"\n",
"A linear first-order plus time-delay model is a good approximation for many process control applications. Assume the manipulated process input, $u$, and measured process output, $y$, are initially at steady-state $u_0, y_0$. \n",
"\n",
"Without loss of generality, the response of a linear first-order system without time-delay can be written as a differential equation\n",
"\n",
"$$\\tau\\frac{d(y-y_0)}{dt} + (y-y_0) = K(u-u_0)$$\n",
"\n",
"or\n",
"\n",
"$$\\tau\\frac{dy}{dt} + (y-y_0) = K(u-u_0)$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"At time $t_0$, the input $u$ is changed to a new constant value $u_\\infty$. Provided the system is stable (i.e, $\\tau \\geq 0$), the new steady state value of $y$ will be \n",
"\n",
"$$y_\\infty = y_0 + K(u_\\infty - u_0)$$\n",
"\n",
"\n",
"The solution to the differential equation can be written in a number of useful forms.\n",
"\n",
"\\begin{align*}\n",
"y(t) & = y_0 + K(u_\\infty - u_0) (1 - e^{-(t-t_0)/\\tau)}) \\\\\n",
"\\\\\n",
"& = y_0 + (y_\\infty - y_0) (1 - e^{-(t-t_0)/\\tau)}) \\\\\n",
"\\\\\n",
"& = y_\\infty + (y_0 - y_\\infty)e^{-(t-t_0)/\\tau)}\n",
"\\end{align*}"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### Time Delay\n",
"\n",
"Chemical processes are frequently encumbered with time delays associated with the transport of materials, chemical measurement, or simply sluggish response to control inputs. A pure time delay is modeled by a single parameter, $\\tau_d$, such that \n",
"\n",
"$$y(t) = u(t-\\tau_d)$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### First Order plus Time Delay (FOPTD) \n",
"\n",
"If we add the time delay feature to the first order process described above, then\n",
"\n",
"\\begin{align*}\n",
"y(t) & = y_0 + K(u_\\infty - u_0) (1 - e^{-(t-\\tau_d - t_0)/\\tau)}) \\\\\n",
"\\\\\n",
"& = y_0 + (y_\\infty - y_0) (1 - e^{-(t-\\tau_d-t_0)/\\tau)}) \\\\\n",
"\\\\\n",
"& = y_\\infty + (y_0 - y_\\infty)e^{-(t-\\tau_d-t_0)/\\tau)}\n",
"\\end{align*}"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### Visualization\n",
"\n",
"First we write a function to compute the response of a first order system with time delay to a unit step input where $u_0 = 0$ and $u_\\infty = 1$. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def foptd(t, K=1, tau=1, tau_d=0):\n",
" tau_d = max(0,tau_d)\n",
" tau = max(0,tau)\n",
" return np.array([K*(1-np.exp(-(t-tau_d)/tau)) if t >= tau_d else 0 for t in t])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/plain": [
" "
]
}
],
"metadata": {
"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
}