# Linear Approximation of Process Models¶

### Key Idea¶

Process models usually exhibit some form of non-linearity due to the multiplication of an extensive flowrate and an intensive thermodynamic state variable, chemical kinetics, or various types of transport phenomenon. Near a steady-state, however, an approximate linear models often provide a 'good-enough' dynamical model for control design and analysis. Here we show how a linear approximation is constructed using a Taylor series expansion.

### Why is this Important?¶

As we will learn later in this course, linear models are amenable to control design and analysis. For process systems that will be operated near a steady-state, linear models provide a useful framework for control design.

## Procedure for a Single Variable System¶

We start with a process model that consists of a single first-order ordinary differential equation of the form

$$\frac{dh}{dt}=f(h,q)$$

where $h$ is the state variable and $q$ is an input variable. Choose a nominal value for the process input $q$, we'll call this nominal value $\bar{q}$. The following procedure will produce a linear approximate valid near the steady-state.

##### Step 1. Find a Nominal Steady State Operating Condition¶

Find the steady-state value of $h$ by solving

$$0=f(\bar{h},\bar{q})$$

where $\bar{q}$ is a nominal (i.e, typical, or desired value) of a manipulated process variable.

##### Step 2. Define deviation variables¶
\begin{eqnarray*} x & = & h-\bar{h}\\ u & = & q-\bar{q} \end{eqnarray*}
##### Step 3. Taylor Series Expansion¶

Compute the first terms in the Taylor series and evaluate at steady-state. The higher-order terms are not needed provided the lower-order terms are non-zero and the deviations are small. $$f(\bar{h}+x,\bar{q}+u)\approx f(\bar{h},\bar{q})+\left.\frac{\partial f}{\partial h}\right|_{\bar{h},\bar{q}}x+\left.\frac{\partial f}{\partial q}\right|_{\bar{h},\bar{q}}u+\cdots$$

##### Step 4. Linear Approximation¶

The linear approximation is $$\frac{dx}{dt}=\underbrace{\left.\frac{\partial f}{\partial h}\right|_{\bar{h},\bar{q}}}_{a}x+\underbrace{\left.\frac{\partial f}{\partial q}\right|_{\bar{h},\bar{q}}}_{b}u$$

### Example: Gravity Drained Tank¶

A simple model for the liquid height in a gravity-drained tank with cross-sectional area $A$ is

$$A\frac{dh}{dt}=q_{in}-C\sqrt{h}$$

where $q_{in}$ is a volumetric inflow and $C$ is a constant associated with the drain. This is a non-linear process model that can be written

$$\frac{dh}{dt}=f(h,q_{in})$$

where

$$f(h,q_{in})=\frac{1}{A}\left(q_{in}-C\sqrt{h}\right)$$

Given a nominal inlet flowrate $\bar{q}_{in}$, the steady state value of $h$, that is $\bar{h}$, is found by solving the steady state equation

$$0=f(\bar{h},\bar{q}_{in})=\frac{1}{A}\left(\bar{q}_{in}-C\sqrt{\bar{h}}\right)$$

which gives

$$\bar{h}=\frac{\bar{q}_{in}^{2}}{C^{2}}$$

It's interesting to note the steady-state height of the liquid in a gravity-drained tank is proportional to the square of the nominal flowrate. A 50\% increase in flowrate more than doubles the liquid height.

Let $x$ and $u$ represent the deviations from steady-state

\begin{eqnarray*} x & = & h-\bar{h}\\ u & = & q-\bar{q} \end{eqnarray*}

Then

\begin{eqnarray*} \frac{d(\bar{h}+x)}{dt} & = & \frac{1}{A}\left(\bar{q}_{in}+u-C\sqrt{\bar{h}+x}\right) \end{eqnarray*}

The Taylor series expansion

$$f(\bar{h}+x,\bar{q}_{in}+u)\approx f(\bar{h},\bar{q}_{in})+\left.\frac{\partial f}{\partial h}\right|_{\bar{h},\bar{q}}x+\left.\frac{\partial f}{\partial q}\right|_{\bar{h},\bar{q}}u+\frac{1}{2}\left.\frac{\partial^{2}f}{\partial h^{2}}\right|_{\bar{h}}x^{2}\cdots$$

For this example

$$\frac{dx}{dt}=\left(-\frac{C}{2A\sqrt{\bar{h}}}\right)x+\left(\frac{1}{A}\right)u$$

An alternative form of the model is found by substituting the solution for $\bar{h}$. While these have somewhat different analytical expressions for a given application they will yield identical numerical results.

$$\frac{dx}{dt}=\left(-\frac{C^{2}}{2A\bar{q}_{in}}\right)x+\left(\frac{1}{A}\right)u$$

How well does this approximation work?

This question can be answered by comparing the results of two simulations. In the first case the simulation consists of integrating

$$A\frac{dh}{dt}=q_{in}-C\sqrt{h}$$

as shown in the graph below.

where $A=1$, $C=2$, initial condition $h(0)=0$, and a constant input $q_{in}=\bar{q}_{in}=1$. For these parameter values, the approximate linear model for the deviation from steady-state is given by

\begin{eqnarray*} \frac{dx}{dt} & = & \left(-\frac{C^{2}}{2A\bar{q}_{in}}\right)x+\left(\frac{1}{A}\right)u\\ \\ & = & -2\,x+u \end{eqnarray*}

In terms of deviations from steady state, the input $u=q_{in}-\bar{q}_{in}=0$ and the initial conditionis $x(0)=h(0)-\bar{h}=-\bar{h}$. Plotting $h(t)$ and $x(t)+\bar{h}$ on the same axis produces the results shown in Figure \ref{fig:LinearApproximation}.

In [11]:
#Simulation of a Gravity-Drained Tank

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint

# parameter values
qin = 1
A = 1
C = 2

hbar = (qin/C)**2

# nonlinear simulation
def hdot(h,t):
return (qin - C*np.sqrt(h))/A

t = np.linspace(0,5)
h = odeint(hdot,[0],t)

# linear approximation
a = -C**2/2/A/qin
b = 1/A

def xdot(x,t):
return a*x + b*u

u = 0
x = odeint(xdot,[-hbar],t)

# visualization
plt.plot(t,h)
plt.plot(t,x+hbar)
plt.legend(['Nonlinear','Linear Approximation'],loc='lower right')
plt.xlabel('Time [min]')
plt.ylabel('Height [m]')
plt.title('Gravity-drained tank: Nonlinear model vs. linear approximation')
plt.grid()


### Exercises¶

1. Suppose you have a tank with an cross-sectional area of 1 square meter, a steady inlet flow $\bar{q}_{in}=10$ liters/min, and observe a liquid height of 0.5 meters. What is the constant $C$? What is the characteristic time constant for the tank?

2. You have an elementary reaction

$$2{\cal A}\longrightarrow Products$$

carried out under isothermal conditions in a stirred tank of volume $V$. The reaction rate is given by the expression

$$R_{A}=k_{A}C_{A}^{2}$$

and the inlet concentration to the tank is $C_{A,in}$ at flowrate $q$. Construct a linear approximation for the dynamics of this process in the neighborhood of a steady state.

## Multivariable Systems¶

### Key Idea¶

Most process models consist of more than a single state and a single input. Techniques for linearization extend naturally to multivariable systems. The most convenient mathematical tools involve some linear algebra.

### Example: Gravity Drained Tanks¶

Here we develop a linear approximation to a process model for a system consisting of coupled gravity-drained tanks.

##### Model¶
\begin{eqnarray*} A_{1}\frac{dh_{1}}{dt} & = & q_{in}-C_{1}\sqrt{h_{1}}\\ A_{2}\frac{dh_{2}}{dt} & = & q_{d}+C_{1}\sqrt{h_{1}}-C_{2}\sqrt{h_{2}} \end{eqnarray*}
##### Nominal Inputs¶
\begin{eqnarray*} \bar{q}_{in} & = & \bar{q}_{in}\\ \bar{q}_{d} & = & 0 \end{eqnarray*}
##### Steady State for nominal input¶
\begin{eqnarray*} \bar{h}_{1} & = & \frac{\bar{q}_{in}^{2}}{C_{1}^{2}}\\ \bar{h}_{2} & = & \frac{\bar{q}_{in}^{2}}{C_{2}^{2}} \end{eqnarray*}
##### Deviation Variables¶

States

\begin{eqnarray*} x_{1} & = & h_{1}-\bar{h}_{1}\\ x_{2} & = & h_{2}-\bar{h}_{2} \end{eqnarray*}

Control input $$u=q_{in}-\bar{q}_{in}$$

Disturbance input $$d=q_{d}-\bar{q}_{d}$$

Measured output $$y=h_{2}-\bar{h}_{2}$$

##### Linearization¶
\begin{eqnarray*} \frac{dh_{1}}{dt} & = & \frac{1}{A_{1}}\left(q_{in}-C_{1}\sqrt{h_{1}}\right)=f_{1}(h_{1},h_{2},q_{in},q_{d})\\ \frac{dh_{2}}{dt} & = & \frac{1}{A_{2}}\left(q_{d}+C_{1}\sqrt{h_{1}}-C_{2}\sqrt{h_{2}}\right)=f_{2}(h_{1},h_{2},q_{in},q_{d}) \end{eqnarray*}

Taylor series expansion for the first tank

\begin{eqnarray*} \frac{dx_{1}}{dt} & = & f_{1}(\bar{h}_{1}+x_{1},\bar{h}_{2}+x_{2},\bar{q}_{in}+u,\bar{q}_{d}+d)\\ & \approx & \underbrace{f_{1}(\bar{h}_{1},\bar{h}_{2},\bar{q}_{in})}_{0}+\left.\frac{\partial f_{1}}{\partial h_{1}}\right|_{SS}x_{1}+\left.\frac{\partial f_{1}}{\partial h_{2}}\right|_{SS}x_{2}+\left.\frac{\partial f_{1}}{\partial q_{in}}\right|_{SS}u+\left.\frac{\partial f_{1}}{\partial q_{d}}\right|_{SS}d\\ & \approx & \left(-\frac{C_{1}}{2A_{1}\sqrt{\bar{h}_{1}}}\right)x_{1}+\left(0\right)x_{2}+\left(\frac{1}{A_{1}}\right)u+\left(0\right)d\\ & \approx & \left(-\frac{C_{1}^{2}}{2A_{1}\bar{q}_{in}}\right)x_{1}+\left(\frac{1}{A_{1}}\right)u \end{eqnarray*}

Taylor series expansion for the second tank

\begin{eqnarray*} \frac{dx_{2}}{dt} & = & f_{2}(\bar{h}_{1}+x_{1},\bar{h}_{2}+x_{2},\bar{q}_{in}+u,\bar{q}_{d}+d)\\ & \approx & \underbrace{f_{2}(\bar{h}_{1},\bar{h}_{2},\bar{q}_{in})}_{0}+\left.\frac{\partial f_{2}}{\partial h_{1}}\right|_{SS}x_{1}+\left.\frac{\partial f_{2}}{\partial h_{2}}\right|_{SS}x_{2}+\left.\frac{\partial f_{2}}{\partial q_{in}}\right|_{SS}u+\left.\frac{\partial f_{2}}{\partial q_{d}}\right|_{SS}d\\ & \approx & \left(\frac{C_{1}}{2A_{2}\sqrt{\bar{h}_{1}}}\right)x_{1}+\left(-\frac{C_{2}}{2A_{2}\sqrt{\bar{h}_{2}}}\right)x_{2}+\left(0\right)u+\left(\frac{1}{A_{2}}\right)d\\ & \approx & \left(\frac{C_{1}^{2}}{2A_{2}\bar{q}_{in}}\right)x_{1}+\left(-\frac{C_{2}^{2}}{2A_{2}\bar{q}_{in}}\right)x_{2}+\left(\frac{1}{A_{2}}\right)d \end{eqnarray*}

Measured outputs

\begin{eqnarray*} y & = & h_{2}-\bar{h}_{2}\\ & = & x_{2} \end{eqnarray*}
##### Summary of the linear model using matrix/vector notation¶
\begin{eqnarray*} \frac{d}{dt}\left[\begin{array}{c} x_{1}\\ x_{2} \end{array}\right] & = & \left[\begin{array}{cc} -\frac{C_{1}^{2}}{2A_{1}\bar{q}_{in}} & 0\\ \frac{C_{1}^{2}}{2A_{2}\bar{q}_{in}} & -\frac{C_{2}^{2}}{2A_{2}\bar{q}_{in}} \end{array}\right]\left[\begin{array}{c} x_{1}\\ x_{2} \end{array}\right]+\left[\begin{array}{c} \frac{1}{A_{1}}\\ 0 \end{array}\right]u+\left[\begin{array}{c} 0\\ \frac{1}{A_{2}} \end{array}\right]d\\ y & = & \left[\begin{array}{cc} 0 & 1\end{array}\right]\left[\begin{array}{c} x_{1}\\ x_{2} \end{array}\right]+\left[\begin{array}{c} 0\end{array}\right]u+\left[\begin{array}{c} 0\end{array}\right]d \end{eqnarray*}

### Exercises¶

##### 1. First Order Reaction in a CSTR¶

A first-order reaction

$$A\longrightarrow\mbox{Products}$$

takes place in an isothermal CSTR with constant volume $V$, volumetric flowrate in and out the same value $q$, reaction rate constant $k$, and feed concentration $c_{AF}$.

• Write the material balance equation for this system as a first-order ordinary differential equation.
• Algebraically determine the steady-state solution to this equation.
• For what values of $q$, $k$, $V$, and $c_{AF}$ is this stable?
• For a particular reaction $k$ = 2 1/min. We run this reaction in a vessel of volume $V$ =10 liters, volumetric flowrate $q$ = 50 liters/min. The desired exit concentrationof $A$ is $0.1$ gmol/liter. Assume that we can manipulate $c_{AF}$, the concentration of $A$ entering the CSTR, with proportional control, in order to control the concentration of $A$ exiting the reactor. Substitute the appropriate control law into the mathematical model and rearrange it to get a model of the same form as part (a).
• Determine the steady-state solution to this equation. If we set $K_{c}=100$, what is the absolute value of the offset between the exit concentration of $A$ and the desired exit concentration of $A$?
##### 2. Two Gravity Drained Tanks in Series¶

Consider the two-tank model. Assuming the tanks are identical, and using the same parameter values as used for the single gravity-drained tank, compute values for all coefficients appearing in the multivariable linear model. Is the system stable? What makes you think so?

##### 3. Isothermal CSTR with second-order reaction¶

Consider an isothermal CSTR with a single reaction $$A\longrightarrow\mbox{Products}$$ whose reaction rate is second-order. Assume constant volume, $V$, and density, $\rho$, and a time-dependent volumetric flow rate $q(t)$. The input to the reactor has concentration $c_{A,in}$.

• Write the modeling equation for this system.
• Assume that the state variable is the concentration of $A$ in the output, $c_{A}$, and the flow rate $q$ is an input variable. There is a steady-state operating point corresponding to $q=1$ L/min. Other parameters are $k=1$ L/mol/min, $V=2$ L, $c_{A,in}=2$ mol/L. Find the linearized model for $\frac{dc'_{A}}{dt}$ valid in the neighborhood of this steady state.
In [ ]: