Professional Documents
Culture Documents
University of Technology
Mathematical
Modeling and
Numerical Analysis
1.1 Introduction
The objective of mathematical modeling is the development of sets of quantitative
(mathematical) expressions that capture the essentials aspects of an existing system.
A mathematical model can assist in understanding the complex physical interactions
in the system and the causes and effects between the system variables. Mathematical
models are valuable tools since they are abstract equations that can be solved and
analyzed using computer calculations. It is therefore safer and cheaper to perform test
on the model using computer simulations rather than to carry out repetitive
experimentations and observations on the real system. This becomes vital if the real
system is new, hazardous, or expensive to operate. Modeling thus prevails the field of
science, engineering and business. It is used to assist in the design of equipment, to
predict behavior, to interpret data, to optimize resources and to communicate
information.
1
strategies. Furthermore, to verify the reliability and safety of the process design
tests can be carried out even prior to plant commissioning.
• Plant operators training
Models can be used to train plant personnel to simulate startup and shutdown
procedures, to operate complex processes and to handle emergency situations
and procedures.
• Controller design and tuning
Models help in developing and evaluating better controller structure and
configuration. Dynamic simulation of models is usually employed for testing
and assessing the effectiveness of various controller algorithms. It is worthwhile
to mention that models play a vital part in designing advanced model-based
control algorithms such as model predictive and internal model controller.
Moreover it is a common practice of many control engineers to determine the
optimum values of the controller settings through dynamic simulation .
• Process optimization
It is desirable from economic standpoint to conduct process optimization before
plant operation to determine the optimum values of the process key parameters
or/and operating conditions that maximizes profit and reduces cost. Process
optimization is also performed during process operation to account for
variations in the feed-stock and utilities market and for changing environmental
regulations.
It is worth mentioning that despite all their usefulness, models at their best are no
more than approximation of the real process since they do not necessarily incorporate
all the features of the real system. Therefore modeling can not eliminate completely
the need for some plant tests, especially to validate developed models or when some
poorly known parameters in the process need to be experimentally evaluated.
Models can be classified in a number of ways. But since mathematical models are
developed from applying the fundamental physical and chemical laws on a specific
2
system, we review first the classification of systems since their nature affect the
modeling approach and the resulting model.
1.3 Systems
A system is a whole consisting of elements or subsystems. The system has
boundaries that distinguish it from the surrounding environment (external world) as
shown in Figure 1.1. The system may exchange matter and/or energy with the
surrounding through its boundary. Consequently, the state of a system can be defined
or understood via the interactions of its elements with the external world. A system
may be classified in different ways, some of which are as follows:
Boundary
System
Suroundings
3
1.3.2 Classification based on number of phases
• Homogeneous system
This is a system that involves only one phase such as gas-phase or liquid-phase
chemical reaction processes.
• Heterogeneous system
This is a system that involves more than one phase. This kind of systems exists
in multi-phase reaction processes and in phase-based separation processes.
4
processing systems a number fundamental quantities are used to describe the natural
state of the system. These quantities are the mass, energy and momentum. Most often
these fundamental quantities can not be measured directly thus they are usually
represented by other variables that can be measured directly and conveniently. The
most common variables are density, concentration, temperature, pressure and flow
rate. There are conveniently called 'state variables' since they characterize the state of
the processing system.
In order to describe the behavior of the system with time and position, the state
(dependent) variables should be linked to the independent variables (time, spatial
position) through sets of equations that are derived from writing mass, energy and
momentum balances. The set of equations describing these variables are called 'state
equations.'
7
S
Sin
System Sout
Figure 1.2
8
Rate of Flow of Rate of
Flow of
Generation of moles of (A) Accumulation of (1.3)
moles (A) in + = +
moles of (A) out moles of (A)
The component balance has the unit of moles A/s. It should be noted that unlike the
total mass, the number of moles of species A is not conserved. The species A can be
generated or consumed by chemical reaction.
Since the velocity v is a vector, the momentum, unlike the mass is also a vector. The
momentum balance equation using (Eq 1.1) is:
The momentum balance has the unit of kg.m/s2. The momentum balance equation is
P P
usually written using the Newton's second law. The law states that the time rate of
change of momentum of a system is equal to the sum of all forces F acting on the
system,
d (mv)
= ∑F
(1.6)
dt
9
Rate of Rate of Rate of Rate of ± Amount of
energy + Generation = energy + accumulation energy (1.7)
in of energy out of energy exchanged
with the
surrounding
The energy generated within a system includes the rate of heat and the rate of work.
The rate of heat includes the heat of reaction (if a reaction occurs in the system), and
the heat exchanged with the surroundings. For the rate of work we will distinguish
between the work done against pressure forces (flow work) and the other work such
as the work done against the gravity force, against viscous forces and shaft work.
For a given system the general conservation law (Eq. 1.1) can be carried out either on
microscopic scale or macroscopic scale.
10
z
y
∆z
∆y
∆x
y
r
θ
θ
r z
11
1.10 Macroscopic balance
In some cases the process state variables are uniform over the entire system, that is
each state variable does not depend on the spatial variables, i.e. x,y and z in cartesian
coordinates but only on time t. In this case the balance equation is written over the
whole system using macroscopic modeling. When modeling the process on
microscopic scale the resulting models consists usually of partial differential equation
(PDE) where time and one or more spatial position are the independent variables. At
steady state, the PDE becomes independent of t and the spatial positions are the only
independent variables. On the other hand, when the modeling is based on
macroscopic scale the resulting model consists of sets of ordinary differential
equations (ODE) .
The fundamental balance equations of mass, momentum and energy already
discussed are usually supplemented with a number of equations associated with
transport rates and thermodynamic relationships. In the following we present an
overview of some of these relations.
In many cases the two transport mechanism occurs together. Therefore, the flux due
to the transport of any fundamental quantity is the sum of a flux due to convection
and a flux due to diffusion.
n Au = j Au + ρ A v u
R R R R R R R
(1.8)
12
total flux = diffusive flux + bulk flux (1.9)
The diffusive flux j Au (kg/m2s) for a binary mixture A-B is given by Fick's law:
R R P P
dw A (1.10)
j Au = − ρD AB
du
mixture and D AB (m2/s) is the diffusivity coefficient of A in the mixture. In molar unit
R R P P
dx A (1.11)
J Au = −CD AB
du
mole fraction of A in the mixture. For constant density the flux Eqs. ( 1.10 and Eq.
1.11) become:
dρ A (1.12)
j Au = − DAB
du
dC A (1.13)
J Au = − D AB
du
in the y-direction, consider a fluid flowing between two infinite parallel plates as
13
shown in Figure 1.6. At a certain time the lower plate is moved by applying a
constant force F x while the upper plate is maintained constant. The force F x is called
R R R R
a shear force since it is tangential to the area A y on which it is applied (Fig. 1.6). R R
y
∆y F, force
∆ Vx
is called a stress and denoted τyx (kg.m/s). It is also a shear stress since it is tangential.
R R
plate. Because of molecular transport, the layer above it has a slightly slower velocity
v x (y) and so on as shown in Figure 1.6. Therefore, there is a transport by diffusion of
R R
the x-component of the momentum in the y-direction. The flux of this diffusive
transport is in fact the shear stress τyx . R R
Therefore, the total flux πyx of the x-component in the y-direction is the sum of the
R R
π yx = τ yx + (ρv x )v y
R R R R R R R
(1.16)
momentum flux = diffusive flux + bulk flux (1.17)
For a Newtonian fluid the shear stress τyx is proportional to the velocity gradient: R R
∂v x (1.18)
τ yx = − µ
∂y
e u = q u + (ρC p T)v u
R R R R R R R
(1.19)
energy flux = diffusive flux + bulk flux (1.20)
The heat flux by molecular diffusion, i.e. conduction in the u-direction is given by
Fourier's law:
∂T (1.21)
qu = −k
∂u
The three relations (Eq. 1.10, 1.18, 1.21) show the analogy that exists between mass,
momentum and energy transport. The diffusive flux in each case is given by the
following form:
Flux = − transport property × potential difference (gradient) (1.22)
The flux represents the rate of transfer per area, the potential difference indicates the
driving force and the transport property is the proportionality constant. Table 1.1
summarizes the transport laws for molecular diffusion.
15
When modeling a process on macroscopic level we can also express the flux by a
relation equivalent to (Eq. 1.22). In this case the gradient is the difference between
the bulk properties, i.e. concentration or temperature in two medium in contact, while
the transport property represents an overall transfer coefficient. For example for mass
transfer problems, the molar flux can be expressed as follows:
J A = K × ∆C A (1.23)
where K an overall mass transfer coefficient.
As for the momentum balance, the macroscopic description generally uses the
pressure drop as the gradient while the friction coefficient is used instead of the flux.
The following relation is for instance commonly used to describe the momentum
laminar transport in a pipe.
f =
D
∆P
(1.25)
2v 2 Lρ
f is the Fanning friction factor, ∆P is the pressure drop due to friction, D is the
diameter of the pipe, L the length and v is the velocity of the fluid.
• Enthalpies :
Liquid and vapor enthalpies for pure component can be computed from simple
formulas, based on neglecting the pressure effect as follows:
~
h = C p (T − Tref ) (1.28)
~
H = C p (T − Tref ) + λ (1.29)
~
Where h is the liquid specific enthalpy, H~ is its vapor specific enthalpy, C p
the average liquid heat capacity and λ is the latent heat of vaporization
heat of mixing is negligible, the enthalpy of a mixture can be taken as the sum
of the specific enthalpies of the pure components multiplied by their
corresponding mole fractions Note that the above enthalpy functions are valid
for small temperature variation and/or when the heat capacities of fluids are
weak function of temperature. In general cases the heat capacity C p can be
R R
~
T (1.32)
H= ∫ C p dT + λ
Tref
• Internal energy :
17
The internal energy U is a fundamental quantity that appears in energy balance
equation. For liquids and solids the internal energy can be approximated by
enthalpy. This can be also a good approximation for gases if the pressure
change is small.
y Ai = F(x Ai )
R R R R (1.33)
The equilibrium relations are in general nonlinear. However, quite satisfactory results
can be obtained through the use of simpler relations that are derived form
assumptions of ideal behavior of the two phases:
yAG yAi
xAi
xAL
NA
Interface
18
• For vapor phases at low concentration, Henry's law provides the following
simple equilibrium relation:
p A = Hx A
R R R (1.34)
Where p A (atm) is the partial pressure of species A in the vapor, x A is the mole
R R R R
Dividing by the total Pressure (P) we get another form of Henry's law:
~
yA = H xA
R R R
(1.35)
~
The constant ( H ) depends on temperature and pressure.
ln( PAS ) = A −
B (1.37)
C +T
where A, B and C are characteristic parameters of the fluid.
• Raoult’s law can be modified to account for non-ideal liquid and vapor
behavior using the activity coefficients γ i and φi of component (i) for liquid R R R R
and vapor phase respectively. The following equilibrium relation, also known
as the Gamma/Phi formulation, can be used:
y iφi P = xi γ i Pi S (1.38)
19
The activity coefficients can be determined using correlations found in standard
thermodynamics text books. Equation (1.38) is reduced to Raoult law for ideal
mixture i.e. ( φi = γ i =1).
T.
• Dew point calculations :
For a given molar vapor compositions (y i ) and either T or P, the dew point
R R
or T.
• Flash calculation :
For known mixture compositions (z i ) and known (T) and (P), the flash
R R
R=
1 dni (1.40)
viV dt
20
where
ni
R R the number of moles
νi
R R the stochiometric coefficient of component i
V is the volume due to the chemical reaction.
The rate expression R is generally a complex relation of the concentrations (or partial
pressures) of the reactants and products in addition to pressure and temperature.
The law of mass action stipulates that the reaction rate is a power law function of
temperature and concentration of reactants, i.e.
R = kCRζ1 C Rζ 2 C Rζ r (1.42)
1 2 r
The powers ξ i are determined experimentally and their values are not necessarily
R R
integers. The temperature dependence comes from the reaction rate constant k given
by Arrhenius law
−E (1.43)
k = ko e RT
21
Depending on the value of f three cases can be distinguished:
• f = 0. The system is exactly determined (specified) system. Thus, the set of
balance equation has a finite number of solutions (one solution for linear
systems).
• f < 0. The system is over-determined (over-specified) by f equations. f
equations have to be removed for the system to have a solution.
• f > 0. The system is under-determined (under-specified) by f equations. The set
of equation, hence, has infinite number of solution.
22
In fact the only class of differential equations for which there is a well-developed
framework are linear ODE. However linearizing the original nonlinear model and
solving it is not always recommended (expect for control purposes) since the
behavior of the linearized model matches the original nonlinear model only around
the state chosen for linearization. For these reasons the solution of process models is
usually carried out numerically, most often through a computer programs.
23
Chapter 2: Examples of Mathematical Models for Chemical
Processes
Consider the perfectly mixed storage tank shown in figure 2.1. Liquid stream with
volumetric rate F f (m3/s) and density ρ f flow into the tank. The outlet stream has
R R P P R R
volumetric rate F o and density ρ ο . Our objective is to develop a model for the
R R R R
variations of the tank holdup, i.e. volume of the tank. The system is therefore the
liquid in the tank. We will assume that it is perfectly mixed and that the density of the
effluent is the same as that of tank content. We will also assume that the tank is
24
isothermal, i.e. no variations in the temperature. To model the tank we need only to
write a mass balance equation.
Ff
ρf V
Fo
ρo
Since the system is perfectly mixed, the system properties do not vary with position
inside the tank. The only variations are with time. The mass balance equation can be
written then on the whole system and not only on a differential element of it. This
leads to therefore to a macroscopic model.
We apply the general balance equation (Eq. 1.2), to the total mass m = ρV. This
yields:
Mass flow in:
ρf FfR R R
(2.1)
Mass flow out:
ρo Fo
R R R
(2.2)
Accumulation:
dm d (ρV )
=
dt dt (2.3)
The generation term is zero since the mass is conserved. The balance equation yields:
d (ρV )
ρ f F f = ρo Fo +
dt (2.4)
For consistency we can check that all the terms in the equation have the SI unit of
kg/s. The resulting model (Eq. 2.4) is an ordinary differential equation (ODE) of first
order where time (t) is the only independent variable. This is therefore a lumped
parameter model. To solve it we need one initial condition that gives the value of the
volume at initial time t i , i.e.
R R
25
V(t i ) = V i
R R R (2.5)
Under isothermal conditions we can further assume that the density of the liquid is
constant i.e. ρ f = ρ o =ρ. In this case Eq. 2.4 is reduced to:
R R R R
dV
= F f − Fo
dt (2.6)
The volume V is related to the height of the tank L and to the cross sectional area A
by:
V = AL (2.7)
Since (A) is constant then we obtain the equation in terms of the state variable L:
dL
A = F f − Fo
dt (2.8)
with initial condition:
L(t i ) = L i
R R R (2.9)
For the system to be exactly specified we need therefore one more equations. This
extra relation is obtained from practical engineering considerations. If the system is
operated without control (at open loop) then the outlet flow rate F o is a function of
R R
26
Note that at steady state, the accumulation term is zero (height does not change with
time), i.e., dL/dt = 0. The model of the tank is reduced to the simple algebraic
equation:
F0 = Ff
R R R R (2.11)
We consider the liquid tank of the last example but at non-isothermal conditions.
The liquid enters the tank with a flow rate F f (m3/s), density ρ f (kg/m3) and
R R P P R R P P
assumed constant. The effluent stream is of flow rate F o (m3/s), density ρ o (kg/m3) R R P P R R P P
and temperature T(K) (Fig. 2.2). Our objective is to model both the variation of liquid
level and its temperature. As in the previous example we carry out a macroscopic
model over the whole system. Assuming that the variations of temperature are not as
large as to affect the density then the mass balance of Eq. 2.8 remains valid.
To describe the variations of the temperature we need to write an energy balance
equation. In the following we develop the energy balance for any macroscopic system
(Fig. 2.3) and then we apply it to our example of stirred tank heater.
Consequently, the flow of energy into the system is:
~
ρf Ff h f R R R R
(2.12)
Q
L
Fo , To , ρo
Tst
Heat supply
27
Figure 2.3 General Macroscopic System
Substituting all these terms in the general balance equation (Eq. 1.7) yields:
(
d ρVh
~
) ~ ~
= ρ f F f h f − ρ o Fo ho + Qe + Qr (2.15)
dt
We can check that all terms of this equation have the SI unit of (J/s). We return now
to the liquid stirred tank heater. A simplifying assumption can be introduced, that
there is no reaction involved, i.e. Q r = 0.R R
28
~ ~
h = Cp(T − Tref ) (2.17)
~
Where Cp is the average heat capacity.
Furthermore since the tank is well mixed the effluent temperature T o is equal to R R
ρC p
(
~ d V (T − Tref ) ~ ) ~
= ρF f C p (T f − Tref ) − ρFoC p (T − Tref ) + Qe (2.18)
dt
Taking T ref = 0 for simplicity and since V = AL result in:
R R
~ d (LT ) ~ ~
ρC p A = ρF f C pT f − ρFoC pT + Qe (2.19)
dt
or equivalently:
d (LT ) Q
A = F f T f − FoT + ~e (2.20)
dt ρC p
Since
d (LT ) d (L ) d (T )
A = AT + AL (2.21)
dt dt dt
And using the mass balance (Eq. 2.8) we get:
dT Q
AL + T ( F f − Fo ) = F f T f − FoT + ~e (2.22)
dt ρC p
or equivalently:
dT Q
AL = F f (T f − T ) + ~e (2.23)
dt ρC p
The stirred tank heater is modeled, then by the following coupled ODE's:
A
dL
= F f − Fo
(2.24)
dt
AL
dT Q
= F f (T f − T ) + ~e
(2.25)
dt ρC p
29
Degree of freedoms analysis
For this system we can make the following simple analysis:
• Parameter of constant values: A, ρ and C p R
• Remaining variables: L, F o , T, Q e R R R
The degree of freedom is therefore, 4− 2 = 2. We s till need two relations for our
problem to be exactly specified. Similarly to the previous example, if the system is
operated without control then F o is related to L through (Eq. 2.10). One additional
R R
relation is obtained from the heat transfer relation that specifies the amount of heat
supplied:
Q e = UA H (T st −T )
R R R R R R (2.27)
U and A H are heat transfer coefficient and heat transfer area. The source temperature
R R
We revisit the perfectly mixed tank of the first example but where a liquid phase
chemical reactions taking place:
k
A
→ B (2.28)
The reaction is assumed to be irreversible and of first order. As shown in figure 2.4,
the feed enters the reactor with volumetric rate F f (m3/s), density ρ f (kg/m3) and R R P P R R P P
concentration C Af (mole/m3). The output comes out of the reactor at volumetric rate
R R P P
isothermal conditions.
Our objective is to develop a model for the variation of the volume of the reactor
and the concentration of species A and B. The assumptions of example 2.1.1 still hold
and the total mass balance equation (Eq. 2.6) is therefore unchanged
30
Ff
ρf
CAf V Fo
CBf ρo
CAo
CBo
Figure 2.4 Isothermal CSTR
We could write a similar component balance on species B but it is not needed since
it will not represent an independent equation. In fact, as a general rule, a system of n
species is exactly specified by n independent equations. We can write either the total
mass balance along with (n −1) component balance equations, or we can write n
component balance equations.
31
Using the differential principles, equation (2.32) can be written as follows:
d (VC A )
=V
d (C A )
+ CA
d (V )
= F f C Af − Fo C A − rV
(2.33)
dt dt dt
Substituting Equation (2.6) into (2.33) and with some algebraic manipulations we
obtain:
d (C A )
V + C A ( F f − Fo ) = F f C Af − Fo C A − rV (2.34)
dt
or equivalently:
d (C A )
V = F f ( C Af − C A ) − rV (2.35)
dt
In order to fully define the model, we need to define the reaction rate which is for a
first-order irreversible reaction:
r = k CA R R (2.36)
Equations 2.6 and 2.35 define the dynamic behavior of the reactor. They can be
solved if the system is exactly specified and if the initial conditions are given:
V(t i ) = V i and C A (t i ) = C Ai
R R R R R R R R R (2.37)
The degree of freedom is therefore 3− 2 =1. The extra relation is obtained by the
relation between the effluent flow F o and the level in open loop operation (Eq. 2.10).
R R
The steady state behavior can be simply obtained by setting the accumulation terms
to zero. Equation 2.6 and 2.35 become:
F0 = Ff
R R R (2.38)
F f ( C Af − C A ) = rV (2.39)
32
2.1.4 Isothermal CSTR of Two feed streams
More complex situations can also be modeled in the same fashion. Consider the
catalytic hydrogenation of ethylene:
A+BP (2.40)
Where A represents hydrogen, B represents ethylene and P is the product (ethane).
The reaction takes place in the CSTR shown in figure 2.5. Two streams are feeding
the reactor. One concentrated feed with flow rate F 1 (m3/s) and concentration C B1 R R P P R R
(mole/m3) and another dilute stream with flow rate F 2 (m3/s) and concentration C B2
P P R R P P R R
(mole/m3). The effluent has flow rate F o (m3/s) and concentration C B (mole/m3). The
P P R R P P R R P P
V
Fo, CB
r=
k1CB
( mole / m 3 .s )
(2.41)
(1 + k2CB ) 2
Where k 1 is the reaction rate constant and k 2 is the adsorption equilibrium constant.
R R R R
Assuming the operation to be isothermal and the density is constant, and following
the same procedure of the previous example we get the following model:
Total mass balance:
dL
A = F1 + F2 − Fo (2.42)
dt
Component B balance:
d (C B )
V = F1 ( C B1 − C B ) + F2 ( C B 2 − C B ) − rV (2.43)
dt
33
Degrees of freedom analysis
• Parameter of constant values: A, k 1 and k 2 R R R
We reconsider the previous CSTR example (Sec 2.1.3), but for non-isothermal
conditions. The reaction A B is exothermic and the heat generated in the reactor is
removed via a cooling system as shown in figure 2.6. The effluent temperature is
different from the inlet temperature due to heat generation by the exothermic
reaction.
Ff , CAf , Tf
Qe V Fo, CA, T
Assuming constant density, the macroscopic total mass balance (Eq. 2.6) and mass
component balance (Eq. 2.35) remain the same as before. However, one more ODE
will be produced from the applying the conservation law (equation 2.20) for total
energy balance. The dependence of the rate constant on the temperature:
k = k o e-E/RT R R P (2.44)
The general energy balance (Eq. 2.20) for macroscopic systems applied to the CSTR
yields, assuming constant density and average heat capacity:
34
ρC p
(
~ d V (T − Tref ) ~ ) ~
= ρF f C p (T f − Tref ) − ρFoC p (T − Tref ) + Qr − Qe (2.45)
dt
Where Q r (J/s) is the heat generated by the reaction, and Q e (J/s) the rate of heat
R R R R
removed by the cooling system. Assuming T ref = 0 for simplicity and using the R R
Q r = −(∆H r )Vr
R R R R
(2.48)
Where ∆H r (J/mole) is the heat of reaction (has negative value for exothermic
R R
reaction and positive value for endothermic reaction). The non-isothermal CSTR is
therefore modeled by three ODE's:
dV
= F f − Fo
(2.49)
dt
V
d (C A )
= F f ( C Af − C A ) − rV
(2.50)
dt
~ dT
ρC pV
~
= ρF f C p (T f − T ) + (−∆H r )Vr − Qe
(2.51)
dt
Where the rate (r) is given by:
r = k o e-E/RTC A R R P P R (2.52)
The system can be solved if the system is exactly specified and if the initial
conditions are given:
V(t i ) = V i
R R R R T(t i ) = T i R R R R and C A (t i ) = C Ai
R R R R R (2.53)
35
The degree of freedom is 5−3 = 2. Following the analysis of example 2.1.3, the two
extra relations are between the effluent stream (F o ) and the volume (V) on one hand
R R
and between the rate of heat exchanged (Q e ) and temperature (T) on the other hand,
R R
Consider the shell and tube heat exchanger shown in figure 2.7. Liquid A of
density ρ A is flowing through the inner tube and is being heated from temperature
R R
both liquids varies not only with time but also along the tubes (i.e. axial direction)
and possibly with the radial direction too. Tubular heat exchangers are therefore
typical examples of distributed parameters systems. A rigorous model would require
writing a microscopic balance around a differential element of the system. This
would lead to a set of partial differential equations. However, in many practical
situations we would like to model the tubular heat exchanger using simple ordinary
differential equations. This can be possible if we think about the heat exchanger
within the unit as being an exchanger between two perfect mixed tanks. Each one of
them contains a liquid.
Tw Liquid, B
TB1
Liquid, A
TA1 TA2
Liquid, B
TB2
36
For the time being we neglect the thermal capacity of the metal wall separating the
two liquids. This means that the dynamics of the metal wall are not included in the
model. We will also assume constant densities and constant average heat capacities.
One way to model the heat exchanger is to take as state variable the exit temperatures
T A 2 and T B 2 of each liquid. A better way would be to take as state variable not the
R RR R R RR R
exit temperature but the average temperature between the inlet and outlet:
TA1 + TA2
TA = (2.54)
2
TB1 + TB 2
TB = (2.55)
2
For liquid A, a macroscopic energy balance yields:
dTA
ρ AC p VA = ρ A FAC p A (TA1 − TA2 ) + Q (2.56)
A
dt
where Q (J/s) is the rate of heat gained by liquid A. Similarly for liquid B:
dTB
ρ BC p VB = ρ B FBC p B (TB1 − TB 2 ) − Q (2.57)
B
dt
The amount of heat Q exchanged is:
Q = UA H (T B – T A )
R R R R R R (2.58)
Or using the log mean temperature difference:
Q = UA H ∆T lm R R R
(2.59)
Where
(TA2 − TB1 ) − (TA1 − TB 2 )
∆Tlm =
(T − TB1 )
ln A2 (2.60)
(TA1 − TB 2 )
with U (J/m2s) and A H (m2) being respectively the overall heat transfer coefficient and
P P R R P P
heat transfer area. The heat exchanger is therefore describe by the two simple ODE's
(Eq. 2.56) and (Eq. 2.57) and the algebraic equation (Eq. 2.58).
37
• Remaining variables: T A2 , T B2 , Q R R R R
The degree of freedom is 5− 3 = 2. The two extra relations are obtained by noting
that the flows F A and F B are generally regulated through valves to avoid fluctuations
R R R R
in their values.
So far we have neglected the thermal capacity of the metal wall separating the two
liquids. A more elaborated model would include the energy balance on the metal wall
as well. We assume that the metal wall is of volume V w , density ρ w and constant heat R R R R
capacity Cp w . We also assume that the wall is at constant temperature T w , not a bad
R R R R
assumption if the metal is assumed to have large conductivity and if the metal is not
very thick. The heat transfer depends on the heat transfer coefficient h o,t on the R R
outside and on the heat transfer coefficient h i,t on the inside. Writing the energy R R
ρ BC p VB
dTB
= ρ B FBC p B (TB1 − TB 2 ) − ho , t Ao , t (TB − TW )
(2.61)
B
dt
Where A o,t is the outside heat transfer area. The energy balance for the metal yields:
R R
ρ wC p Vw
dTw
= ho , t Ao , t (TB − Tw ) − hi , t Ai , t (Tw − TA )
(2.62)
w
dt
Where A i,t is the inside heat transfer area. The energy balance for liquid A yields:
R R
ρ AC p VA
dTA
= ρ A FAC p A (TA1 − TA2 ) + hi , t Ai , t (Tw − TA )
(2.63)
A
dt
Note that the introduction of equation (Eq. 2.62) does not change the degree of
freedom of the system.
38
Tw Steam
Ts(t)
Liquid, L
TL1 TL2
condensate, Ts
T s = T s (P)
R R R R (2.67)
Assuming ideal gas law, then the mass flow of steam is:
M s PsVs
ms = (2.68)
RTs
Where M s is the molecular weight and R is the ideal gas constant. The mass balance
R R
Where F c and ρ c are the condensate flow rate and density. The heat losses at the
R R R R
39
• (Forced variable): T L1 R
• Remaining variables: T L2 , F L , T s , F s , P s , Q s , F c
R R R R R R R R R R R R R R
The degrees of freedom is therefore 7 – 5 = 2. The extra relations are given by the
relation between the steam flow rate F s with the pressure P s either in open-loop or
R R R R
temperature and pressure passes through a throttling valve where its pressure is
reduced substantially. As a result, part of the liquid feed vaporizes. The two phases
are assumed to be in phase equilibrium. x i and y i represent the mole fraction of
R R R R
component i in the liquid and vapor phase respectively. The formed vapor is drawn
off the top of the vessel while the liquid comes off the bottom of the tank. Taking the
whole tank as our system of interest, a model of the system would consist in writing
separate balances for vapor and liquid phase. However since the vapor volume is
generally small we could neglect the dynamics of the vapor phase and concentrate
only on the liquid phase.
40
Fv
yi
P, T, Vv
Fo
zi
To
Po VL ρL FL
xi
• Liquid-vapor Equilibrium:
Raoult's law can be assumed for the phase equilibrium
xi Pi s
yi = (i=1,2,….,N c )
(2.74)
R R
P
Together with the consistency relationships:
Nc
∑y
i =1
i =1
(2.75)
Nc
∑x
i =1
i =1
(2.76)
41
• Physical Properties:
The densities and enthalpies are related to the mole fractions, temperature and
pressure through the following relations:
ρL R R = f(x i ,T,P)
R R (2.77)
ρv R R = f(y i ,T,P) ≈ M v aveP/R T
R R R RP P (2.78)
Nc
(2.79)
M v ave =
R RP P
∑y M
i =1
i i
Nc
(2.80)
h = f(x i ,T) ≈
R R
∑ x Cp (T − T
i =1
i i ref )
Nc
(2.81)
H = f(y i ,T) ≈
R R
∑ y Cp (T − T
i =1
i i ref ) + λm
Nc
(2.82)
λm R R = ∑yλ
i =1
i i
• Number of equations: 2N c +3: (Eq. 2.71, 2.72, 2.73, 2.74, 2.75, 2.76) R R
Note that physical properties are not included in the degrees of freedom since they
are specified through given relations. The degrees of freedom is therefore (2N c +5)- R R
(2N c +3)=2. Generally the liquid holdup (V L ) is controlled by the liquid outlet flow
R R R R
rate (F L ) while the pressure is controlled by F V . In this case, the problem becomes
R R R R
42
absorption towers, extraction towers and multi-stage flash evaporator where distillate
water is produced from brine by evaporation.
The same modeling approach used for single stage processes will be used for the
staged processes, where the conservation law will be written for one stage and then
repeated for the next stage and so on. This procedure will result in large number of
state equation depending on the number of stages and number of components.
The separation process generally takes place in plate, packed or spray-type towers.
In tray or spay-type columns the contact and the transfer between phases occur at the
plates. Generally, we can always assume good mixing of phases at the plates, and
therefore macroscopic balances can be carried out to model these type of towers.
Packed towers on the other hand are used for continuous contacting of the two phases
along the packing. The concentrations of the species in the phases vary obviously
along the tower. Packed towers are therefore typical examples of distributed
parameters systems that need to be modeled by microscopic balances.
In the following we present some examples of mass separation units that can be
modeled by simple ODE's, and we start with liquid-liquid extraction process.
Liquid-liquid extraction is used to move a solute from one liquid phase to another.
Consider the single stage countercurrent extractor, shown in Figure 2.10, where it is
desired to separate a solute (A) from a mixture (W) using a solvent (S). The stream
mixture with flow rate W (kg/s) enters the stage containing X Af weight fraction of
R R
solute (A). The solvent with a flow rate (S) (kg/s) enters the stage containing Y AfR R
weight fraction of species (A). As the solvent flows through the stage it retains more
of (A) thus extracting (A) from the stream (W). Our objective is to model the
variations of the concentration of the solute. A number of simplifying assumptions
can be used:
• The solvent is immiscible in the other phase.
• The concentration X A and Y A are so small that they do not affect the mass flow
R R R R
rates. Therefore, we can assume that the flow rates W and S are constant. A total
mass balance is therefore not needed.
43
• An equilibrium relationship exists between the weight fraction Y A of the solute R R
in the solvent (S) and its weight fraction X A in the mixture (W). The relationship R R
dX A
ρ1V1 = WX Af − WX A − N A (2.84)
dt
whereas N A (kg/s) is the flow rate due to transfer flow between the two phases. A
R R
similar component balance on the solvent phase of volume V 2 and density ρ 2 gives: R R R R
dYA
ρ2V2 = SYAf − SYA + N A (2.85)
dt
Since Y A = K X A and K is constant, the last equation is equivalent to:
R R R R
dX A
ρ 2V2 K = SY Af − SKX A + N A
dt (2.86)
Adding Eq. 2.84 and 2.86 yields:
dX A
( ρ1V1 + ρ 2V2 K ) = WX Af + SY Af − (W + KS ) X A
dt (2.87)
The latter is a simple linear ODE with unknown X A . With the volume V 1 , V 2 and flow R R R R R R
rates W, S known the system is exactly specified and it can be solved if the initial
concentration is known:
X A (t i ) = X Ai
R R R R R (2.88)
Note that we did not have to express explicitly the transferred flux N A . R R
S, YA S, YAf
W, XAf W, xA
The same analysis can be extended to the multistage liquid/liquid extraction units
as shown in Figure 2.11. The assumptions of the previous example are kept and we
44
also assume that all the units are identical, i.e. have the same volume. They are also
assumed to operate at the same temperature.
1 2 i N
A component balance in the ith stge (excluding the first and last stage) gives:
P P
ρ1iV1i
dX Ai
= WX Ai −1 − WX Ai − N Ai (i=2…,N-1)
(2.89)
dt
where N Ai is the flow rate due to transfer between the two phases at stage i.
R R
ρ 2iV2i
dY Ai
= SY Ai +1 − SY Ai + N Ai … (i = 2…,N-1)
(2.90)
dt
Writing the equilibrium equation (Eq. 2.83) for each component Y Ai = K X Ai R R R
(ρ1iV1i + ρ2iV2i K )
dX Ai
= WX Ai −1 + SYAi +1 − (W + KS ) X Ai (i=2…,N-1)
(2.91)
dt
Since the volume and densities are equal, i.e.:
V 1i = V 1 and V 2i = V
R R R R R R (2.92)
ρ 1i = ρ 1 and ρ 2i = ρ 2
R R R R R R R
(2.93)
Equation 2.91 is therefore equivalent to:
dX Ai
(ρ1V1 + ρ2V2 K ) = WX Ai −1 + SYAi +1 − (W + KS ) X Ai (i=2…,N-1)
dt (2.94)
The component balance in the first stage is:
dX A1
(ρ1V1 + ρ2V2 K ) = WX Af + SYA1 − (W + KS ) X A1
dt (2.95)
And that for the last stage is:
45
dX AN
(ρ1V1 + ρ2V2 K ) = WX AN −1 + SYAf − (W + KS ) X AN
dt (2.96)
The model is thus formed by a system of linear ODE's (Eq. 2.94, 2.95, 2.96) which
can be integrated if the initial conditions are known:
X A (t i ) = X Ai (i=1,2…,N)
R R R R R R (2.97)
stream flows upward with molar flow rate (G) and feed composition (y f ). We are R R
interested in deriving an unsteady state model for the absorber. A simple vapor-liquid
equilibrium relation of the form of:
yi = a xi + b
R R R R (2.98)
Can be used for each stage i (i=1,2,…,N).
Assumptions:
• Isothermal Operation
• Negligible vapor holdup
• Constant liquid holdup in each stage
• Perfect mixing in each stage
According to the second and third assumptions, the molar rates can be considered
constants, i.e. not changing from one stage to another, thus, total mass balance need
46
not be written. The last assumption allows us writing a macroscopic balance on each
stage as follows:
Component balance on stage i:
dxi
H = G ( yi −1 − yi ) + L( xi +1 − xi ) (i=2…,N-1) (2.99)
dt
where H is the liquid holdup, i.e., the mass of liquid in each stage. The last equation
is repeated for each stage with the following exceptions for the last and the first
stages:
L, xf G, yN
stage N
xN yN-1
xi+1 yi
stage i
xi yi-1
x3 y2
stage 2
x2 y1
stage 1
L, x1 G, yf
48
Cw
D
xd
F
z
steam
B
xb
Since the vapor-phase has negligible holdups, then conservation laws will only be
written for the liquid phase as follows:
Energy balance:
d (M f hf ) (2.111)
= V f −1H f −1 − (V f H f + (1 − q) Fh f ) + L f +1h f +1 − ( L f h f + qFh f )
dt
Energy balance:
d ( M 1h1 )
= VB H B − V1H1 + L2 h2 − L1h1 (2.114)
dt
51
Liquid holdup: M i = f (L i ) R R R R
Notation:
Li, Vi
R R R R Liquid and vapor molar rates
Hi, hi R R R R Vapor and liquid specific enthalpies
xi, yi
R R R R Liquid and vapor molar fractions
Mi R R Liquid holdup
Q Liquid fraction of the feed
Z Molar fractions of the feed
F Feed molar rate
Mi R R n
MB, MD R R R R 2
Li R R n
B,R,D 3
x i,j
R R n(nc − 1)
x B,j ,x D,j
R R R 2(nc − 1)
y i,j
R R n(nc − 1)
y B,j
R R nc − 1
hi R R n
hB, hDR R R R 2
Hi R R n
HB R R 1
Vi R R n
VB R R 1
Ti R R n
52
TD, TB R R R R 2
Total 11+6n+2n(nc−1)+3(nc−1)
Equations:
Total Mass n+2
Energy n+2
Component (n + 2)(nc − 1)
Equilibrium n(nc − 1)
Liquid holdup n
Enthalpies 2n+2
Vapor rate n
hB = h1 R R R 1
yB = xB
R R R (nc − 1)
Total 7+6n+2n(nc-1)+3(nc-1)
Constants: P, F, Z
To well define the model for solution we include four relations imported from
inclusion of four feedback control loops as follows:
• Use B, and D to control the liquid level in the condenser drum and in the re-
boiler.
• Use V B and R to control the end compositions i.e., x B , x D
R R R R R
53
R, xd Vn, yn
Vn, yn
stage n
(a)
Qc (b)
R, xd D, xd
Ln, xn Vn-1, yn-1
stage i stage f
(c) (d)
stage 1
(f)
B, xB
(e)
L1, x1 V B , yB
L1, x1
Section 3
Section 2
L2 Figure (2.15) Reboiler of batch distillation column
V1
Reboiler M1
54
Total mass balance.
dM B
= L1 − VB (2.118)
dt
Component balance
d ( M B ⋅ x B ,i )
= L1 x1,i − VB y B ,i (2.119)
dt
Energy balance
d ( M B hB )
= L1h1 − VB H B + Qr (2.120)
dt
Where Q r is heat supplied by reboiler
R R
55
Figure (2.16) continuous packed reactive distillation column.
56
Lm+1 Vm
Lm Vm-1
Consider a fluid flowing inside a pipe of constant cross sectional area (A) as shown
in Figure 2.18. We would like to develop a mathematical model for the change in the
fluid mass inside the pipe. Let v be the velocity of the fluid. Clearly the velocity
changes with time (t), along the pipe length (z) and also with the radial direction (r).
In order to simplify the problem, we assume that there are no changes in the radial
direction. We also assume isothermal conditions, so only the mass balance is needed.
Since the velocity changes with both time and space, the mass balance is to be carried
57
out on microscopic scale. We consider therefore a shell element of width ∆z and
constant cross section area (A) as shown in Fig. 2.18.
ρ(t,z)
∆z
vo v(t,z)
We can check for consistency that the units in each term are in (kg). Dividing Eq.
2.127 by ∆t ∆z and rearranging yields:
(ρA) − (ρA) (ρvA) − (ρvA) (2.128)
t + ∆t t
= z z + ∆z
∆t ∆z
58
∂ρ ∂ ( ρv ) (2.131)
+ =0
∂t ∂z
The equation (2.131) is a partial differential equation (PDE) that defines the variation
of ρ and v with the two independent variables t and z. This equation is known as the
one-dimensional continuity equation. For incompressible fluids for which the density
is constant, the last equation can also be written as:
∂v (2.132)
=0
∂z
This indicates that the velocity is independent of axial direction for one dimensional
incompressible flow.
We reconsider the flow inside the pipe of the previous example. Our objective is to
find the velocity profile in the pipe at steady state. For this purpose a momentum
balance is needed. To simplify the problem we also assume that the fluid is
incompressible. We will carry out a microscopic momentum balance on a shell with
radius r, thickness ∆r and length ∆z as shown in Fig 2.19.
r
∆r
R
r
∆r z
∆z
P|z P|z+∆z
Momentum out:
59
(τrz 2πr∆z)| r+∆r
R R R
(2.134)
As for the momentum generation we have mentioned earlier in section 1.8.3 that the
generation term corresponds to the sum of forces acting on the volume which in this
example are the pressure forces, i.e.
(PA)| z – (PA)| z+∆z = P(2πr∆r)| z − P(2πr∆r)| z+∆z
R R R R R R R
(2.135)
There is no accumulation term since the system is assumed at steady state.
Substituting this term in the balance equation (Eq. 1.6) and rearranging yields,
rτrz |r + ∆r −rτrz |r r ( P |z − P |z + ∆z ) (2.136)
=
∆r ∆z
We can check for consistency that all the terms in this equation have the SI unit of
(N/m2). Taking the limit of (Eq. 2.136) as ∆z and ∆r go to zero yields:
P P
d (rτrz ) dP (2.137)
= −r
dr dz
Here we will make the assumption that the flow is fully developed, i.e. it is not
influenced by the entrance effects. In this case the term dP/dz is constant and we
have:
dP P2 − P1 ∆P (2.138)
= =
dz L L
where L is the length of the tube. Note that equation (2.138) is a function of the shear
stress τrz , but shear stress is a function of velocity. We make here the assumption that
R R
the fluid is Newtonian, that is the shear stress is proportional to the velocity gradient:
τ rz = − µ
dv z (2.139)
dr
Substituting this relation in Eq. 2.137 yields:
d rdv z ∆P (2.140)
µ ( )=r
dr dr L
or by expanding the derivative:
d 2 v z 1 dv z ∆P (2.141)
µ( 2
+ )=
dr r dr L
The system is described by the second order ODE (Eq. 2.141). This ODE can be
integrated with the following conditions:
• The velocity is zero at the wall of the tube
60
vz = 0
R R at r = R (2.142)
• Due to symmetry, the velocity profile reaches a maximum at the center of the
tube:
dvz
=0 at r = 0 (2.143)
dr
Note that the one-dimensional distributed parameter system has been reduced to a
lumped parameter system at steady state.
accumulation term since the system is assumed at steady state. The mass balance
equation is therefore,
(SN A )| z − (SN A )| z+∆z − (S∆z)kC A =0
R R R R R R R R R R
(2.147)
61
Porous
catalyst
particle
Exterior
surface
∆z
z=0 z=L
Figure 2.20 diffusion with chemical reaction inside a slab catalyst
slab. The second condition implies that the concentration is finite at the center of the
slab.
62
2.2.4 Temperature profile in a heated cylindrical Rod
fluid of temperature T m while the surface area of the rod is exposed to ambient
R R
describes the variation of the rod temperature with the position. The metal has high
thermal conductivity that makes the heat transfer by conduction significant. In
addition, the rod diameter is assumed to be large enough such that thermal
distribution in radial direction is not to be neglected. The system is depicted by figure
2.21. For modeling we take an annular ring of width ∆z and radius ∆r as shown in
the figure. The following transport equation can be written:
R
∆r
r
∆r
∆z
63
q r+∆r (2π (r+∆r)∆z)∆t
R R
(2.157)
Heat accumulation:
~ ~
ρ(2π r ∆r ∆z)( h t+∆t − h t ) R R R R
(2.158)
~
Where h is the specific enthalpy. Summing the above equation according to the
conservation law and dividing by (2π ∆r ∆z ∆t), considering constant density, gives:
~ ~
ht + ∆t − ht q − qz + ∆z rqr − rqr + ∆r (2.159)
ρr =r z +
∆t ∆z ∆r
64
Consequently, the above energy balance equation (Eq. 2.165) is reduced to the
following ODE
d 2T (2.166)
0 = kz − U ( 2πRL)(Ta − T )
dz 2
v(t,z)
CAo CA
z z+∆z z=L
ρ(t,z), CA(t,z)
In the following we derive the microscopic component balance for species (A) around
differential slice of width ∆z and constant cross-section area (S).
65
(C A S ∆z) | t+∆t − (C A S ∆z) | t
R R R R R R R
(2.169)
Generation due to reaction inside the shell:
− r(S∆z∆t) (2.170)
Where r = k C A is the rate of reaction.
R R
Substituting all the terms in the mass balance equation (Eq. 1.3) and dividing by ∆t
and ∆z gives:
(C A S ) |t + ∆t −(C A S ) |t (vC A S + N A S ) |z −(vC A S + N A S ) |z + ∆z (2.171)
= − kC A S
∆t ∆z
Taking the limit of ∆t 0 and ∆z 0 and omitting S from both sides give the
following PDE:
∂C A ∂vC A ∂N A (2.172)
=− − − kC A
∂t ∂z ∂z
N A = − DAB
dC A (2.173)
dz
Where D AB is the binary diffusion coefficient. Equation 2.172 can be then written as
R R
follows:
∂C A ∂ ( vC A ) ∂ 2C A (2.174)
=− + DAb − kC A
∂t ∂z ∂z 2
Expanding the derivatives, the last equation can be reduced to:
∂C A ∂C ∂v ∂ 2C A (2.175)
= −v A − C A + DAb − kC A
∂t ∂z ∂z ∂z 2
This equation can be further simplified by using the mass balance equation for
incompressible fluids (Eq. 2.132). We get then:
∂C A ∂C ∂ 2C A (2.176)
= −v A + DAb − kC A
∂t ∂z ∂z 2
The equation is a PDE for which the state variable (C A ) depends on both t and z.R R
The PDE is reduced at steady state to the following second order ODE,
dC A d 2C A (2.177)
0 = −v + DAb − kC A
dz dz 2
The ODE can be solved with the following boundary conditions (BC):
66
BC1: at z = 0 C A (0) = C A0
R R R (2.178)
BC2: at z = L dC A ( z )
=0
(2.179)
dz
The first condition gives the concentration at the entrance of the reactor while the
second condition indicates that there is no flux at the exit length of the reactor.
To T
CAo v(t,z) v(t,z)
CA
Assumptions:
• Kinetic and potential energies are neglected.
• No Shaft work.
• Internal energy is approximated by enthalpy.
• Energy flow will be due to bulk flow (convection) and conduction.
~
(q z A + v Aρ h )∆t| z
R R R R
(2.180)
Energy flow out of the shell:
~
(q z A + v Aρ h )∆t| z+∆z
R R R R
(2.181)
Accumulation of energy:
~ ~
(ρA h ∆z)| t+∆t − (ρA h ∆z)| t R R R R
(2.182)
Heat generation by reaction:
(−∆H r )kC A A ∆z ∆t R R R R
(2.183)
Heat transfer to the wall:
h t (πD∆z)(T − T w )∆t
R R R R
(2.184)
Where h t is film heat transfer coefficient.
R R
Substituting these equations in the conservation law (equation 1.7) and dividing by
Α∆t ∆z give:
~ ~ ~ ~
( ρh ) |t + ∆t −( ρh ) |t ( ρvh ) | z −( ρvh ) | z + ∆z q z | z −q z | z + ∆z πD
= + − ∆H r kC A − ht ( )(T − Tw ) (2.185)
∆t ∆z ∆z A
by:
~
h = C p(T − Tref ) (2.188)
Since the fluid is incompressible it satisfies the equation of continuity (Eq. 2.132).
Substituting these expressions in Eq. 2.186 and expanding gives:
∂T ∂T ∂ 2T πD
ρC p = − ρC pv + kt 2 − ∆H r ko e − E / RT C A − ht ( )(T − Tw ) (2.189)
∂t ∂z ∂z A
68
At steady state this PDE becomes the following ODE,
dT d 2T πD
0 = − ρC pv + kt 2 − ∆H r ko e − E / RT C A − ht ( )(T − Tw ) (2.190)
dz dz A
Similarly to Eq. 2.177 we could impose the following boundary conditions:
B.C1: at z = 0 T(z) = T oR (2.191)
B.C2: at z = L dT ( z )
=0
(2.192)
dz
The first condition gives the temperature at the entrance of the reactor and the second
condition indicates that there is no flux at the exit length of the reactor.
69
Chapter 3: Equations of Change
∆y
∆x
(ρvx)x+∆x
(ρvx)x
∆z
z (ρvy)y
y
(ρvz)z
Mass in:
The mass entering in the x-direction at the cross sectional area (∆y∆z) is
(ρv x )| x ∆y∆z∆t
R R R R (3.1)
The mass entering in the y-direction at the cross sectional area (∆x∆z) is
(ρv y )| y ∆x∆z∆t R R R R (3.2)
The mass entering in the z-direction at the cross sectional area (∆x∆y) is
(ρv z )| z ∆x ∆y ∆t
R R R R
(3.3)
Mass out:
The mass exiting in the x-direction is:
(ρv x )| x+∆x ∆y∆z∆t
R R R R
(3.4)
The mass exiting in the y-direction is:
(ρv y )| y+∆y ∆x∆z∆t
R R R R
(3.5)
The mass exiting in the z-direction is:
(ρv z )| z+∆z ∆x∆y ∆t
R R R R
(3.6)
Rate of accumulation:
The rate of accumulation of mass in the elementary volume is:
(ρ)| t+∆t ∆x ∆y ∆z - (ρ)| t ∆x ∆y ∆z
R R R R
(3.7)
Since there is no generation of mass, applying the general balance equation Eq. 1.2
and rearranging gives:
(ρ| t+∆t − ρ| t ) ∆x ∆y ∆z = (ρv x | x − ρv x | x+∆x )∆y∆z∆t + (ρv y | y
R R R R R R R R R R R R R R R R
(3.8)
− ρv y | y+∆y )∆x∆z∆t + (ρv z | z − ρv z | z+∆z ) ∆x ∆y ∆t
R R R R R R R R R R R R
By taking the limits as ∆y,∆x,∆,z and ∆t goes to zero, we obtain the following
equation of change:
∂ρ ∂ρvx ∂ρv y ∂ρvz
=− − − (3.10)
∂t ∂x ∂y ∂z
Expanding the partial derivative of each term yields after some rearrangement:
∂ρ ∂ρ ∂ρ ∂ρ ∂v ∂v ∂v
+ vx + vy + vz = −ρ( x + y + z ) (3.11)
∂t ∂x ∂y ∂z ∂x ∂y ∂z
This is the general form of the mass balance in cartesian coordinates. The equation is
also known as the continuity equation. If the fluid is incompressible then the density
is assumed constant, both in time and position. That means the partial derivatives of ρ
are all zero. The total continuity equation (Eq. 3.11) is equivalent to:
∂vx ∂v y ∂vz
0 = −ρ( + + ) (3.12)
∂x ∂y ∂z
or simply:
∂vx ∂v y ∂vz
0= + + (3.13)
∂x ∂y ∂z
and ρ (kg/m3s) is the density of the mixture. Our objective is to establish the
P P
∆y
nAx|x+∆x
nAx|x
∆z
y
∆x
nAy|y nAz|z+∆z
x
Mass of A in:
The mass of species A entering the x-direction at the cross sectional (∆y∆z) is:
(n Ax )| x ∆y∆z∆t
R R R R
(3.14)
where n Ax kg/m2 is the flux transferred in the x-direction
R R P P
Similarly the mass of A entering the y and z direction are respectively:
(n Ay )| y ∆x∆z∆t
R R R R
(3.15)
(n Az )| z ∆x∆y∆t
R R R R
(3.16)
Mass of A out:
The mass of species A exiting the x, y and z direction are respectively
(n Ax )| x+∆x ∆y∆z∆t
R R R R
(3.17)
(n Ay )| y+∆y ∆x∆z∆t
R R R R
(3.18)
(n Az )| z+∆z ∆x∆y∆t
R R R R
(3.19)
The rate of accumulation is:
ρ A | t+∆t ∆x ∆y ∆z − ρ A | t ∆x ∆y ∆z
R R R R R R R R
(3.20)
(3.22)
n Ay | y )∆x∆z∆t + (n Az | z+∆z − n Az | z )∆x∆y∆t +r A ∆x ∆y ∆z∆t
R R R R R R R R R R R R R R
Dividing each term by ∆x∆y∆z∆t and letting each of these terms goes to zero yields:
∂ρ A ∂n Ax ∂n Ay ∂n Az
+ + + = rA (3.23)
∂t ∂t ∂t ∂t
We know from Section 1.11.1, that the flux n A is the sum of a term due to convection R R
n A = ρA v + j A
R R R R R (3.24)
Substituting the different flux in Eq. 3.23 gives:
∂ρ A ∂ ( ρ A v x ) ∂ ( ρ A v y ) ∂ ( ρ A v z ) ∂j Ax ∂j Ay ∂j Az
+ + + + + + = rA (3.25)
∂t ∂x ∂y ∂z ∂x ∂y ∂z
For a binary mixture (A,B), Fick’s law gives the flux in the u-direction as :
∂wA
j Au = −ρDAB (3.26)
∂u
where w A = ρ A /ρ. Expanding Eq. 3.25 and substituting for the fluxes yield:
R R R R
∂ρ A ∂v ∂v y ∂v z ∂ρ A ∂ρ ∂ρ
+ ρ A x + + + v x + v y A + v z A
∂t ∂x ∂y ∂z ∂x ∂y ∂z
(3.27)
∂ ∂ρD AB w A ∂ ∂ρD AB w A ∂ ∂ρD AB w A
− ( )+ ( )+ ( ) = rA
∂x ∂x ∂y ∂y ∂z ∂z
This is the general component balance or equation of continuity for species A. This
equation can be further reduced according to the nature of properties of the fluid
involved. If the binary mixture is a dilute liquid and can be considered
incompressible, then density ρ and diffusivity D AB are constant. Substituting the
R R
This equation can also be written in molar units by dividing it by the molecular
weight M A to yield:
R R
∂C A ∂C A ∂C A ∂C A ∂ 2C A ∂ 2C A ∂ 2C A
+ v x + vy + vz − D AB + + = RA
∂
t ∂x ∂y ∂z ∂x 2 ∂ 2
∂ 2 (3.29)
y
z
reaction
accumulation Convection Diffusion
−σxx |x+∆x
σxx |x
−σzx |z+∆z
σyx |y
x
z
Since, unlike the mass or the energy, the momentum is a vector that has three
components, we will present the derivation of the equation for the conservation of the
x-component of the momentum. The balance equations for the y-component and the
z-component are obtained in a similar way. To establish the momentum balance for
its x-component we need to consider its transfer in the x-direction, y-direction, and z-
direction.
Momentum in:
The x-component of momentum entering the boundary at x-direction, by
convection is:
(ρv x v x )| x ∆y∆z∆t
R R R R R R
(3.30)
The x-component of momentum entering the boundary at y-direction, by
convection is:
(ρv y v x )| y ∆x∆z∆t
R R R R R R
(3.31)
and it enters the z-direction by convection with a momentum:
(ρv z v x )| z ∆x∆y∆t
R R R R R R
(3.32)
The x-component of momentum entering the boundary at x-direction, by molecular
diffusion is:
(τxx )| x ∆y∆z∆t
R R R R
(3.33)
The x-component of momentum entering the boundary at y-direction, by molecular
diffusion is:
(τyx )| y ∆x∆z∆t R R R R
(3.34)
and it enters the z-direction by molecular diffusion with a momentum:
(τzx )| z ∆x∆y∆t R R R R
(3.35)
Momentum out:
The rate of momentum leaving the boundary at x+∆x, by convection is:
(ρv x v x )| x+∆x ∆y∆z∆t R R R R R R
(3.36)
and at boundary y+∆y,:
(ρv y v x )| y+∆y ∆x∆z∆t
R R R R R R
(3.37)
and at boundary z+∆z:
(ρv z v x )| z+∆z ∆x∆y∆t R R R R R R
(3.38)
Using the equation of continuity (Eq. 3.10) for incompressible fluid, Equation (3.46)
is reduced to:
∂v x ∂v ∂v ∂v ∂τ ∂τ ∂τ ∂P
ρ + v x x + v y x + v z x = −( xx + yx + zx ) − + ρg x (3.47)
∂t ∂x ∂y ∂z ∂x ∂y ∂z ∂x
∂v z ∂v ∂v ∂v ∂ 2v ∂ 2v ∂ 2 v ∂P
ρ + ρ v x z + v y z + v z z = µ 2z + 2z + 2z − + ρg z
∂
t ∂x ∂y ∂z ∂x ∂y ∂z ∂
z (3.51)
accumulation
generation
transport by bulk flow transport by viscous forces
∆y
∆x
qx |x+∆x
qx |x
∆z
qy |y+∆y
qz |z
The rate of generation is Φ H where Φ H includes all the sources of heat generation, i.e.
R R R R
reaction, pressure forces, gravity forces, fluid friction, etc. Substituting all these terms
in the general energy equation (Eq. 1.7) and dividing the equation by the term
∆x∆y∆z∆t and letting each of these terms approach zero yield:
∂ ( ρCpT ) ∂ ( ρCpTv x ) ∂ ( ρCpTv y ) ∂ ( ρCpTvz ) ∂qx ∂q y ∂qz
+ + + + + + = ΦH (3.60)
∂t ∂x ∂y ∂z ∂x ∂y ∂z
Using the equation of continuity (Eq. 3.10) for incompressible fluids the equation is
reduced to:
∂T ∂T ∂T ∂T ∂q x ∂q y ∂q z
ρCp + vx + vy + vz + + + = ΦH (3.62)
∂t ∂x ∂y ∂z ∂x ∂y ∂z
The energy balance includes as before a transient term, a convection term, a diffusion
term, and generation term. For solids, the density is constant and with no velocity, i.e.
v = 0, the equation is reduced to:
∂T ∂ 2T ∂ 2T ∂ 2T
ρCp = k 2 + 2 + 2 + Φ
∂ ∂ ∂y ∂z generation
H
t x (3.65)
accumulation
Transport by thermal diffusion
Introduction to Numerical Analysis
Numerical analysis is similar in that problems solved, but the only procedures that
are used are arithmetic: add, subtract, multiply, divide and compare.
• As you will learn enough about many numerical methods, you will be able to
write programs to implement them.
• Programs can be written in any computer language. In this course all programs
will be written in Matlab environment.
• Actually, writing programs is not always necessary. Numerical analysis is so
important that extensive commercial software packages are available.
1) Model Error: due to the mismatch between the physical situation and the
mathematical model.
5) Truncation Error: the notion of truncation error usually refers to errors introduced
when a more complicated mathematical expression is “replaced” with a more
elementary formula. This formula itself may only be approximated to the true values,
thus would not produce exact answers.
The truncation error would be the unused terms of the Taylor series, which then are
x4 x5 14 15
Et = + + = + + ≅ 0.0516152
4! 5! 4! 5!
Check a few Taylor series approximations of the number ex, for x = 1, n = 2, 3 and 4.
Given that e1 = 2.718281.
Example:
• Absolute error = | true value – approximate value |, which is usually used when the
magnitude of the true value is small.
While
true value − approximate value
Percent relative error, ε t = × 100%
true value
Example 1.2:
Solve the system of linear equations by Gaussion- Elimination method
x1 + x2 + x3 = 3
2 x1 − x2 − 2 x3 = 6
4 x + 2 x + 3x =
1 2 3 7
Solution:
Step 1.
Augmented matrix is
1 1 1 3 R2 = r2 − 2r1
R3 = r3 − 4r1
2 − 1 − 2 6
4 2 3 7
1 1 1 3
R2 = −r2
0 − 3 − 4 0
r3
0 0 5 − 15 R3 =
5
1 1 1 3
0 3 4 0
0 0 1 − 3
Equivalent system of equations form is:
Example 1.3:
For the below figure calculate the values of the unknown flow rates F 1 , F 2 and F 3 by
using Gaussion- Elimination method
. F1=? F2=?
99% Benzene 5% Benzene
1% Toluene 92% Toluene
3 % Xylene
Tower 1
Tower 2
F=1000 kg/hr
40% Benzene
40% Toluene
20% Xylene
F3=?
10% Toluene
90% Xylene
Example 1.4:
Solve the system of linear equations by Gauss-Jorden elimination method
x 1 + x 2 + 2x 3 = 8
- x 1 - 2x 2 + 3x 3 = 1
3x 1 -7x 2 + 4x 3 = 10
1 1 2 8
0 − 1
5 9 R 2 =-r 2
0 − 10 − 2 - 14 R 3 =r 3 -10r 2
1 1 2 8
0 1 − 5
- 9 R 3 =-r 3 /52
0 0 − 52 - 104
1 1 2 8 R 1 =r 1 -2r 3
0 1 − 5 − 9 R 2 =r 2 +5r 3
0 0 1 2
1 1 0 4
0 1 0 1 R 1 =r 1 -r 2
0 0 1 2
1 0 0 3
0 1 0 1
0 0 1 2
Equivalent system of equations form is:
x1 = 3
x2 = 1
x3 = 2
is the solution of the system.
Example 1.5:
Total and component material balance on a system of distillation columns gives the
flowing equations:-
F1 + F2 + F 3 + F 4 = 1690
0.4F 1 + 0.15F 2 + 0.25F 3 + 0.2F 4 = 412.5
0.25F 1 + 0.8F 2 + 0.3F 3 + 0.45F 4 = 701
0.08F 1 + 0.05F 2 + 0.45F 3 + 0.3F 4 = 487.3
Use Gauss - Jorden method to compute the four un-known's in above equations:-
Example 1.6:
Use the Jacobi iteration method to obtain the solution of the following equations:
6x 1 -2 x 2 + x 3 = 11
x 1 +2x 2 -5x 3 = -1
-2x 1 +7 x 2 +2x 3 = 5
Solution
Step 1: Re-write the equations such that each equation has the unknown with largest
coefficient on the left hand side:
6x 1 = 11+2 x 2 -x 3
7x 2 = 5+2x 1 -2x 3
5x 3 =1+x 1 +2x 2
2 x2 − x3 + 11
x1 =
6
x=3
2 1
20
( 25 − 2x11 + 3x12 =) 1.1515
These and further iterates are listed in the table below:
i x1i x2i x3i
0 0 0 0
1 0.85 –0.90 1.25
2 1.02 –0.965 1.1515
3 1.0134 –0.9954 1.0032
4 1.0009 –1.0018 0.9993
5 1.0000 –1.0002 0.9996
6 1.0000 –1.0000 1.0000
The values in 5th and 6th iterations being practically the same, we can stop. Hence the
solutions are:
x 1 = 1, x 2 = –1 and x 3 = 1
Example 1.8:
Use the Gauss-Seidel method to obtain the solution of the following equations:
6x 1 -2 x 2 + x 3 = 11 (1)
x 1 +2 x 2 -5x 3 = -1 (2)
-2x 1 +7 x 2 +2x 3 = 5 (3)
Solution
Step 1: Re-write the equations such that each equation has the unknown with largest
`coefficient on the left hand side:
2 x − x + 11
x1 = 2 3 from eq. (1)
6
2 x − 2 x3 + 5
x2 = 1 from eq. (3)
7
x + 2 x2 + 1
x3 = 1 from eq. (2)
5
Step 2: Assume the initial guesses x20 = x30 = 0 , then calculate x11 :
2( x20 ) − ( x30 ) + 11 2(0) − (0) + 11
x11 = = =1.833
6 6
Use the updated value x11 = 1.833 and x30 = 0 to calculate x12
2( x11 ) − 2( x30 ) + 5 2(1.833) − 2(0) + 5
x12 = = =1.238
7 7
Similarly, use x11 = 1.833 and x12 = 1.238 to calculate x31
( x11 ) + 2( x12 ) + 1 (1.833) + 2(1.238) + 1
x31 = = =1.062
5 5
Example 1.9:
For the below figure calculate the values of the unknown flow rates F 1 , F 2 and F 3 by
using Gauss-Seidel Method
. F1=? F2=?
99% Benzene 5% Benzene
1% Toluene 92% Toluene
3 % Xylene
Tower 1
Tower 2
F=1000 kg/hr
40% Benzene
40% Toluene
20% Xylene
F3=?
10% Toluene
90% Xylene
Component material balance gives these three equations of three variables
0.99 F1 + 0.05 F2 + 0 F3 = 400
0.01F1 + 0.92 F2 + 0.1F3 = 400
0 F1 + 0.03F2 + 0.9 F3 = 200
A Matlab program for solving the above equations using Gauss-Seidel method is
listed in Table 1.1
Table (1.1) Matlab code and results for solution example (1.9)
F1=333.33; F2=333.33; F3=333.33
for i=1:4
F1=(400-0.05*F2)/0.99;
Matlab F2=(400-0.01*F1-0.1*F3)/0.92;
Code F3=(200-0.03*F2)/0.9;
disp([ i, F1, F2, F3])
end
1.0000 387.2056 394.3423 209.0775
2.0000 384.1241 407.8815 208.6262
Results 3.0000 383.4403 407.9380 208.6243
4.0000 383.4375 407.9383 208.6243
To determine the variables contained in the column vector 'x', complete the
following steps.
(a) Create the coefficient matrix 'A'. Remember to include zeroes where an equation
does not contain a variable.
(b) Create the right-hand-side column vector 'b' containing the constant terms from
the equation. This must be a column vector, not a row.
(c) Calculate the values in the 'x' vector by left dividing 'b' by 'A', by typing x = A\b.
Note: this is different from x = b/A.
Example 1.10
Xylene, styrene, toluene and benzene are to be separated with the array of distillation
columns that is shown below. Write a program to calculate the amount of the streams
D, B, D1, B1, D2 and B2 also to calculate the composition of streams D and B.
Note: Solve the system of equations by using the matrix inverse method.
Solution
By making material balances on individual components on the overall
Example 1.11
Balance the following chemical equation:
x 1 P 2 I 4 + x 2 P 4 + x 3 H2 O → x 4 PH 4 I + x 5 H 3 PO 4
R R R R R R R R R R R R R R R R R R R R R R R
USolution:
P balance: 2x 1 + 4x 2 =x 4 + x 5 R R R R R R R R
I balance: 4x 1 =x 4 + x 5 R R R R R R
O balance: x 3 =4x 5 R R R R
Re-write these as homogeneous equations, each having zero on its right hand
side:
Table (1.3) Matlab code and results for solution example (1.11)
A = [2 4 0 -1 -1
4 0 0 -1 0
0 0 2 -4 -3
Matlab
0 0 1 0 -4
Code
1 0 0 0 0];
B= [0;0;0;0;1];
X = A\B
X=
1.0000
Results 1.3000
12.8000
4.0000
3.2000
This does not yield integral coefficients, but multiplying by 10 will do the trick:
The balanced equation will be:
10 P 2 I 4 + 13 P 4 + 128 H 2 O → 40 PH4 I + 32 H 3 PO 4
Example 1:12
Steady state mass balances on a flash tank.
Consider an isothermal flash tank:
Vi(y)
Fi(Z)
Isothermal
flash tank Li(x)
This unit takes a pressurized liquid, three-component feed stream and exposes it to
a low-pressure vessel maintained under isothermal conditions. The net result is that
Solution:
Then you have six unknowns, the compositions of the liquid stream and the
composition of the vapor stream and you have eight available equations, which are.
A mole balance: Lx A +Vy A =Fz A
B mole balance: Lx B +VyB =Fz B (not used dependent)
C mole balance: Lx C +VyC =Fz C (not used dependent)
Liquid mole fraction constraint x A +x B +x C =1
Vapor mole fraction constraint y A +yB +y C =1
A equilibrium constraint x A PAVap -y A P=0
B equilibrium constraint x B PBVap -y B P=0
C equilibrium constraint x C PCVap -y C P=0
R R
1 L 0 0 V 0 0
2 1 1 1 0 0 0
3 0 0 0 1 1 1
4 PAVap 0 0 P 0 0
5 0 PBVap 0 0 -P 0
6 0 0 PCVap 0 0 -P
2 1
3 1
4 0
5 0
6 0
A Matlab program for solving the above equations using Gaussian-Elimination
method is listed in Table 1.4
Table (1.4) Matlab code and results for solution example (1.12)
F = 100; V = 44.738; L = F - V; zA = 0.4; zB = 0.3; zC = 0.3; PvapA = 0.6;
PvapB = 1.0;PvapC = 2.0;P = 1.01325;
A = [L, 0,0,V,0,0;1,1,1,0,0,0;0,0,0,1,1,1;PvapA,0,0,-P,0,0;0,PvapB, 0,0,-P,0;
Matlab 0,0,PvapC,0,0,-P]
Code b =[F*zA; 1; 1; 0; 0; 0]
x = A\b;
xA = x(1),xB = x(2),xC = x(3),yA = x(4),yB = x(5),yC = x(6)
xA =
0.4893
xB =
0.3018
xC =
0.2090
Results yA =
0.2897
yB =
0.2978
yC =
0.4125
Example 1.13
Steady state mass balances on a single-stage liquid-liquid extractor.
Extract
E , (XEb, XEC, XEf) Solvent
S , (Xsb, XsC, Xsf)
Extractor
Feed Raffinate
F , (XFb, XFC, XFf) R , (XRb, XRC, XRf)
X Fc =0.9
R R X Sc =0.0001
R R X Rc =? R R X Ec =? R R
X Ff =0.0
R R X Sf =0.9989
R R X Rf =? R R X Ef =? R R
dependent)
raffinate mole fraction constraint X Rb +X Rc +X Rf =1 R R R R R R
Note: you have six variables and seven equations therefore; you have to choice any
six equations from these equations. In this case, we neglect mole balance equation.
Put the equations in matrix form.
1 R 0 0 E 0 0
2 0 R 0 0 E 0
3 1 1 1 0 0 0
4 0 0 0 1 1 1
5 -Kb 0 0 1 0 0
6 0 -Kc 0 0 1 0
Table (1.5) Matlab code and results for solution example (1.13)
F=100;S=150;R=95;E=155;
Kb=20;Kc=0.05;XFb=.1;XFc=.9;XFf=0;
XSb=.001;XSc=.0001;XSf=.9989;
Matlab A=[R,0,0,E,0,0;0,R,0,0,E,0;1,1,1,0,0,0;0,0,0,1,1,1;-Kb,0,0,1,0,0;0,-Kc,0,0,1,0];
Code B=[F*XFb+S*XSb;F*XFc+S*XSc;1;1;0;0];
X=A\B;
XRb=X(1),XRc=X(2),XRf=X(3),XEb=X(4),XEc=X(5),XEf=X(6)
XRb =
0.0032
XRc =
0.8761
XRf =
0.1208
Results XEb =
0.0635
XEc =
0.0438
XEf =
0.8927
Example 2.1
(1 − e−0.15x) =50 using the graphical method.
600
Solve
x
Solution
(1 − e−0.15x) − 50 can be plotted in Figure 2.1 using the
600
The function f(x) =
x
Matlab statements listed in table (2.1).
Table (2.1) Matlab code for solving example (2.1) using graphical method
x=4:0.1:20;
fx=600*(1-exp(-0.15*x))./x-50;
Matlab plot(x,fx,[0 20],[0 0])
Code xlabel('x');
ylabel('f(x)')
grid on; zoom on
20
15
10
0
f(x)
-5
-10
-15
-20
-25
0 2 4 6 8 10 12 14 16 18 20
x
0.06
0.04
0.02
0
f(x)
-0.02
-0.04
-0.06
-0.08
Figure 2.2 The graphical method for roots finding with Matlab Zoom on.
The plot of a function between x 1 and x 2 is important for understanding its behavior
within this interval. More than one root can occur within the interval when f(x 1 ) and
f(x 2 ) are on opposite sides of the x axis. The roots can also occur within the interval
when f(x 1 ) and f(x 2 ) are on the same sides of the x axis. Since the functions that are
tangent to the x axis satisfy the requirement f(x) = 0 at this point, the tangent point is
called a multiple root.
Figure 2.3 shows first three iterations x 3 , x 4 , and x 5 of the bisection method.
15
10
x5 x3 x2=b
f(x)
0
x1 = a x4
-5
-10
-15
4 6 8 10 12 14 16
x
Figure 2.3 The first three iterations x 3 , x 4 , and x 5 of the bisection method.
Table (2.2) Matlab code and results for solving example (2.1) using bisection method
fun=inline('600*(1-exp(-0.15*x)) /x-50')
x1=6;
f1= fun (x1);
x2=14;
f2= fun (x2);
tol=1e-5;
for i=1:100
x3=(x1+x2)/2;
f3= fun(x3);
Matlab
if f1*f3<0
Code
x2=x3;
f2=f3;
else
x1=x3;
f1=f3;
end
if abs(x2-x1)<tol; break;end
end
x3
x3 =
Results
8.7892
The statement Inline is used to define the function at a given value of x.
Example 2.2
Use the bisection method to find the root of the equation x-cos(x) = 0 with a percent
relative error |ε t |≤ 1%. (The exact value is 0.7391)
Solution
f(x)= x-cos(x)
Example 2.3
The friction factor f depends on the Reynolds number Re for turbulent flow in smooth
pipe according to the following relationship.
1
= −0.40 + 3 ln(Re f )
f
Use the bisection method to compute f for Re = 25200 that lies between [0.001 ,0.1 ].
Solution
Re-write the above equation in the form
1
E ( f ) = −0.40 + 3 ln(25200 f ) −
f
Iter fl f2 f3 E(f l ) E(f 2 ) E(f 3 )
1 0.0010 0.1000 0.0505 -20.4514 11.9973 10.1179
2 0.0010 0.0505 0.0258 -20.4514 10.1179 7.7528
3 0.0010 0.0258 0.0134 -20.4514 7.7528 4.7705
4 0.0010 0.0134 0.0072 -20.4514 4.7705 1.0841
5 0.0010 0.0072 0.0041 -20.4514 1.0841 -3.2373
6 0.0041 0.0072 0.0056 -3.2373 1.0841 -0.6453
7 0.0056 0.0072 0.0064 -0.6453 1.0841 0.2946
8 0.0056 0.0064 0.0060 -0.6453 0.2946 -0.1536
Then according to above table f = 0.006
x1 x3 x4
x5 x2
A
f(x1)
The intersection of the straight line with the x-axis can be obtained by using similar
triangles x 3 x 1 A and x 3 x 2 A or by using linear interpolation with the following
points.
x x1 x3 x2
f(x) f(x 1 ) 0 f(x 2 )
x3 − x 2 0 − f ( x2 ) x2 − x1
= ⇒ x 3 = x 2 − f(x 2 )
x2 − x1 f ( x 2 ) − f ( x1 ) f ( x2 ) − f ( x1 )
The next guess is then obtained from the straight line through two points [x 2 , f(x 2 )]
and [x 3 , f(x 3 )]. In general, the guessed valued is calculated from the two previous
points [x n-1 , f(x n-1 )] and [x n , f(x n )] as
xn − xn −1
x n+1 = x n − f(x n )
f ( xn ) − f ( xn −1 )
The secant method always uses the latest two points without the requirement that they
bracket the root as shown in Figure 2.4 for points [x 3 , f(x 3 )] and [x 4 , f(x 4 )]. As a
consequence, the secant method can sometime diverge. A Matlab program for
Example 2.4
Use secant method to estimate the root of f(x)=e-x-x. with the two initial guesses x 0 =
0. and x 1 = 1.
Solution:
Iter x f(x)
Starting 0 1.0000
Values 1.0 -0.6321
1 0.6127 -0.0708
2 0.563838 0.00518
3 0.56717 -0.0000418
Example 2.6
Use secant method with initial guesses T = 300 and T = 350 to calculate the bubble
point of binary system (VCM 18 mol%, Water 82 mol%). The vapor pressure for this
components is calculated by:
VCM Po vcm =exp(14.9601-1803.84/(T-43.15))
Water Po w =exp(18.3036-3816.44/(T-46.13))
Where: K i = P o i /P t
P t =760
y i =K i ×x i
At Bubble point ∑y i =∑K i ×x i =1
Solution
1803.84 3816.44
(14.9601- ) 0.18 (18.3036 - T - 46.13 ) 0.82
f(T)= K i ×x i -1 = e T - 43.15
× +e × -1
760 760
Iter T f(T)
Initial 300.0000 -0.3086
Values 350.0000 1.4192
1 308.9299 -0.1132
2 311.9636 -0.0378
3 313.4866 0.0018
4 313.4157 -0.000028
Then at bubble point T=313.457 K
f(x)
f(x1) B
x3 x2 x1
In general, from the point [x n , f(x n )], the next guess is calculated as
f ( xn )
x n+1 = x n −
f ' ( xn )
A Matlab program for solving example 2.1 using Newton- Raphson method is listed
in Table 2.4 .
Example 2.7
Use Newton-Raphson method to estimate the root of f(x)=e-x-x. Show all details of
the iterations. Hint: the root is located between 0 and 1.
Solution:
Iter Xi f(X i ) f’(X i ) X i+1 |ε a (%)|
1 0.0 1.0 -2.0 0.5 100.00
2 0.5 0.1065 -1.6065 0.5663 11.71
3 0.5663 0.0013 -1.5676 0.5671 0.15
4 0.5671 0.0000 -1.5676 0.5671 0.00
Example 2.8
Repeat Example 2.7 starting with x o = 5.
Solution:
Iter Xi f(X i ) f’(X i ) X i+1 |ε a (%)|
1 5.0 -4.9933 -1.0067 0.04016 12351
2 0.04016 0.92048 -1.9606 0.5096 92.12
3 0.5096 0.0911 -1.6007 0.5665 10.04
Numerical Analysis / M. Sc. - 34 - Written by Assoc. Prof.
Chap. 2 Dr. Zaidoon M. Shakoor
4 0.5665 0.0010 -1.5675 0.5671 0.000
Example 2.9
Apply Newton-Raphson method to solve Redlich-Kwong equation which used to
estimate the molar volume of saturated vapor of methyl chloride at 333.15 K and
13.76 bar
RT a
P= − 0.5
V − b T V (V + b)
If you know that:-
A=1.5651×108 cm6 bar mol-2 K1/2
b=44.891 cm3 mol-1
R=83.14 cm 3.bar.K-1.mol-1
Solution
RT a
f (V ) = − 0.5 −P
V − b T V (V + b)
83.14 × 333.15 1.5651 × 108
f (V ) = − − 13.76
V − 44.891 333.150.5V (V + 44.891)
27698 8574764.131
f (V ) = − − 13.76
V − 44.891 V (V + 44.891)
- 27698 8574764.131 8574764.131
f ′(V) = + + 2
(V − 44.891) 2
V(V + 44.891) 2
V (V + 44.891)
It’s better to start with ideal molar volume as initial value of V
RT 83.14 × 333.15
V= = = 2012.943
P 13.76
Iter Vi f(V i ) f’(V i ) V i+1
1 2012.943 -1.75623 -0.00512 1669.717
2 1669.717 0.291628 -0.00695 1711.673
3 1711.673 0.005731 -0.00668 1712.531
4 1712.531 0.00000231 -0.00667 1712.531
The molar volume equal to 1712.531 cm3 mol-1
Examples: x2 + y2 = 25 y = 3x2 – 4x + 2 xy = 9
2x + 3y = 7 x2 + y = 8 3x2 – y2 = 12
The solutions of a nonlinear system are the points of intersection of the graphs of the
equations. Some systems have one point of intersection; some have more than one
point of intersection; and some have no points of intersection.
Example 2.10
Solve x2 + 2x = y + 6
x + y = –2
Solution
x + y = –2 → y = –2 – x → x2 + 2x = –2 – x + 6 →
x2 + 3x – 4 = 0 → (x + 4) (x – 1) = 0 → x = –4 & x = 1
y = –2 – (–4) = 2 & y = –2 – 1 = –3 →
Line the equations up vertically so like terms are underneath each other. If needed,
multiply each equation by a number so that when the equations are added together one
of the variables is eliminated. Solve for the remaining variable. Back substitute to find
the value(s) of the eliminated variable. Write your solutions as ordered pairs.
Example 2.11
Solve 3x2 + 5y2 = 17
2x2 – 3y2 = 5
Solution:
3x2 + 5y2 = 17 3R 1 9x2 + 15y2 = 51
→
It can be shown that sufficient convergence criteria for two equations are:
∂f1 ∂f
+ 1 <1
∂x1 ∂x2
Example 2.12
Solve using 5 iteration of successive substitution where x = y = 1.5 initially:
x 2 + y 2 = 5
y − x 2 = −1
Solution
Iteration xn yn
0 1.5 1.5
1 1.658 1.75
2 1.392 0.9375
3 2.030 3.121
4 Non-real Non-real
5
So it is apparent that successive substitution this will not work using these formulas.
Iteration xn yn
0 1.5 1.5
1 1.5811 1.5811
2 1.607 1.555
3 1.599 1.564
4 1.601 1.561
5 1.600 1.562
1 + 17 − 1 + 17
Which is rapidly converging on the true solution of ,
2 2
As with the Jacobi iterative process, convergence is assured only for a system of
Numerical Analysis / M. Sc. - 38 - Written by Assoc. Prof.
Chap. 2 Dr. Zaidoon M. Shakoor
diagonally dominant linear equations. For systems that are neither linear nor
diagonally dominant, convergence is a function of the equations themselves as well
as the values of x’s chosen to start the iterations.
Example 2.13
As an example of applying the Jacobi method to a system of non-linear equations,
consider the following system:
4 x1 − x 2 + x 3 =7
4x1 −8( x 2 ) + x 3 =−21
2
Solving the equations for each of the unknowns (x’s), we have the following:
7+ x 2 − x 3
2
x1 =
4
−21−4x1 − x 3
x2 =
−8
15+2x1 − x 2
x3 =
5
Using these relationships in a Jacobi algorithm with starting values of x 1 = x 2 = x 3 =
0, we can show the convergence of the algorithm over ten iterations in the following
table:
Itr x1 x2 x3
0 0 0 0
1 3.0625 1.620185 1.732051
2 2.9654 2.091114 1.975086
3 3.164866 2.086764 1.941118
4 3.191267 2.109519 1.961783
5 3.193133 2.113257 1.963314
6 3.195105 2.113523 1.963314
7 3.195343 2.113757 1.963501
8 3.195385 2.113790 1.963514
9 3.195403 2.113796 1.963516
10 3.195406 2.113798 1.963518
For the root estimate f1(i+1) and f 2(i+1) must be equal zero.
Therefore:
∂f1(i ) ∂f ∂f ∂f
x1(i+1) + 1(i ) x2 (i+1) = − f1(i ) + x1(i ) 1(i ) + x2(i ) 1(i )
∂x1 ∂x2 ∂x1 ∂x2
and
∂f 2(i ) ∂f ∂f ∂f
x1(i+1) + 2(i ) x2(i+1) = − f 2(i ) + x1(i ) 2(i ) + x2(i ) 2(i )
∂x1 ∂x2 ∂x1 ∂x2
Finally:
∂f 2 (i ) ∂f1(i )
f1(i ) − f 2 (i )
∂x 2 ∂x 2
x 1(i +1) = x 1(i ) −
∂f1(i ) ∂f 2 (i ) ∂f1(i ) ∂f 2 (i )
−
∂x 1 ∂x 2 ∂x 2 ∂x 1
∂f1(i ) ∂f 2 (i )
f 2 (i ) − f1(i )
∂x 1 ∂x 1
x 2 (i +1) = x 2 (i ) −
∂f1(i ) ∂f 2 (i ) ∂f1(i ) ∂f 2 (i )
−
∂x 1 ∂x 2 ∂x 2 ∂x 1
x 0 − x1 2 − 9.125
ε= = = 3.5625
x0 2
x 0 − x1 9.125 − 7.543703
ε = = = 0.173293
x0 9.125
∂f1 ∂f1 ∂f 2 ∂f 2
Itr f1 f2 x y εs
∂x ∂y ∂x ∂y
2 4
1 -1 55 -4 4 -16 8 9.125 11.375 3.5625
2 105.1563 105.1563 10.25 18.75 -1.75 22.75 7.543703 6.631109 0.173293
3 25.005 25.005 7.087406 9.262218 -4.91259 13.26222 6.826694 4.480083 0.095047
4 5.141014 5.141014 5.653389 4.960166 -6.34661 8.960166 6.576327 3.728981 0.036675
5 0.626838 0.626838 5.152654 3.457963 -6.84735 7.457963 6.535955 3.607865 0.006139
6 0.016299 0.016299 5.07191 3.215731 -6.92809 7.215731 6.534848 3.604543 0.000169
7 1.23E-05 1.23E-05 5.069696 3.209087 -6.9303 7.209087 6.534847 3.604541 1.28×10-7
Setting this equal to f(t,y) and solving for y (t + ∆t ) yields the following algorithm for
Example 3.2:
Apply Euler’s method to approximate the solution of the initial value problem
dy
= 2 y with y (0) = 5 (2)
dx
Solution:
We know that the analytical solution of equation (2) is , y = 5 exp(2 x) . We numerically
solve equation (2) using Euler’s method with h=0.1 in the time interval [0, 0.5], and
then check how well this method performs. We have f ( y ) = 2 y . Then
x0 = 0
x1 = x0 + h = 0 + 0.1 = 0.1
x 2 = x1 + h = 0.1 + 0.1 = 0.2
x3 = x 2 + h = 0.2 + 0.1 = 0.3
x 4 = x3 + h = 0.3 + 0.1 = 0.4
x5 = x 4 + h = 0.4 + 0.1 = 0.5
And
y0 = 5
y1 = y 0 + hf ( y 0 ) = 5 + (
0.1)( 2)(5) = 6
h f ( y0 )
y 2 = y1 + hf ( y1 ) = 6 + (0.1)(2)(6) = 7.2
y 3 = y 2 + hf ( y 2 ) = 7.2 + (0.1)(2)(7.2) = 8.64
y 4 = y 3 + hf ( y 3 ) = 8.64 + (0.1)(2)(8.64) = 10.368
y 5 = y 4 + hf ( y 4 ) = 10.368 + (0.1)(2)(10.368) = 12.4416
Doing five steps only gets us to x=0.05. We can do more steps until we reach x=0.5.
We find that the final point will be:
x y Exact Difference
0.5 13.45794 13.59141 0.133469
Choosing a smaller value for h resulted in a better approximation at x=0.5 but also
required more steps. One source of error in the approximation comes from the
approximation itself.
Example 3.3
Consider the following initial value problem:
dx 2
=t +t with the initial condition: x (0) = 0.5 from t=0 to t=2
dt
Solution:
4.5
3.5
3
x(t)
2.5
1.5
0.5
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (t)
5.5
4.5
3.5
x(t)
2.5
0.5
0 0.5 1 1.5 2 2.5
Time (t)
yi +1 = yi +
1
(k1 + 2k2 + 2k3 + k4 )h
6
k1 = f (xi , yi )
1 1
k2 = f xi + h, yi + k1h
2 2
1 1
k3 = f xi + h, yi + k2 h
2 2
Numerical Analysis / M. Sc. - 48 - Written by Assoc. Prof.
Chap. 3 Dr. Zaidoon M. Shakoor
k4 = f (xi + h, yi + k3h )
Example 3.4:
Solve the following ordinary differential equation (ODE) using fourth order
Runge-Kutta method to calculate y(x=0.2)
dy
= x + y ; y(0) = 1 , h = 0.1
dx
Solution:
k 1 = 0 + 1= 1
k 2 = (0+0.05)+(1+1×0.05)=1.10
k 4 = (0+0.1)+(1+1.1050×0.1) = 1.2105
h
y1 = y o + ( k1 + 2k 2 + 2k 3 + k 4 )
6
0.1
y(0.1) = 1 + × (1 + 2 × 1.1 + 2 × 1.105 + 1.2105) = 1.11034
6
k 2 = (0.1+0.05)+(1.11034+1.21034×0.05) = 1.3209
Example 3.5:
A ball at 1200 K is allowed to cool down in air at an ambient temperature of 300 K.
Assuming heat is lost only due to radiation, the differential equation for the
temperature of the ball is given by
Solution
= −2.2067 × 10 −12 (T 4 − 81 × 108 )
dT
dt
Ti+1 = Ti +
h
(k1 + 2k 2 + 2k 3 + k 4 )
6
For i = 0 , t 0 = 0 , T0 = 1200 K
k 2 = f t 0 + h , T0 + k1h = f 0 + (240 ),1200 + (− 4.5579 ) × 240
1 1 1 1
2 2 2 2
(
= f (120,653.05) = −2.2067 × 10 −12 653.054 − 81 × 108 )
= −0.38347
k 3 = f t 0 + h , T0 + k 2 h = f 0 + (240 ),1200 + (− 0.38347 ) × 240
1 1 1 1
2 2 2 2
( )
= f (120,1154 .0 ) = −2.2067 × 10 −12 1154 .0 4 − 81 × 108 = −3.8954
h
T1 = T0 + ( k1 + 2k 2 + 2k 3 + k 4 )
6
= 1200 +
240
(− 4.5579 + 2(− 0.38347 ) + 2(− 3.8954) + (0.069750))
6
= 675.65 K
= −0.44199
Numerical Analysis / M. Sc. - 50 - Written by Assoc. Prof.
Chap. 3 Dr. Zaidoon M. Shakoor
k 2 = f t1 + h , T1 + k1h = f 240 + (240 ),675.65 + (− 0.44199 )240
1 1 1 1
2 2 2 2
= f (360,622.61) = −2.2067 × 10 −12 (622.614 − 81 × 108 )
= −0.31372
k 3 = f t1 + h , T1 + k 2 h = f 240 + (240 ),675.65 + (− 0.31372 ) × 240
1 1 1 1
2 2 2 2
= f (360,638.00 )
(
= −2.2067 × 10 −12 638.00 4 − 81 × 10 8 )
= −0.34775
k 4 = f (t1 + h , T1 + k 3h ) = f (240 + 240,675.65 + (− 0.34775) × 240 ) = f (480,592.19 )
= −0.25351
h
T2 = T1 + (k1 + 2k 2 + 2k 3 + k 4 )
6
= 675.65 +
240
(− 0.44199 + 2(− 0.31372) + 2(− 0.34775) + (− 0.25351))
6
= 594.91 K
Table 1 and Figure 2 show the effect of step size on the value of the calculated
temperature at t = 480 seconds.
Example 3.6
Using Matlab Commands solve the following equation using both Eular and
Runge-Kutta method and to approximate the solution of the initial value problem
dy
= x + y, y (0) = 1 with step size h = 0.1.
dx
Numerical Analysis / M. Sc. - 51 - Written by Assoc. Prof.
Chap. 3 Dr. Zaidoon M. Shakoor
Solution:
Eular Runge-Kutta
clear all, clc,format short clear all, clc,format short
x(1)=0; x(1)=0;y(1)=1;h=0.1;
y(1)=1; f=inline('x+y');
h=0.5 % f(x,y) = x+y
for i=1:5 for i=1:5
x(i+1)=x(i)+h; x(i+1)=x(i)+h;
dy=x(i)+y(i); k1 = f(x(i),y(i));
y(i+1)=y(1)+h*dy; k2 = f(x(i)+h/2,y(i)+k1*h/2);
end k3 = f( x(i) + h/2,y(i)+k2*h/2);
y_exact= -1-x+2*exp(x); k4 = f( x(i) + h,y(i)+k3*h);
error=y_exact-y y(i+1)=y(i)+(1/6)*h*(k1 +2*k2 + 2*k3 +k4);
table=[x',y',y_exact',error'] end
y_exact= -1-x+2*exp(x); error=y_exact-y
table=[x',y',y_exact',error']
table = table =
0 1.0000 1.0000 0 0 1.0000 1.0000 0
0.1000 1.1000 1.1103 0.0103 0.1000 1.1103 1.1103 0.0000
0.2000 1.1200 1.2428 0.1228 0.2000 1.2428 1.2428 0.0000
0.3000 1.1320 1.3997 0.2677 0.3000 1.3997 1.3997 0.0000
0.4000 1.1432 1.5836 0.4404 0.4000 1.5836 1.5836 0.0000
0.5000 1.1543 1.7974 0.6431 0.5000 1.7974 1.7974 0.0000
To solve the example 3.3 using MATLAB Routine, We just have to write a
function which returns the rate of change of the vector x.
function dx = example(t,x)
dx(1,1) = t^2+t;
The above file named example.m must be saved in default MATLAB folder then
Numerical Analysis / M. Sc. - 52 - Written by Assoc. Prof.
Chap. 3 Dr. Zaidoon M. Shakoor
the following code must run.
Vspan = 0:0.2:2;
x0=0.5;
[t,x] = ode45('example',Vspan,x0);
plot (t,x,'k*:')
xlabel('Time (t)')
ylabel('x(t)')
legend('Runge Kutta integration')
The numerical solution, computed using ODE45 is given below in Figure (3.3)
4
x(t)
0 0.5 1 1.5 2
Time (t)
Figure (3.3): Solution produced by ODE45.
k11 = f ( xi , yi , zi )
k12 = g( xi , yi , zi )
k 21 = f ( xi + 0.5 h , yi + 0.5 hk11 , zi + 0.5 hk12 )
k 22 = g ( xi + 0.5 h , yi + 0.5 hk11 , zi + 0.5 hk12 )
k32 = f ( xi + 0.5 h , yi + 0.5 hk 21 , zi + 0.5 hk 22 )
k32 = g( xi + 0.5 h , yi + 0.5 hk 21 , zi + 0.5 hk 22 )
k41 = f ( xi + h , yi + hk31 , zi + hk32 )
k42 = g( xi + h , yi + hk31 , zi + hk32 )
As example an exothermic reaction in unsteady-state continuous stirred tank reactor
and exothermic reaction in a plug flow reactor with heat exchange through the reactor
wall.
From the one and two ODE examples, you can extend the method to integration of
three coupled ODE’s. Three coupled ODE’s would be encountered, for example, for
reaction of gases in a steady-state non-isothermal plug flow reactor with significant
pressure drop (dC/dx =, dT/dx =, and dP/dx=).
h
yin + 1 = yin + (k1,i + 2k 2,i + 2k3,i + k4,i ) Where i = 1, 2, ..., m and
6
h n hk1,1 n hk1,2 hk
k 2,i = f i (x n + , y1 + , y2 + …, ymn + 1,m )
2 2 2 2
Example 3.7:
Using fourth order Runge-Kutta method with step size h = 0.1 solve
dy1
= y1 y2 + x , y 1 (0) = 1
dx
dy 2
= xy 2 + y 1 , y 2 (0) = -1
dx
Solution
At x = 0, y 1 = 1, y2 = -1
k 1,1 = y1 y2 + x = (1)(-1) + 0 = -1
k 1,2 = xy 2 + y 1 = (0)(-1) + 1= 1
k 2,1 = (y 1 +0.5hk 1,1 )(y 2 +0.5hk 1,2 ) + (x+0.5h) =(0.95)(-0.95) + 0.05 = -0.8525
k 2,2 = (x+0.5h)(y 2 +0.5hk 1,2 ) +(y 1 +0.5hk 1,1 ) =(0.05)(-0.95) + 0.95 = 0.9025
k 3,1 = (y 1 +0.5hk 2,1 )(y 2 +0.5hk 2,2 ) + (x+0.5h) =(0.9574)(-0.9549) + 0.05= -0.8642
k 3,2 = (x+0.5h)(y 2 +0.5hk 2,2 ) +(y 1 +0.5hk 2,1 ) =(0.05)(-0.9549) + 0.9574 = 0.9096
k 4,1 = (y 1 +hk 3,1 )(y 2 +hk 3,2 ) + (x+h) =(0.9136)(-0.9091) + 0.1 = -0.7305
k 4,2 = (x+h)(y 2 +hk 3,2 ) +(y1 +hk 3,1 ) =(0.1)(-0.9091) + 0.9136= 0.8227
at x=0.1
y1 (0.1) = y 1 (0) + (h/6)(k 1,1 + 2k 2,1 + 2k 3,1 + k 4,1 )
Example 3.8
Use ode45 Matlab Command to solve the following first order system for y1 and y2 at
0 ≤ x ≤ 1.
The command ode45 is then evaluated from the command windows. Matlab will set
the step size to achieve a preset accuracy that can be changed by user.
The independent variable can also be specified at certain locations between the initial
and final values and Matlab will provide the dependent value at these locations.
xspan=0:0.1:1;
[x,y]=ode45('exode',xspan,[1 , -1])
x= y=
0 1.0000 -1.0000
0.1000 0.9139 -0.9092
0.2000 0.8522 -0.8341
0.3000 0.8106 -0.7711
0.4000 0.7863 -0.7174
0.5000 0.7772 -0.6705
0.6000 0.7817 -0.6283
0.7000 0.7987 -0.5889
0.8000 0.8274 -0.5504
0.9000 0.8675 -0.5108
1.0000 0.9188 -0.4681
Exercise 3.9:
Let’s consider a simple example of a model of a plug flow reactor that is described by a
system of ordinary differential equations. A plug flow reactor is operated as shown in
Figure (3.4) below.
The plug flow initially has only reactant A, the components A react to form component
B. The mole balance for each component is given by the following differential
equations
dC A
u = − k 1C A
dz
dC
u B = k 1C A − k 2 C B
dz
dC
u C = k 2CB
dz
With the following initial values
C A (z=0) =1 kmol/m3 C B (z=0) =0 C C (z=0) =0 and k 1 =2 k 2 =3
If u=0.5 m/s and reactor length z=3 m. Solve the differential equations and plot the
concentration of each species along the reactor length
Solution:
We’ll start by writing the function defining the right hand side (RHS) of the ODEs. The
following function file ‘Example’ is used to set up the ode solver.
Now we’ll write a main script file to call ode45. CA, CB and CC must be defined
within the same matrix, and so by calling CA as C(1), CB as C(2) and CC as c(3), they
are listed as common to matrix C.
The following run file is created to obtain the solution:
1
A
Concentrations (kmol/m3)
B
0.8
C
0.6
0.4
0.2
0
0 1 2 3
Length (m)
Figure (3.5): A, B and C concentrations along plug flow reactor
dy dz1
= = z2 (2)
dx dx
d 2 y dz 2
= = z3 (3)
dx 2 dx
=
1
(− a n−1 z n − a1 z 2 − a0 z1 + f (x )) (n+1)
an
The above Equations from (2) to (n+1) represent n first order differential equations as
follows
dz1
= z 2 = f 1 ( z1 , z 2 , , x )
dx
dz 2
= z 3 = f 2 ( z1 , z 2 , , x )
dx
dz n
=
1
(− a n−1 z n − a1 z 2 − a0 z1 + f (x ))
dx an
Each of the n first order ordinary differential equations is accompanied by one initial
condition. These first order ordinary differential equations are simultaneous in nature
but can be solved by the methods used for solving first order ordinary differential
equations that we have already learned.
Example 3.10
Re-write the following differential equation as a set of first order differential equations.
d2y
+ 2 + 5 y = e − x , y (0) = 5, y ′(0) = 7
dy
3 2
dx dx
Solution
The ordinary differential equation would be rewritten as follows. Assume
dy d 2 y dz
= z, Then =
dx dx 2 dx
Substituting this in the given second order ordinary differential equation gives
dz
3 + 2z + 5 y = e −x
dx
dz 1 − x
(
= e − 2z − 5 y
dx 3
)
The set of two simultaneous first order ordinary differential equations complete with
the initial conditions then is
= z, y (0) = 5
dy
dx
= (e − 2 z − 5 y ), z (0) = 7 .
dz 1 − x
dx 3
Now one can apply any of the numerical methods used for solving first order ordinary
differential equations.
Example 3.11
Given the third-order ordinary differential equation and associated initial conditions
d3y d2y dy y (0) = 4, dy d2y
3
+ 3 2 + 5 + y = x2 , = 0.6 , 2 = 0.22
dx dx dx dx x =0 dx x =0
(a) Elliptic
∂ 2u ∂ 2u
+ 2 =0 (Laplace’s equation)
∂x 2 ∂y
∂ 2u ∂ 2u
+ 2 +e=0 (Poisson’s equation)
∂x 2 ∂y
(b) Parabolic
∂u ∂ 2u
=α 2 ; where α is a positive constant
∂y ∂x
∂u ∂ 2u ∂ 2u
= α ( 2 + 2 ) + e; (Parabolic in time t and elliptic in spatial dimensions x
∂t ∂x ∂y
and y)
(c) Hyperbolic
∂ 2u 2∂ u
2
− c =0 (wave’s equation)
∂t 2 ∂x 2
For constant physical properties and no heat generation, the heat conduction equation
becomes
ρCp ∂T = k∇2T or ∂T = α∇2T
∂t ∂t
k
Where: α = is the thermal diffusivity of the materials.
ρc p
We must consider changes in time as well as in space for parabolic equations. The
domain of elliptic equations is a closed region whereas the domain of parabolic
equations is an open region in time.
x x + ∆x x
So if you want to find the value of f ′(x ) at x = xi , we may choose another point ' Δx'
ahead as x = xi +1 . This gives
f ( xi +1 ) − f ( xi )
f ′( xi ) ≅
∆x
f ( xi +1 ) − f ( xi )
= Where Δx = xi +1 − xi
xi +1 − xi
f (x)
x
x − ∆x x
Figure 4.2 Graphical representation of backward
difference approximation of first derivative
x − ∆x x x + ∆x
∂t ∂x 2
We have an explicit method if the time derivative is approximated by a forward
difference and the second spatial derivative is approximated by a central difference
n +1
∂T = Ti − Ti
n
∂t ∆t
∂ 2T Ti +n1 − 2Ti n + Ti −n1
=
∂x 2 ∆x 2
In finite difference form, the heat conduction equation becomes
Ti n +1 − Ti n Ti +n1 − 2Ti n + Ti −n1
=α
∆t ∆x 2
The explicit scheme is depicted in Figure 4.4 where three nodes in the previous time
tn are required to compute the node at the present time tn+1.
xi-1 xi xi+1
n+1
t
The temperature at node i can be obtained from the three previous time nodes as
α∆t α∆t
Ti n +1 = ( Ti +n1 + Ti −n1 ) + 1 − 2 Ti n
( ∆x ) 2
( ∆x )
2
A solution is stable when the errors at any stage of the computation are not amplified
but are attenuated as the computation progresses. For stable solution
α∆t α∆t 1
1 − 2 ≥0⇒
2
≤
( ∆x ) ( ∆x ) 2
2
Example 4.1:
∂ T 2
Solve the partial differential equation ∂T = 0.02 2 with the following initial and
∂t ∂x
boundary conditions Initial conditions: T(x, 0) = 100x for 0 ≤ x ≤ 0.5; T(x, 0) =
100(1− x) for 0.5 ≤ x ≤ 1 Boundary conditions: T(0, t) = 0; T(1, t) = 0
x=0:0.1:1;
T=[0 20 40 60 80 100 80 60 40 20 0];
k=1;
plot(x,T,'k-*')
for t=0.5 :0.5:5
k=k+1;
T(k,1)=0;
T(k,11)=0;
for i=2 :10
T(k,i)=0.25*(T(k-1,i+1)+T(k-1,i-1))+0.5*T(k-1,i);
end
hold on
plot(x,T(k,:),'k-*')
hold off
end
xlabel('x'),ylabel ('Temperature')
90
80
70
Temperature
60
50
40
30
20
10
Time
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x
Figure (4.5): Temperature distribution using explicit method.
If you need to plot your results in three dimension plot, try the code after the above
program:
[X,Time]=meshgrid(x,[0:0.5:5])
surf(X,Time,T)
xlabel('x')
ylabel ('Time')
zlabel ('Temperature')
100
Temperature
80
60
40
20
0
6
1
4
0.8
0.6
2 0.4
0.2
0 0
Time x
Figure (4.6): Three dimensional temperature distribution using explicit method.
L=2,dt=1,D=0.02;dx=sqrt(dt*D/.25);x=0:dx:L;
nx=(L+dx)/dx;T(1,1:nx)=0;T(1,1)=0;
time(1)=0;k=1;
for t=dt:dt:20
k=k+1
T(k,1)=100
for i=2:nx-1
T(k,i)=.25*(T(k-1,i+1)+T(k-1,i-1))+.5*T(k-1,i)
end
end
plot(x,T(4,:),'k-+'x,T(8,:),'k-^',x,T(12,:),'k-*',x,T(20,:),'k-o')
xlabel('length'),ylabel('temperature')
legend('T4','T8','T12','T20')
100
T4
90 T8
T12
80
T20
70
60
temperature
50
40
30
20
10
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
length
Example 4.3
A long column with thermal conductivity k = 1 W/m⋅oK is maintained at 500oK on
three surfaces while the remaining surface is exposed to a convective environment
with h = 10 W/m2⋅oK and fluid temperature T ∞ . The cross sectional area of the
column is 1 m by 1 m. Using a grid spacing ∆x = ∆y = 0.25 m, determine the steady-
state temperature distribution in the column and the heat flow to the fluid per unit
length of the column.
Solution
The cross sectional area of the column is divided into many sub-areas called a grid or
nodal network with 25 nodes as shown in Figure 4.8. There are 12 nodal points with
unknown temperature, however only 8 unknowns need to be solved due to symmetry
so that the nodes to the left of the centerline are the same as those to the right.
∆x
500 K
m, n+1
∆y
1 2 1
500 K 3 4 3
m-1, n m, n m+1, n
5 6 5 500 K
7 8 7
h= 300 K 2
m, n-1
h = 10 W/m K
Figure (4.8): The grid for the column cross sectional area.
The above result shows that the temperature of an interior node is just the average of
the temperatures of the four adjoining nodal points. Using this formula, the
temperatures for the first six nodes are
1
T1 = (T 2 + T 3 + 500 + 500)
4
1
T2 = (T 1 + T 4 + T 1 + 500)
4
1
T3 = (T 1 + T 4 + T 5 + 500)
4
1
T4 = (T 2 + T3 + T6 + T3 )
4
1
T5 = (T 3 + T 6 + T 7 + 500)
4
1
T6 = (T 4 + T5 + T8 + T5 )
4
Nodes 7 and 8 are not interior points; therefore Eq. (3) is not applicable.
∆y
1 2 1
500 K 3 4 3 5 6
5 6 5 500 K
7 8 7
500 K 7 8 7
h = 300 K
h = 10 W/m2K
Figure (4.9): Directions of heat flow for nodes 7 and 8.
We have 8 linear equations with 8 unknowns that can be solved by matrix method or
iterations. As below the MATLAB program using Gauss-Seidel iteration to solve for
the temperatures.
Example 4.4:
Solve for the steady-state temperature in a rectangular slab that is 20 cm wide and 10
cm high. All edges are kept at 0oC except the right edge, which is at 100oC. No heat
gain or loss from the top and bottom surface of the slab as shown in Figure 4.10. Let
∆x = ∆y = 2.5 cm.
top surface
y
b
bottom surface
0 a x
Figure (4.10): A thin rectangular plate with insulated top and bottom surfaces
Solution
The two-dimensional heat conduction equation for steady state, no heat generation,
and k independent of T is given
∂ 2T ∂ 2T
+ =0
∂x 2 ∂y 2
Let i be the index in the x direction and j be the index in the y direction as shown in
Figure 3, the finite difference form of the two-dimensional heat conduction is
Numerical Analysis / M. Sc. 77 Written by Assoc. Prof.
Chap. 4 Dr. Zaidoon M. Shakoor
Ti +1,n − 2Ti , j + Ti −1, j Ti , j +1 − 2Ti , j + Ti , j −1
+ =0
∆x 2
∆y 2
For ∆x = ∆y, the temperature at the node (i, j) can be obtained as
Ti +1, j + Ti , j +1 + Ti −1, j + Ti , j −1
T i,j =
4
y
5
j3
1
1 2 3 4 5 6 7 8 9 x
i
Figure (4.11): The grid of the rectangular plate with insulated top and bottom
surfaces
Example 4.5:
The steady state concentration profile in 0.1 m radius spherical particle can be
described by the following equation:
∂ 2 C A 2 ∂C A
D Ae ( + ) − k1C A = 0
∂r 2 r ∂r
The boundary conditions: C A = C AS at r = R and dC A /dr = 0 at r = 0
With the aid of finite difference approximation and Gaussian elimination method,
solve system of linear equations and plot the concentration profile taken 20 points
radialy in the sphere if you know that:
Effective diffusivity; D Ae =2×10-7 m2/s
Reaction rate constant: K 1 =1×10-3
Concentration in sphere surface: C As =500 mol/m3
Solution
Gaussian elimination Method
500
400
Concentration (mol/m3)
300
200
100
0
0 0.02 0.04 0.06 0.08 0.1
Radius (m)
CA = ∆t D AE ( + ) − ∆t k1CA mj + CA mj . . . . (6)
(∆r ) 2 ∆r
j
rj
DAE=2e-7;% m2/s
R=.1;% m
K1=20;
CAs=500;% mol/m3
np=20;
dr=R/(np-1);
r=0:dr:R;
CA(1:np,1)=0;CA(np,1)=CAs;
m=0;
for time=0:10:3600;
m=m+1;
for j=2:np-1
CA(j,m+1)=CA(j,m)+dt*DAE*((CA(j+1,m)-2*CA(j,m)+…
CA(j-1,m))/(dr^2)+(2/(r(j)))*(CA(j+1,m)-CA(j,m))/dr);
end
CA(np,m+1)=CAs;
CA(1,m+1)=CA(2,m+1);
end
plot(r,CA(:,1:100:end))
xlabel('Radius m')
zlabel('Time (sec)')
ylabel('Concentration (mol/m3)')
200
100
Time =0
0
0 0.02 0.04 0.06 0.08 0.1
Radius m
Figure (4.14) Concentration distribution at different time periods
Solution 2
Using method of line integration using fourth order Runge-Kutta Method
Eq. (4) Re-written in the form
dCA j CA mj+1 − 2CA mj + CA mj−1 2 CA j +1 − CA j −1
m m
= D AE ( + ) − k1CA mj . . . . (7)
dt (∆r ) 2 rj 2∆r
Eq. (7) represents the concentration change of each point with respect to time and
other points. This equation can be written for each point except the terminal points (at
r=0 and at r=R). Therefore these equations can be solved using Fourth order Runge-
Kutta integration method
R=0.1;% m
CAs=500;% mol/m3
np=20;
r=0:R/(np-1):R;
CAo(1:np)=0;CAo(np)=CAs;
Time=0:100:3600;
[Ti,CA]=ode45('Code',Time,CAo);
[RX,TX]=meshgrid(r,Time);
surf(RX,TX,CA);
xlabel('Radius m')
zlabel('Time (sec)')
ylabel('Concentration (mol/m3)')
500
400
Time (sec)
300
200
100
0
4000
0.1
2000
0.05