# The Recipe to Build a Mathematical Model

• Liliane Maria Ferrareso Lona
Chapter

## Abstract

Most chemical engineering students feel a shiver down the spine when they see a set of complex mathematical equations generated from the modeling of a chemical engineering system. This is because they usually do not understand how to achieve this mathematical model, or they do not know how to solve the equation system without spending a lot of time and effort.

Most chemical engineering students feel a shiver down the spine when they see a set of complex mathematical equations generated from the modeling of a chemical engineering system. This is because they usually do not understand how to achieve this mathematical model, or they do not know how to solve the equations system without spending a lot of time and effort.

Trying to understand how to generate a set of mathematical equations to represent a physical system (to model) and how to solve these equations (to simulate) is not a simple task. A model, most of the time, takes into account all phenomena studied during a chemical engineering course (mass, energy and momentum transfer, chemical reactions, etc.). In the same way, there is a multitude of numerical methods that can be used to solve the same set of equations generated from the modeling, and many different computational languages can be adopted to implement the numerical methods. As a consequence of this comprehensiveness and the combinatorial explosion of possibilities, most books that deal with this subject are very comprehensive, requiring a lot of time and effort to go through the subject.

This book tries to deal with this modeling and simulation issue in a simple, fast, and friendly way, using what you already know or what you can intuitively or easily understand to build a model step by step and, after that, solve it using Excel, a very friendly and widely used tool.

This chapter starts by showing that even if you are a lower undergraduate student, you already known how to do mental calculations to model and simulate simple problems. To prove that, let us imagine a cylindrical tank initially containing 10 m3 of water. Let us also imagine that the input and output valves in this tank operate at the same volumetric flow rate (2 m3/h), as shown in Fig. 2.1. Assume that the density of water remains constant all the time. Fig. 2.1 Tank of water with an initial volume equal to 10 m3

The first question is: 2 h later, what is the volume of water inside the tank? If you say 10 m3, you are correct. The flow rate that enters the tank is equal to the flow rate that exits (2 m3/s), so the volume of water in the tank remains constant (10 m3).

Now, if the input volumetric flow rate changes to 3 m3/h and the flow rate at the exit remains at 2 m3/h, what is the volume of water in the tank after 2 h? If you correctly say 12 m3, it is because you mentally develop a model to represent this tank and after that you simulate it. When the inflow rate becomes 3 m3/h, by inspection one can conclude easily that the volume of water will increase 1 m3 in each hour.

Unfortunately, you only know how to do mental modeling and simulation if the problem is very simple. In order to understand how to model and simulate complex systems, let us try to understand what was mentally done in this simple example and transform that into a step-by-step procedure that is robust enough to successfully work also for very complex systems.

## 2.1 The Recipe

In order to build a mathematical model, three fundamental concepts are used:
1. 1.
Conservation Law : The conservation law says that what enters the system (E), minus what leaves the system (L), plus what is generated in the system (G), minus what is consumed (C) in the system, is equal to the accumulation in the system (A); or:
$$\mathrm{E}\hbox{--} \mathrm{L}+\mathrm{G}\hbox{--} \mathrm{C}=\mathrm{A}$$

The accumulation is the variation that occurs in a period of time. This accumulation can be positive or negative, i.e., if what enters plus what is generated in the system is greater than what leaves plus what is consumed in this system, there is a positive accumulation. Otherwise, there is a negative accumulation.

When developing mass and energy balances in the problems presented in this book, we will assume that terms of generation and/or consumption can exist if there are chemical reactions. For example, there is energy generation if there is an exothermic chemical reaction , which will result in an increase in temperature.

2. 2.

Control volume : The control volume is the volume in which the model is developed and the conservation law is applied. All variables (concentration, temperature, density, etc.) have to be uniform inside the control volume. In the example of the tank presented previously, all variables do not change with the position inside the tank (a lumped-parameter problem), so the control volume is the entire tank.

3. 3.
Infinitesimal variation of the dependent variable with the independent variable : Imagine that a dependent variable y varies with x (an independent variable) according to the function shown in Fig. 2.2. Also imagine that in an initial condition x0 the initial value of y is y0. To estimate the value of the dependent variable y after an infinitesimal increment in xx), one can draw a tangent line to the curve starting from the point (x0, y0), as shown in Fig. 2.2. Fig. 2.2 Variation of the dependent variable y with the independent variable x

The tangent line reaches v1 at x = x1 (x1 = x0 + Δx). If the increment Δx is sufficiently small, it follows that y1 ≅ v1, and it is possible to obtain the value of y1 using the concept tangent of α:
$${\left.\tan \alpha =\frac{y_1-{y}_0}{x_1-{x}_0}=\frac{dy}{dx}\right|}_{x_0,{y}_0}$$
so:
$${\left.{y}_1={y}_0+\Delta x\frac{dy}{dx}\right|}_{x_0,{y}_0}$$
Generalizing and simplifying the way to show the index of the derivative:
$${y}_{i+1}={y}_i+\frac{dy_i}{dx}\Delta x$$
(2.1)
Equation (2.1) could be also obtained using the first term of a Taylor series expansion (Eq. 2.2):
$${y}_{i+1}\cong {y}_i+\frac{dy_i}{dx}\Delta x+\frac{1}{2!}\frac{d^2{y}_i}{dx^2}{\left(\Delta x\right)}^2+\frac{1}{3!}\frac{d^3{y}_i}{dx^3}{\left(\Delta x\right)}^3+\frac{1}{4!}\frac{d^4{y}_i}{dx^4}{\left(\Delta x\right)}^4+\kern0.5em \cdots$$
(2.2)
For all systems presented in this book, the same recipe will be used to obtain the mathematical model, following the three steps:

## 2.2 The Recipe Applied to a Simple System

Keeping in mind the three fundamental concepts presented in Sect. 2.1, let us apply the step-by-step procedure (the recipe) to model the tank presented previously. This procedure, used to model this simple system, will be the same used throughout the entire book, in order to solve more and more complex problems.

As stated in Sect. 2.1, the entire tank must be considered as the control volume because we are dealing with a lumped-parameter problem. The dashed line in Fig. 2.3 shows the control volume considered in this case. Fig. 2.3 Tank of water with the control volume used in the modeling
The application of the conservation law to the control volume yields the expression presented by Eq. (2.3) (observe that there is neither generation nor consumption of water):
$$\mathrm{E}\hbox{--} \mathrm{L}=\mathrm{A}$$
(2.3)

The E and L terms can be easily obtained, since the flow rates that enter and leave the tank are known (3 m3/h and 2 m3/h, respectively); however, how can the accumulation term be obtained?

In order to obtain the accumulation term, we can use the concept of the infinitesimal variation of the dependent variable with the independent variable . So if we say that at a time t the mass of water in the tank is M (kg), after an infinitesimal period of time (Δt) the mass of water in the tank will be $$M+\frac{dM}{dt}\Delta t$$ (kg) (see analogy with Eq. (2.1)). The table below summarizes this information.
 t t + Δt Dimension M $$M+\frac{dM}{dt}\Delta t$$ kg
The amount of water accumulated in the tank in a period of time Δt is the mass of water at the time t + Δt minus the mass of water at the time t, so the accumulation term (A) is given by:
$$A=M+\frac{dM}{dt}\Delta t-M$$
or:
$$A=\frac{dM}{dt}\Delta t\kern1em \left(\mathrm{kg}\right)$$
Since the mass is the density times the volume (M = ρV) and the density remains constant, the accumulation term can also be written as:
$$A=\rho \frac{dV}{dt}\Delta t\kern1em \left(\mathrm{kg}\right)$$

A very important tool to check if a model is correct is to do a dimensional analysis on all terms of the conservation law equation.

If we calculate how much water accumulates in the tank in a period of time Δt, we have to consider how much water enters and leaves the tank in this same interval of time (Δt). So, in a period of time Δt, the amount of water that enters and leaves the tank is:
$$\mathrm{E}=3\left({\mathrm{m}}^3/\mathrm{h}\right)\ \rho \left(\mathrm{kg}/{\mathrm{m}}^3\right)\ \Delta t\left(\mathrm{h}\right)\kern1em \to \kern1em \mathrm{E}=3\rho\ \Delta t\left(\mathrm{kg}\right)$$
$$\mathrm{L}=2\left({\mathrm{m}}^3/\mathrm{h}\right)\ \rho \left(\mathrm{kg}/{\mathrm{m}}^3\right)\ \Delta t\left(\mathrm{h}\right)\kern1em \to \kern1em \mathrm{L}=2\rho\ \Delta t\left(\mathrm{kg}\right)$$
so applying the conservation law for the period of time Δt yields:
$$\underset{\mathrm{Enters}\ \left(\mathrm{E}\right)}{\underbrace{3\rho \Delta t\left(\mathrm{kg}\right)}}-\underset{\mathrm{Leaves}\ \left(\mathrm{L}\right)}{\underbrace{2\rho \Delta t\left(\mathrm{kg}\right)}}=\underset{\mathrm{Accumulation}\ \left(\mathrm{A}\right)}{\underbrace{\rho \frac{dV}{dt}\Delta t\left(\mathrm{kg}\right)}}$$
(2.4)
Observe that the density (ρ) is present in the three terms of the mass balance , so Eq. (2.4) can be simplified. In this way, we can conclude that when the density remains constant, we can directly do the volume balance (instead of mass balance). In this case, the accumulation term, as well as the terms E and L, could be obtained as shown below:
 t t + Δt Accumulation Dimension V $$V+\frac{dV}{dt}\Delta t$$ $$\frac{dV}{dt}\Delta t$$ m3
$$\mathrm{E}=3\left({\mathrm{m}}^3/\mathrm{h}\right)\Delta t\left(\mathrm{h}\right)\kern1em \to \kern1em \mathrm{E}=3\Delta t\left({\mathrm{m}}^3\right)$$
$$\mathrm{L}=2\left({\mathrm{m}}^3/\mathrm{h}\right)\Delta t\left(\mathrm{h}\right)\kern1em \to \kern1em \mathrm{L}=2\Delta t\left({\mathrm{m}}^3\right)$$
so the balance becomes:
$$\underset{\mathrm{Enters}\ \left(\mathrm{E}\right)}{\underbrace{3\Delta t\left({\mathrm{m}}^3\right)}}-\underset{\mathrm{Leaves}\ \left(\mathrm{L}\right)}{\underbrace{2\Delta t\left({\mathrm{m}}^3\right)}}=\underset{\mathrm{Accumulation}\ \left(\mathrm{A}\right)}{\underbrace{\frac{dV}{dt}\Delta t\left({\mathrm{m}}^3\right)}}$$
(2.5)
Observe that Eqs. (2.4) and (2.5) are the same, and after simplifying terms this yields:
$$\frac{dV}{dt}=1$$
(2.6)

Equation (2.6) represents the model for this simple system and agrees with the mental calculation you did previously. Having completed the modeling stage, we need to do the simulation, which is nothing more than solving, by analytical or numerical methods, the equations generated from the modeling. In our case, as the system is greatly simplified, a single and very simple ordinary differential equation (ODE) is generated from the modeling, and it will be solved by direct integration.

To solve this ODE, one initial condition is necessary. In our case, we know that in the beginning of the operation, the volume of water in the tank is 10 m3. So the initial condition is:
$$\mathrm{At}\kern0.62em t=0,\kern0.62em V=10\ {\mathrm{m}}^3$$
Solving Eq. (2.6) using the initial conditions yields:
$$V=10+t$$
(2.7)

Equation (2.7) shows how the volume of liquid in the tank varies with time, making it possible to predict, for example, the time it takes for the liquid to overflow the tank (also observe that the equation says that after 2 h, the volume of water is 12 m3, as predicted previously).

The procedure adopted for this simple example will be used from now on for more and more complex examples.

### Proposed Problem

2.1) Develop a model for the tank presented in Fig. 2.3, but consider that the flow rate of water that leaves the tank (Q out , m3/h) depends on the level of the water (h) inside the tank, in the way Q out  = 1 + 0.1h (m3/h). This can be a real situation because as the column of water increases, the pressure on the exit point also increases, and consequently the exit flow rate becomes greater. Assuming that the initial volume of water inside the tank is equal to 10 m3 and the cross-sectional area of this tank is equal to 1 m2, the initial level of water (h) is 10 m, so in the beginning, the flow rate that leaves the tank (Q out ) is equal to 2 m3/h. In the beginning, the input flow rate is equal to 2 m3/h, so the volume of water remains constant, in a steady-state regime. If for some reason the inflow rate varies from 2 to 3 m3/h, develop a mathematical model to represent how the level of water inside the tank varies with time. Define the initial condition needed to solve the equation generated from the modeling.