{ "cells": [ { "cell_type": "markdown", "metadata": { "nbpages": { "level": 0, "link": "[](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html)", "section": "" } }, "source": [ "\n", "*This notebook contains material from [CBE30338](https://jckantor.github.io/CBE30338);\n", "content is available [on Github](https://github.com/jckantor/CBE30338.git).*\n" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 0, "link": "[](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html)", "section": "" } }, "source": [ "\n", "< [3.3 Linear Approximation of a Multivariable Model](https://jckantor.github.io/CBE30338/03.03-Linear-Approximation-of-a-Multivariable-Model.html) | [Contents](toc.html) | [Tag Index](tag_index.html) | [3.5 One Compartment Pharmacokinetics](https://jckantor.github.io/CBE30338/03.05-One-Compartment-Pharmacokinetics.html) >
"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[3.4 Fitting First Order plus Time Delay to Step Response](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4-Fitting-First-Order-plus-Time-Delay-to-Step-Response)",
"section": "3.4 Fitting First Order plus Time Delay to Step Response"
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"# 3.4 Fitting First Order plus Time Delay to Step Response"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 2,
"link": "[3.4.1 Summary](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.1-Summary)",
"section": "3.4.1 Summary"
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"## 3.4.1 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": {
"nbpages": {
"level": 2,
"link": "[3.4.2 Initializations](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.2-Initializations)",
"section": "3.4.2 Initializations"
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"## 3.4.2 Initializations"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"nbpages": {
"level": 2,
"link": "[3.4.2 Initializations](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.2-Initializations)",
"section": "3.4.2 Initializations"
}
},
"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": {
"nbpages": {
"level": 2,
"link": "[3.4.3 First Order plus Time Delay Models](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3-First-Order-plus-Time-Delay-Models)",
"section": "3.4.3 First Order plus Time Delay Models"
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"## 3.4.3 First Order plus Time Delay Models"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 3,
"link": "[3.4.3.1 First Order Models](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3.1-First-Order-Models)",
"section": "3.4.3.1 First Order Models"
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### 3.4.3.1 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": {
"nbpages": {
"level": 3,
"link": "[3.4.3.1 First Order Models](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3.1-First-Order-Models)",
"section": "3.4.3.1 First Order Models"
},
"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": {
"nbpages": {
"level": 3,
"link": "[3.4.3.2 Time Delay](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3.2-Time-Delay)",
"section": "3.4.3.2 Time Delay"
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### 3.4.3.2 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": {
"nbpages": {
"level": 3,
"link": "[3.4.3.3 First Order plus Time Delay (FOPTD) ](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3.3-First-Order-plus-Time-Delay-(FOPTD))",
"section": "3.4.3.3 First Order plus Time Delay (FOPTD) "
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### 3.4.3.3 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": {
"nbpages": {
"level": 3,
"link": "[3.4.3.4 Visualization](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3.4-Visualization)",
"section": "3.4.3.4 Visualization"
},
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### 3.4.3.4 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": {
"nbpages": {
"level": 3,
"link": "[3.4.3.4 Visualization](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3.4-Visualization)",
"section": "3.4.3.4 Visualization"
}
},
"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": {
"nbpages": {
"level": 3,
"link": "[3.4.3.4 Visualization](https://jckantor.github.io/CBE30338/03.04-Fitting-First-Order-plus-Time-Delay-to-Step-Response.html#3.4.3.4-Visualization)",
"section": "3.4.3.4 Visualization"
},
"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
}