You are on page 1of 91

1 ‫النمذجة الرايضية يف التطبيقات اهلندسية‬

2 Mathematical Modeling in Engineering Applications


3 Duration: Fifteen Lecture (2 Hours/ Week)
4 Instructor: Dr. AMJED AHMED
5
6 Reference
7 [1] Anders Rasmuson, Mathematical Modeling in Chemical Engineering, 2014, 3rd ed.
8 [2] Amiya K. Jana Chemical Process Modelling and Computer Simulation, 2011, 2nd ed
9

10 First Lecture
11 Introduction
12
13 A student should be able to construct, solve, and apply mathematical models for engineering
14 problems. In particular [1]:
15  Construct models using balances on differential or macroscopic control volumes for
16 momentum, heat, mass, and numbers (population balances);
17  Construct models by simplification of general model equations;
18
19 1.1 Why Do Mathematical Modeling?
20 Mathematical modeling is the art of translating problems from an application area into
21 tractable mathematical formulations whose theoretical and numerical analysis provides
22 insight, answers, and guidance useful for the originating application.
23 Mathematical modeling is a prerequisite for:
24  Design and scale-up;
25  Process control;
26  Optimization;
27  Mechanistic understanding;
28  Evaluation/planning of experiments;
29  Trouble shooting and diagnostics;
30  Determining quantities that cannot be measured directly;
31  Simulation instead of costly experiments in the development lab;
32  Feasibility studies to determine potential before building prototype equipment or devices.
Mathematical Modeling: Introduction 2 / 25

1 1.2 The Modeling Procedure


2 Model building comprises different steps, as.
3
4 Step 1: Problem definition
5 This involves stating clear goals for the modeling,
6 including the various elements that pertain to the problem
7 and its solution. Consider the following questions:
8  What questions should the model be able to answer?
9  What resolution is needed?
10  What degree of accuracy is required?
11
12 Step 2: Formulation of conceptual model
13 The first task is to collect data and experience about the subject to be modeled. The main
14 challenges are in identifying the underlying mechanisms and governing physical/chemical
15 principles of the problem.
16
17 Step 3: Formulation of mathematical model
18 What are the variables (dependent, independent, parameters)?
19 1. The independent variable, x, is the one being changed,
20 2. The dependent variable, y, is the observed variable caused by this change, e.g. y = x3.
21 3. Parameters represent physical quantities that characterize the system and model as
22 functions of the dependent (or independent) variables, e.g. heat capacity Cp. such as
23 density, thermal conductivity, viscosity, reaction rate constants, or activation energies.
24
25 Step 4: Solution of the mathematical problem
26 Check the validity of individual mathematical relationships, consider the analytical solution
27 versus the numerical solution. Analytical solutions are only possible for special situations;
28 essentially the problem has to be linear.
29
30 Step 5: Estimation of parameters
31 The parameters of the system must be evaluated and the appropriate values must be used in the
32 model. Some parameters can be obtained independently of the mathematical model. They may
33 be of a basic character, like the gravitation constant, or it may be possible to determine them by
Mathematical Modeling: Introduction 3 / 25

1 independent measurements, like, for instance, solubility data from solubility experiments.
2
3 Step 6: Evaluation/validation
4 A key step in mathematical modeling is experimental validation. Ideally the validation should
5 be made using independent experimental results, i.e. not the same set as used for parameter
6 estimation. There are certain characteristics that models have to varying degrees and which
7 have a bearing on the question of how good they are:
 Accuracy (is the output of the model correct?); )‫الدقة (هل مخرجات النموذج صحيح؟‬
 Descriptive realism (i.e. Based on correct assumptions); .)‫الواقعية الوصفية (مستند على االفتراضات الصحيحة‬
 Precision (are predictions in the form of definite numbers?); )‫الدقة (هل التنبؤات في القيم صحيح؟‬
 Robustness (i.e. Relatively immune to errors in the input data); )‫المتانة (محصنة نسبيا ً من األخطاء في بيانات المدخالت‬
 Generality (applicable to a wide variety of situations); )‫العمومية (تنطبق على مجموعة واسعة من الحاالت‬
 Fruitfulness (a model is considered fruitful if its conclusions are .)‫غير مثمر (ﻳعتبر النموذج مثمرا إذا كانت استنتاجاتﻪ مفيدة‬
useful).
8
9 Step 7: Application
10 The validated model is then ready to be used for one or several purposes as described earlier.
Mathematical Modeling: Introduction 4 / 25

1 Second Lecture
2
3 1.3 Formulation of Mathematical Model [2]
4 Formulating mathematical models by applying
5 balance and conservation and constitutive
6 relations. A stirred tank is isolated from its
7 surroundings by the dashed circle.
8
9 In general conservation principle, the basic model
10 structure can be developed making balance in
11 terms of three fundamental quantities: mass,
12 energy and momentum.
13
14 A general conservation principle is written as
15 [Accumulation] = [Input] + [Generation] – [Output] – [Consumption] (1.1)
16
17 1. The mass balance equation is
18 [Rate of Mass Accumulation] = [Rate of Mass Input] + [Rate of Mass Generation]
19 – [Rate of Mass Output] – [Rate of Mass Consumption]
20 (1.3)
21
22 Employing Equation (1.3), we can obtain one total mass balance equation along with n
23 component mass balance equations (one for each component), total (n + 1) equations.
24 The total mass balance equation does not have any generation or Consumption term. But the
25 mass of an individual component within a system may change, because of chemical reaction.
26 One component disappears (reactant) another component appear (product).
27
28 2. The energy balance equation can be obtained by modifying Equation (1.2) as:
29 [Rate of Energy Accumulation] = [Rate of Energy Input] + [Rate of Energy Generation]
30 – [Rate of Energy Output] – [Rate of Energy Consumption]
31 (1.4)
32 It is important to note that the first law of thermodynamics is a statement of the conservation of
33 energy for thermodynamic systems.
Mathematical Modeling: Introduction 5 / 25

1
2 The momentum balance equation is given in the following manner:
3 [Momentum Accumulation] = [Momentum Input] + [Momentum Forces Acting on
4 Volume Element] – [Momentum Output] (1.5)
5
6 It is a fact that any generation of momentum must be the result of the forces acting on the
7 volume element. This equation is a generalization of Newton’s law of motion which states that
8 force is the product of mass and acceleration.
9
10 1.4 Model Representation
11 The mathematical model usually describes a system by a set of variables and a set of equations
12 that establish relationships between the variables.
13 In general, there are six basic groups of variables:
14 1. Decision variables,
15 2. Input variables,
16 3. State variables,
17 4. Exogenous variables,
18 5. Random variables,
19 6. Output variables.
20 If there are many variables of each type, the variables may be represented by vectors.
21
22 In addition to these groups of variables, parameters or constant parameters (also sometimes
23 known as exogenous variables) are also present in the mathematical model. A parameter is
24 typically a physical or chemical property value. The values of parameters, such as density, heat
25 capacity, viscosity, activation energy, thermal conductivity, heat transfer coefficient, mass
26 transfer coefficient, etc., must be known or specified for solving a problem.
27
28 All the process variables we mentioned above, such as input, state, or output variables, depend
29 on time and/or spatial position. Therefore, they all are considered as dependent variables.
30 Whereas, time and the spatial coordinate variables are the independent variables.
Mathematical Modeling: Introduction 6 / 25

1
2 Example. The liquid tank is shown in Figure 1.1.
3
4 Fi: the inlet volumetric flow rate (input variable),
5 Fo: the outlet volumetric flow rate (output variable),
6 h : the height of the liquid in the tank, (state variable)
7 V : the volume of the liquid in the tank (state variable)
8 A : the cross-sectional area of the tank (constant).
9
10 The input variables typically include flow rates, compositions, temperatures, and pressures of
11 fluids. In the process control, the input variables are again classified into two categories: load
12 variables (or disturbances) and manipulated (or adjustable) variables.
13 The liquid volume in the tank can be controlled by manipulating the Fo. which is the
14 manipulated variable ‫ المتغير المؤثر‬.
15
16 The output variables are dependent on
17 the state variables. Figure shows the
18 dependency of the output variable y on the state variable x.
19 g has been considered as a nonlinear function of x.
20
21 For a linear case, g(x) may be represented as:
22 g(x) = C x (1.6)
23
24 A state variable arises naturally in the accumulation term of a dynamic balance equation.
25 For example, tray temperature and composition in a distillation column are a state variable
26 that arises when dynamic enthalpy balance is performed around a tray;
27
28 The conservation of mass is a fundamental concept of physics along with the conservation of
29 energy and the conservation of momentum. The conservation principle provides the basic
30 blueprint for building the mathematical models of interest.
31
32 State equations are derived by the application of the conservation principle on the fundamental
33 quantities to relate the state variables with the other variables (including other state variables).
34
Mathematical Modeling: Introduction 7 / 25

1 In the liquid tank (Figure 1.1). The principle of conservation of mass implies
2 [Rate of mass accumulation] = [Rate of mass input] – [Rate of mass output] (1.8)
3 If the liquid density () is assumed constant, then
4 Rate of mass input = Fi 
5 Rate of mass output = Fo 

6
7 where m represents the mass (= volume × density).
8 Equation (1.8) finally gives
𝑑𝑉
9 = 𝐹𝑖 − 𝐹𝑜 (1.9)
𝑑𝑡
10 Equation (1.9) is the state equation and V is the state variable which is dependent on the input
11 variable Fi. Time (t) is commonly regarded as an independent variable.
12 If we assume that the Fo is proportional to the volume of liquid in the tank V as:
13 𝐹𝑜 ∝ √𝑉 (1.10)
14 Then
15 𝐹𝑜 = 𝐶√𝑉 (1.11) a nonlinear expression
16 C: represents the constant of proportionality.
17 Substituting in Equation (1.9),
𝑑𝑉
18 = 𝐹𝑖 − 𝐶√𝑉
𝑑𝑡
19 The state variable V is dependent on the input variable Fi only.
Mathematical Modeling: Introduction 8 / 25

1 Third Lecture
2
3 1.5 Classification of Modelling Equations
4 1.1 Classification based on Models into Opposite Pairs
1. Linear versus nonlinear models; .‫ الخطية × غير الخطية‬
2. Static model vs. dynamic model ‫ حالة ثابتة × حالة متحركة‬
3. Lumped parameter versus distributed parameter; ‫ عامل مجمعة × عامل موزعة‬
4. Fundamental model vs. empirical model. ‫ المودﻳل الرﻳاضي × التجرﻳبية‬
5. Continuous versus discrete variables; .‫ المتغيرات المستمرة × المتغيرات المتقطعة‬
6. Interpolation versus extrapolation; .‫ االستيفاء × االستقراء‬
5
6 1. Linear Model vs. Nonlinear Model
7 Models are linear if the dependent variables or their derivatives appear only to the first power;
8 otherwise they are nonlinear. General analytical methods solving are all based on linearity.

linear Model Nonlinear Model

The pressure P at any liquid depth in the The flow of liquid through the valve is given
vessel is given by the following linear by the following nonlinear relationship:
relationship.
P = Po + h  (1.14)
P = pressure at depth h (kg/m2) F = flow through valve (m3/s)
h = depth (m) CV = valve coefficient (m3/(s)(kg/m2)
Po = pressure above surface (kg/m2)
ΔP = pressure drop across valve (kg/m2)
 = liquid density (kg/m3)
GF = specific gravity of liquid.
Linear model consists of either linear AE(s) Nonlinear model consists the nonlinear AE(s)
or linear ODE(s) or both. and/or nonlinear ODE(s).
It never include any nonlinear equation. it may include linear form of equations
Mathematical Modeling: Introduction 9 / 25

1 2. Static Model vs. Dynamic Model


2 Static processes is time invariant, steady state, or stationary. These terms refer to a process in
3 which the point values of the dependent variables remain constant over time, as at steady state
4 and at equilibrium. A static model is represented with algebraic equations.
5
6 Dynamic processes are also called unsteady state, transient, or dynamic, and represent a
7 situation in which the process dependent variables change with respect to time. A typical
8 example of an unsteady-state process is the startup of a distillation column which would
9 eventually reach a pseudo steady-state (equilibrium) set of operating conditions.
10 Dynamic model is described by differential equations. The liquid tank (Figure 1.1) is
11 mathematically represented by the following form:

12
13 Equation (1.13) represents a dynamic model since practically all the variables,
14
15 At static model or steady state, Equation (1.13) becomes:
16 0 = Fis – Fos (1.18)
17
18 3. Lumped parameter model vs. distributed parameter model
19 ‫نموذج المعامالت المجتمعة × نموذج المعامالت المتفرقة‬
20 A lumped-parameter representation means that spatial variations are ignored, and the various
21 properties and the state of a system can be considered homogeneous throughout the entire
22 volume. If the response of the process is “instantaneous” throughout the process, then the
23 process can be lumped. If the response shows instantaneous differences throughout the process,
24 then it should not be lumped.
25
26 A distributed-parameter representation, in contrast, considers detailed variations in behavior
27 from point to point throughout the system.
28 All real systems are distributed in that there some variations occur throughout them. As the
29 variations are often relatively small, they may be ignored, and the system may then be
30 “lumped.”
31
32 There are processes in which the dependent variables may be considered as being uniform
Mathematical Modeling: Introduction 10 / 25

1 throughout the entire system, varying only with one independent variable (time, for example,
2 but not space). These processes are called as lumped parameter systems because the dependency
3 of all the observed variations have been lumped into one single independent variable.
4 Because the mathematical procedures for solving lumped-parameter models are simpler than
5 those for solving distributed-parameter models,
6
7 i) Lumped Parameter Model
8 A typical example of a lumped parameter system is a perfectly as shown in,

9
10 FIGURE 1.5 Stirred heating tank.
11
12 To develop the model for stirred heating tank based on the following assumptions:
13  the temperature is uniform throughout the tank.
14  The temperature of the outflow liquid is the same temperature in the tank (T).
15  The (), (Cp) and () of steam vary negligibly with temperature.
16  the heat given up by the steam through condensation is completely received by the tank.
17  Heat losses from the process to the atmosphere are negligible.
18
19 The overall mass balance is:

20
21 Equation (1.19) can also be derived using Equation (1.8). Since the volumetric flow rates of
22 inlet and outlet streams are equal (F), Equation (1.19) implies that the volume of liquid mixture
23 in the tank (V) remained constant.
24 The energy balance from the conservation of energy (Equation (1.4)) provides:

25
Mathematical Modeling: Introduction 11 / 25

2
3 Rate of energy input =  F Cp (Ti – Tref) + Q
4 Rate of energy output =  F Cp (T – Tref)
5
6 Tref is the reference temperature, Q the steam flow rate and Ti the inlet liquid temperature.
7 Substitution of all the above terms into Equation (1.20) yields:

8
9 After simplification,

10
11 V/F is the residence time. This model is generally described by ODEs that is a lumped
12 parameter model it is represents the variation of temperature T with a single independent
13 variable, time t.
14
15 ii) Distributed Parameter Model
16 Distributed parameter model When the variables of a process vary with both spatial position
17 ‫الموقع المكاني‬and time, such a process is referred to a s distributed parameter system. There is
18 more than one independent variable, and the observed process variations are distributed among
19 them. This model typically takes the form of PDEs so that the additional variation with spatial
20 position be accounted for properly.
21
22 Example: Consider a counter flow shell-and-tube heat exchanger. The model is a distributed
23 parameter model because the temperature of the liquid stream can change along the length of
24 the heat exchanger and also with time.
Mathematical Modeling: Introduction 12 / 25

1
2 The following assumptions are used to build the heat exchanger model:
3  The liquid within the element is assumed at a uniform temperature T, but the
4 temperature at the boundaries of the element are and .
5  The temperature does not change along the radius of the tube.
6  Physical properties are assumed constant.
7  The average velocity of the liquid (v) is assumed constant.
8  The shell-side steam is assumed to be at a constant temperature Tst.
9  The dynamics of the tube and shell walls are negligibly small.
10
11 By Equation (1.20) becomes:
12 [Accumulation of energy] = [Input of energy] – [Output of energy] (1.23)
13
14 𝐸𝑛𝑒𝑟𝑔𝑦 𝑎𝑐𝑐𝑢𝑚𝑢𝑙𝑎𝑡𝑒𝑑 = 𝜌 𝐶𝑃 𝐴 𝛥𝑍 𝛥𝑇
15 Energy input during the time period Δt

16
17 Energy out during the time period Δt

18
19 Q is the rate of heat transferred from the shell-side steam to the tube-side liquid,
20 D the external diameter of the tube,
21 A the cross-sectional area of the tube.
22 Inserting the above terms into Equation (1.23), we obtain
Mathematical Modeling: Introduction 13 / 25

1
2 Rearranging, we have

3
4 Dividing both sides of the above equation by Δt ΔZ and then assuming Δt = 0 and ΔZ = 0, we
5 finally get

6
7 where
8 Q = U ( Tst – T) (1.27)
9 U is the overall heat transfer coefficient between the steam and the liquid. The PDE (1.26)
10 represents a distributed parameter model because the liquid temperature T varies with two
11 independent variables, time t and length Z.
12
13 Example: consider the equilibrium stage concept of distillation. We usually assume that the
14 entire stage acts as a whole, and we do not consider variations in temperature, composition, or
15 pressure in various parts of the stage. All of these variables are “lumped” together into some
16 overall average. The errors introduced are compensated for by the stage efficiency factor.

17
18 Figure 2.1. Lumped-parameter and distributed-parameter visualization of a distillation tray.
19 (a) Actual plate with complex flow patterns and resulting variations in properties from point to
20 point. (b) Idealized equilibrium stage ignoring all internal variations.
21
Mathematical Modeling: Introduction 14 / 25

1 4. Mathematical Model vs. Empirical Model


2 A Mathematical Model are based on physical–chemical relationships. Actually, these models
3 are derived by applying the conservation principle and may also include transport phenomena,
4 reaction kinetics, and thermodynamic (e.g. phase equilibrium) relationships.
5
6 An Empirical Model is generally developed to use when the actual process is too complex and
7 the underlying phenomena are not well understood or when the numerical solution of the
8 Mathematical model is quite difficult or when the empirical model provides satisfactory
9 predictions of the process characteristics. Experimental plant data are used to develop a
10 relationship between the process input and process output as an empirical model using a
11 mathematical framework such as artificial neural network, least square method, etc.
12
13 A hybrid model is combining the Mathematical and empirical models, thus utilizing the
14 benefits of both. As an example, the mixed modelling techniques have been used to model the
15 polymerization reactors. The mass balance equations for the reactants are developed within the
16 Mathematical modelling approach, whereas the unknown rates of the reactions taking place are
17 modelled within the empirical approach.
18
19 5. Continuous versus Discrete Variables
20 Continuous variables: the variables can assume any
21 values within an interval;
22 Discrete variables: a variable can take on only distinct
23 values within an interval.
24 For example, concentrations in a countercurrent packed
25 bed column absorber are usually modeled in terms of
26 continuous variables, whereas plate absorbers are modeled
27 in terms of staged multicompartment models in which a
28 concentration is uniform at each stage but differs from
29 stage to stage in discrete jumps. Continuous and discrete
30 models are described by differential equations (DEs).
Mathematical Modeling: Introduction 15 / 25

1 Fourth Lecture
2
3 6. Interpolation versus Extrapolation
4 A model based on interpolation implies that the model
5 is fitted to experimentally determined values at different
6 points and that the model is used to interpolate between
7 these points.
8
9 A model used for extrapolation, goes beyond the range
10 of experimental data. Extrapolation requires, in general,
11 a detailed mechanistic understanding of the system. The
12 procedure requires great care to avoid misleading
13 conclusions.
14
15 Illustrates an exaggerated ‫ مبالغة‬case of extrapolation by
16 means of a linear model into a region beyond the range
17 of experimental data for a chemical reaction that reaches
18 a maximum yield in time.
19

20 1.2 Classification Based on Mathematical Complexity‫التصنيف يعتمد على التعقيد الرايضي‬

21 A mathematical process model usually consists of three types of equations:


22 1. Algebraic equations (AEs)
23 2. Ordinary differential equations (ODEs)
24 3. Partial differential equations (PDEs)
25
26 AEs are usually easier to solve than ODEs, which in turn are usually easier to solve than PDEs.
27 Follow the schematic diagram of the tank as shown in Figure 1.1. The mass balance equation
28 is given in Equation (1.9):

29
30 Substitution of AE in the ODE yields:
31
Mathematical Modeling: Introduction 16 / 25

1 The theory of ODEs is reasonably well advanced with regard to analytical solutions, but the
2 same is not true for the theory of PDEs. Thus, we can rather seldom find the analytical solution
3 to a PDEs.
4
5 2. Classification scheme is shown in Figure 2.4.

7
8 Figure 2.4. Classification based on mathematical complexity.
9
10 3. Classification of models based on scale
11 Table 2.1 shows the various classes of mathematical equations and the limited class amenable
12 to analytical solution. A model with more than one equation, the difficulty in obtaining a
13 solution is dependent on the degree of coupling. The analytical methods have its counterpart
14 for numerical methods. In such a case, the borderline to difficult/impossible problems is
15 shifted to the right. In most cases, the models need to be solved numerically. Some reasons for
Mathematical Modeling: Introduction 17 / 25

1 this might be non-linearities, varying material properties, and varying boundary conditions.
2
3 Table 2.1. Classification of models according to scale

4
5
6 1.3 Classification based on scale (degree of physical detail)
7 Models are classified based on the degree of internal detail of the system encompassed.

Scale Topical designations ‫المسميات‬ Parameters


Molecular treats discrete entities; quantum distribution functions; collision
mechanics, statistical mechanics, integrals
kinetic theory
Microscopic Laminar transport phenomena, phenomenological coefficients;
Statistical theories of turbulence viscosity, thermal conductivity,
diffusivity
Mesoscopic laminar and turbulent transport “effective” transport coefficients
phenomena;
transport in porous media
Macroscopic Process Engineering, Unit Operations Interphase Transport Coefficients
8
9 1. Molecular description
10 A molecular description is distinguished by the fact that it treats an arbitrary system as if it were
11 composed of individual entities, each of which obeys certain rules. Quantum mechanics,
12 equilibrium and non-equilibrium statistical mechanics. Classical mechanics are typical methods
13 of analysis, by which the properties and responses of the system can be calculated.
14
15 2. Microscopic description
16 A microscopic description assumes that a process acts as a continuum and that the mass,
17 momentum, and energy balances can be written in the form of phenomenological equations.
18 This is the “usual” level of transport phenomena where detailed molecular interactions are
Mathematical Modeling: Introduction 18 / 25

1 ignored and differential balance equations are formulated for momentum, energy, and mass.
2 The continuum concept is illustrated with the density of a fluid, ρ, at a particular point in the
3 fluid, as

4
5 Δm is the mass contained in a volume ΔV,
6 Vr is the elementary volume surrounding the
7 point.
8 The density may vary from point to point in a
9 fluid and may also vary with respect to time.
10
11 3. Mesoscopic description
12 mesoscopic involves averaging at higher levels and thus incorporates less detailed information
13 about the internal features of the system of interest. This level is of particular interest for
14 processes involving turbulent flow or flow in geometrically complex systems on a fine scale,
15 such as porous media. The values of the dependent variables are averaged in time (turbulence)
16 or space (porous media). Processes at this level are described by “effective” transport
17 coefficients such as eddy viscosity (turbulence) or permeability (porous media).
18 The continuum concept at the porous media level is illustrated in Figure 2.5(b) for porosity:

19
20 Where ΔVv is the void volume in ΔV, and d is the pore length scale.
21
22 The instantaneous velocity vz oscillates irregularly. We define the time-smoothed velocity vz by
23 taking a time average of over a time interval t0, which is large with respect to the time
24 of turbulent oscillation but small with respect to the overall time

25
26 4. Macroscopic description
27 Macroscopic ignores all the details within a system and merely creates a balance equation for
28 the entire system. The dependent variables, such as concentration and temperature, are not
29 functions of position, but represent overall averages throughout the volume of the system. The
30 model is effective as long as detailed information internal to the system is not required in model
31 building. Macroscopic and lumped mean the same thing.
Mathematical Modeling: Introduction 19 / 25

1 Questions [1]
2 1. What is the difference between a lumped and a distributed-parameter model?
3 2. Explain the difference between deterministic and stochastic models.
4 3. Why is a linear mathematical model tractable for analytical solution?
5 4. Describe the continuum concept.
6 5. At what scale is Darcy’s law formulated? Are there alternatives that describe flow in porous
7 materials?
8
9 Problem [2]
10 1.1 Keenan and Keyes (1959) proposed the following boiling relation for water [pressure (P)
11 in atm and temperature (T) in K]:

12 (1.28)

13 Where x = 647.27 – T.
14 Is it a linear/nonlinear relation? Why? Verify the relation with the help of steam table data.
15 1.2 What is the key difference between the independent variable and the dependent variable?
16 1.3 Write the general forms of mass, energy and momentum balance equations based on the
17 conservation law.
18 1.4 When is a system at steady state?
19 1.5 What is the difference between the state variable and the output variable of a process?
20 1.6 What do you mean by a differential–algebraic equation (DAE) system?
21 1.7 What is the main difference between the lumped parameter model and the distributed
22 parameter model?
23 1.8 Is it possible to obtain the steady state model from the given dynamic model of a
24 process? If yes, how?
25 1.9 It is well-known that the distillation column is a unit operation. Sometimes, the distillation
26 column is also called as distillation system. How can you explain it?
27 1.10 Consider a perfectly insulated, well-stirred
28 tank, as shown in Figure, where a hot liquid stream
29 at 75 °C is mixed with a cold liquid stream at 15
30 °C. Is it a lumped parameter system or a distributed
31 parameter system? Explain why.
32
Mathematical Modeling: Introduction 20 / 25

1 1.11 Consider a conical receiver shown


2 in Figure 1.8. The inlet and outlet liquid
3 volumetric flow rates are F1 and F2,

4 respectively.
5
6 (i) Develop the model equation with
7 necessary assumption(s) with respect to
8 the liquid height h. (ii) What type of
9 mathematical model is this?

Hint: Model:
10

Where the volume since


11

12 Substitute V and F2 expressions and get the final form.


13
14 1.13 Consider a liquid level
15 system as shown in Figure.
16 Derive the mathematical
17 model. What type of model is
18 it? Why?
19
20 1.12 Derive the dynamic mass balance equations for the following two simple cases. Assume
21 (i) a linear relationship between liquid level and flow rate through the outlet valve,
22 (ii) Constant liquid density.
23
24

25
Chapter 4

Initial Value Problems

F[
Consider two simultaneous differential equations \ and F\  [ . The analytical solution
FZ FZ
of the differential equations is y = A sin(x + a) and z = A cos(x + a). There are two constants
of integration A and a. In general, a system of N first order equations has N constants of
integration. If the values of the dependent variables y and z are specified for a value of x, then
the problem of determining the values of y and z at some future x is called an initial value
problem. Alternatively, the values of some of the dependent variables may be specified at a
number of different values of x, then the problem is called a boundary value problem. The
most common form is a two-point boundary value problem where the function values are given
for two values of x. Boundary value problems are discussed in Chapters 5–10.
The examples discussed here include the calculation of temperature profile in a double
pipe heat exchanger, of a single stirred tank with coil heater and also of a series of stirred tanks
with coil heater. The velocity profile of a solid particle in a pneumatic conveyor, and the
calculation of the concentration profile in the batch, stirred and plug flow reactors is also
discussed in this chapter.

4.1 Solution of Single Ordinary Differential Equation


Consider an ordinary differential equation
F[
H Z [ (4.1)
FZ
with the initial condition: at x = x0, y = y0. The ordinary differential equation has to be
integrated to determine the value of y at some x. A step size, h, is chosen in the independent
variable. At the initial condition both x and y are known and after a step size in independent
variable, i.e. at x = x0 + h the value of y is computed. Then this becomes the starting point
for the next value of independent variable, x = x0 + 2h at which the value of dependent variable
is determined. This procedure is repeated till the value of x at which the y-value is to be
determined is reached. For each problem there exists an optimum step size. The step size
should not be high, otherwise the truncation errors will be high, and if the step size is very
small, then round-off errors are high. At the optimum step size the total error (truncation error
+ round-off error) is the least, and thus the numerical results are accurate.
53
54 Introduction to Numerical Methods in Chemical Engineering

In the numerical formulation of the problem some terms are left out; those errors are
called truncation errors. When the step size is small, these errors are less. If the step size is
very low, then the truncation errors are less but the round-off errors are high. Consider a step
size of 10–6 m; then to go from 1 to 10 m, the number of iterations required is 107, which is
huge. Whenever the new concentration is computed, the number is not completely stored, it
is stored up to some decimal places only, depending on the compiler used. So to avoid round-
off errors the step size should not be very small and to avoid truncation errors it should not
be very large. So there is an optimum step size and it varies with the problem. To determine
the optimum step size, at a particular value of independent variable x the value of the
dependent variable y is determined using various step sizes. When for two consecutive step
sizes the value of y is the same, then the higher of the two is the optimum step size.
In the Runge–Kutta fourth order method the following are computed:
M J u H Z  [ (4.2)

§   ·
M J u H ¨ Z  J [  M ¸ (4.3)
©   ¹
§   ·
M J u H ¨ Z  J [  M ¸ (4.4)
©   ¹
M J u H Z  J [  M (4.5)

[ [  M   M   M  M (4.6)

From the initial condition (x0, y0) we have determined the value of y at x0 + h. Now again the
above calculations are carried out to determine the value of y at x0 + 2h. But before carrying
out the next calculation the following statements, due to which the value of y1 becomes y0 and
x0 + h becomes x0, are executed:
x0 = x0 + h (4.7)
y0 = y1 (4.8)

EXAMPLE 4.1 Integrate the ordinary differential equation


F[
Z[
FZ
using the Runge–Kutta fourth order method. The initial condition is: at x = 0, y = 0. Determine
the value of y at x = 0.2. The analytical solution is given by y = ex – x – 1.
F[
Solution Let us take step size of h = Dx = 0.1. The function is H Z  [ . To compute
FZ
y at x = 0.1 the starting point is x0 = 0 and y0 = 0. The calculations are given below.
f (0,0) = 0; therefore k1 = 0.1 ´ f(0,0) = 0;
f (0.05,0) = 0.05; therefore k2 = 0.1 ´ 0.05 = 0.005;
f (0.05,0.0025) = 0.0525; therefore k3 = 0.00525;
f (0.1,0.00525) = 0.10525; therefore k4 = 0.010525.
Initial Value Problems 55

Thus

[ M   M  M  M 
[  at x = 0.1

Now let us compute the value of y at x = 0.2. For this computation the starting point is
x0 = 0.1 and y0 = 0.0051708. The calculations are given below.
f(0.1, 0.0051708) = 0.1051708; therefore k1 = 0.01051708;
f(0.15, 0.01042934) = 0.16042934; therefore k2 = 0.0160429;
f(0.15, 0.01319225) = 0.16319225; therefore k3 = 0.016319225;
f(0.2, 0.02149) = 0.22149; therefore k4 = 0.022149.
Thus

[      u    u    

Thus the value of y (at x = 0.2) = 0.0214025.
The analytical solution at x = 0.2 is y = e0.2 – 0.2 – 1 = 0.0214028, which is close to the
numerical solution.

EXAMPLE 4.2 Solve the following ordinary differential equation:

dy y

dx 1 x
with the initial condition y(0) = 2. Determine y at x = 2.5 using the fourth-order Runge–Kutta
method.
Solution The initial condition is: at x = 0: y = 2. We have to determine y at x = 2.5. The result
from Program 4.1 (given in the Appendix) at step size of 0.01 is: at x = 2.5, y = 0.57.

4.2 Double Pipe Heat Exchanger


The schematic diagram of the inner pipe of the double pipe heat exchanger is shown in Fig. 4.1.
The outer pipe contains steam at temperature TS and the fluid in the inner pipe is heated.

 2
6\  6TGH
O%  2
6\  '\  6TGH
O%

Heat entering through whole


circumference = U(2pRDz)(TS – T)
Fig. 4.1 Schematic diagram of double pipe heat exchanger.
56 Introduction to Numerical Methods in Chemical Engineering

Consider a differential section of the inner pipe. Through the circumference of the inner pipe
heat enters from steam in the outer pipe. Under steady conditions (Input – Output = 0)
 2 6\  6TGH  O%
O%  2 6\  '\  6TGH  7Q & '\ 65  6 
Dividing by Dz, we get
§6  6\ ·
 2 ¨ \  '\
 O% ¸  7Q & 65  6 
© '\ ¹
As Dz ® 0, we get
F6
 2
 O%  7Q & 65  6  (4.9)
F\
where T is the temperature of the fluid in the inner pipe and is a function of length, TS is the
temperature of steam in the outer pipe and is constant, and O is the mass flow rate of fluid in
inner pipe. The analysis of the double pipe heat exchanger is described in the example below.

EXAMPLE 4.3 On one side of a double pipe heat exchanger is saturated steam and water
is flowing in the inner tube. The temperature of entering water is 20°C and the velocity of
water is 1 m/s. The inner diameter of the inner pipe is 2.4 cm. Under steady conditions,
determine the temperature of water at the length of 5 and 10 m from the inlet. The total length
of the heat exchanger is 10 m. Assume that the temperature does not change along the radius
of the pipe. The density of water is 1000 kg/m3 and the specific heat capacity is 4184 J/kg-
K. The overall heat transfer coefficient based on the inside area of the inner pipe is 200 W/
m2-K and the temperature of saturated steam is 250°C.

Solution The mass flow rate of water is



§  ·
O S X#  u  u Q ¨ ¸  kg/s
©  ¹
Eq. (4.9) becomes
F6
 u    u  u  u   6 
F\
F6
 u     6
F\
The initial condition is: at z = 0, T = 20. The temperature is to be determined at z = 5 and
z = 10. The differential equation is integrated using the Runge–Kutta fourth order method.
Program 4.1 can be modified, and with step size of 0.01 m, we get at z = 5 m, T = 28.97°C
and at z = 10 m, T = 37.60°C.
Let us now check the answer. The exit temperature of water at z = 10 m is 37.60°C. The
heat taken up by water is equal to UADTlmtd, and from the energy balance equation we get

7 Q &. '6 NOVF


 2
6  6
O%  
Initial Value Problems 57

where T1 is the temperature of the inlet water, T2 is the temperature of the exit water, and
L = 10 m. The temperatures in the double pipe heat exchanger are shown in Fig. 4.2.

250°C 250°C
Steam temperature

20°C 37.60°C
Water temperature
Fig. 4.2 Diagram for Example 4.3.

The log mean temperature difference is given by


  
'6 
§  ·
NOVF

NP ¨ ¸
©  ¹
Substituting the values in the energy balance equation, we get
 2
6  6
O%  u  u 
7  W/m2-K
Q &. '6NOVF Q u  u  u 
which is close to the given value. In this problem the overall heat transfer coefficient is given
and temperature of water is determined. Usually in heat transfer laboratory experiments, the
exit temperature of water is known and the overall heat transfer coefficient is determined.

4.3 Stirred Tank with Coil Heater


The schematic diagram of a stirred tank with coil heater is shown in Fig. 4.3.

O O

M = Mass
of fluid
in tank

TS

Fig. 4.3 Schematic diagram of stirred tank with coil heater.


58 Introduction to Numerical Methods in Chemical Engineering

The energy balance equation is given by Accumulation = Input – Output. The input is due to
energy input by the entering stream and the heat input from the steam, and the output is energy
carried away by the exit stream. From the energy balance equation, we get
F6
/% 2  2 6  6  3
O% (4.10)
FV
where T1 is the temperature of the entering stream and T is the temperature of exit stream and
is equal to temperature of water in the stirred tank. The heat transfer between the steam in the
coil and the fluid is given by Q = UADTlmtd = UA(TS – T). The temperature throughout the coil
is TS as the steam is saturated, and outside the whole coil, that is inside the tank uniform
temperature, T exists as the vessel is stirred; therefore DTlmtd = TS – T. Note that though the
temperature in the tank is uniform, it varies with time.

EXAMPLE 4.4 Consider a stirred tank heater. It is a square tank 0.5 m on its sides and 2
m high and is filled with water at 20°C. Water is fed to the tank at a flow rate of 1L/s and
exits out at the same flow rate from the top of the tank. The temperature of inlet water is 20°C.
At time t = 0 s, water in the tank is heated by a coil containing steam whose overall heat
transfer coefficient based on the outside area of the coil is 200 W/m2-K. The outside area of
the coil through which heat exchange takes place is 1 m2. The temperature of the steam is
250°C. The specific heat capacity of water is 4184 J/kg-K. After how much time is the
temperature of exit water 28°C? What is the maximum temperature that can be reached in the
tank?

Solution Volume of tank = 0.5 ´ 0.5 ´ 2 = 0.5 m3. Since the density of water is 1000 kg/m3,
therefore the mass of water in the tank is 500 kg. Thus M = 500 kg, CP = 4184 J/kg-K,
3 = UA(TS – T) = 200(TS – T), and m  = 1 kg/s, and Eq. (4.10) becomes
F6
 u   u  u   6   u   6
FV
Simplifying, we get
F6
  6
FV
The initial condition is: at t = 0, T = 20°C. We have to determine t at T = 28°C. Program 4.1 can
be modified, and with step size of 0.1 we get T = 28°C at t = 700 s. The variation of
temperature of the fluid in the tank with time is shown in Table 4.1.

Table 4.1 Variation of fluid temperature in tank with time in Example 4.4

Time (s) Temperature (°C)


500 26.81
750 28.31
1000 29.19
3000 30.46
5000 30.48
Initial Value Problems 59

F6
The steady state temperature is obtained when in the differential equation  ; thus
FV
the steady state temperature is given by 0.064 – 0.0021 T = 0 or T = 30.48°C. The same is
also obtained from the numerical solution. Note the temperature at 5000 s in Table 4.1.

EXAMPLE 4.5 Consider a stirred vessel which initially contains 760 kg of solvent at 25°C.
12 kg/min of solvent flows into the stirred vessel at 25°C and exits out also at the same rate.
At t = 0 the flow of steam is started in a coil in the stirred vessel. The heat supplied by steam
to the solvent is given by 3 = UA(TS – T), where UA is the overall heat transfer coefficient
multiplied by coil area through which heat exchange takes place and TS is the temperature of
steam and is 150°C. UA = 11.5 kJ/min-K. The specific heat of the solvent is Cp = 2.3 kJ/kg-
K. Show that
F6 Q

%U   6
FV
Determine the solvent temperature after 50 min. Also determine the maximum temperature that
can be reached in the tank.

Solution From the energy balance equation we know: Accumulation = Input – Output. Here
input energy is due to incoming fluid and steam and output is due to outgoing fluid.
Substituting the values in Eq. (4.10), we get
F6  
 u  u    6    6
FV  
Note that DTlmtd = TS – T, where T is the temperature of the fluid in the stirred tank. In the
coil throughout the temperature is TS and the fluid temperature is T. Simplifying the above
equation, we get
F6
   6
FV
The initial condition is: at t = 0, T = 25°C. We have to determine T at t = 3000 s.
Program 4.1 can be modified, and with step size of 0.01 we get: at t = 3000 s, T = 49.69°C.
The variation of temperature of the fluid in the tank with time is shown in Table 4.2.

Table 4.2 Variation of fluid temperature in tank with time in Example 4.5

Time (s) Temperature (oC)

1000 36.41
2000 44.27
3000 49.69
5000 55.98
7500 59.43
10000 60.78
15000 61.53
20000 61.64
25000 61.66
60 Introduction to Numerical Methods in Chemical Engineering

F6
The steady state temperature is obtained when in the differential equation,  , thus the
FV
steady state temperature is given by 0.023 – 0.000373T = 0 or T = 61.66°C. The same is also
obtained from the numerical solution. Note the temperature at 25000 s in Table 4.2.

4.4 Pneumatic Conveying


Consider a pneumatic conveyor in which solids are inserted from the bottom along with the
flowing gas. The forces acting on the particle are: drag force acting upwards, buoyancy force
acting upwards and gravitational force acting downwards. The momentum balance equation
becomes [see Eq. (2.15)]
FX R (&  (D  (I
SR
FV 8R
where rp is the density of the particle, vp is the upward velocity of the particle, FD is the drag
force acting on the particle, Fb is the buoyancy force acting on the particle, Fg is the
gravitational force acting on the particle, and Vp is the volume of the particle. The drag force
is given by
(& #R
%&

SI XI  X R
 (4.11)

where rg is the density of the gas, Ap is the projected area of the particle on a plane at right
angles to the direction of motion, and vg – vp is the relative velocity. The gravitational force
minus the buoyancy force on the particle is given by [see Eq. (2.17)]
(I  (D 8R S R  S I I
The various forces acting are shown in Figure 4.4.

 #R
S I%& X  X
X  X
 8R I R I R

(rp – rg)g

vg

Fig. 4.4 Various forces (divided by volume of particle) acting on particle during pneumatic
conveying.
Initial Value Problems 61

Thus the momentum balance equation becomes


FX R  #R
XI  X R  S I  S R I

SR %& S I (4.12)
FV  8R
Note that the terms have units of force acting on the particle divided by the volume of the
particle. Dividing both sides of the equation by rp, we get
FX R  S I #R § SI ·
XI  X R  ¨

%&  ¸ I
FV  S R 8R ¨ SR ¸
© ¹
The derivative
FX R FX R
XR
FV F\
where z is the direction along the length of the pneumatic conveyor. Thus the momentum
balance equation can be written as
FX R  SI #R § SI ·
XI  X R  ¨

XR %&  ¸ I (4.13)
S R 8R ¨ ¸
F\  © SR ¹
Program 4.2 uses the Runge–Kutta fourth order method for integrating the above ordinary
differential equation and is given in the Appendix.

EXAMPLE 4.6 Determine the velocity of the solid particles of diameter 3 ´ 10–4 m along
the length of the pneumatic conveyor. The initial velocity of the particle is zero and superficial
velocity of air is 12 m/s. The density of the particle is 900 kg/m3. Air is fed at 25°C and 1
atm and the viscosity of air under these conditions is 1.8 ´ 10–5 kg/m-s. Neglect wall effects.
Use the following relation to determine CD:

%&
4G R

  4G 
R
where Rep is the particle Reynolds number based on relative velocity and is given by
SI XI  X R F R
4G R
N
Solution The following data are given:
dp = 3 ´ 10–4 m
vg = 12 m/s
m = 1.8 ´ 10–5 kg/m-s.
The density of air under the given conditions is given by
2/  u  u  
SI  kg/m3
46  u 
62 Introduction to Numerical Methods in Chemical Engineering

The projected area of the particle divided by the volume of the particle is given by

#R Q TR    –1


 m
  8R
Q TR TR FR  u  

The particle Reynolds number is
SI XI  X R F R  u   X R u  u  
4G R    X R
N  u  
The momentum balance equation is
FX R  SI #R § SI ·
XI  X R  ¨

XR %&  ¸ I
F\  S R 8R ¨S ¸
© R ¹

FX R   §  ·


  X R  ¨

XR %&   ¸ 
F\   ©  ¹

 FX R
%&   X R  


 F\
Let [ X R ; thus

F[


%&   [  
F\

where 4G R
   [ and %&

4G R

  4G 
R
. The initial condition is at

z = 0, y = 0. The problem can be solved using the Runge–Kutta fourth order method. The
velocity of the particle along the length of the pneumatic conveyor as obtained from
Program 4.2 is presented in Table 4.3. The step size of 0.01 m is taken.

Table 4.3 Velocity of particle as obtained from Program 4.2

z (m) vp (m/s)
0.0 0.00
0.1 5.84
0.2 7.24
0.3 8.06
0.5 9.01
1.0 10.06
2.0 10.67
3.0 10.83
5.0 10.90
10.0 10.90
Initial Value Problems 63

4.5 Solution of Simultaneous Ordinary Differential Equations


Consider a system of two ordinary differential equations
F[
H Z [ \ (4.14)
FZ
F\
H  Z  [ \ (4.15)
FZ
with the initial condition: at x = x0, y = y0 and z = z0. The ordinary differential equations have
to be integrated to determine the value of y and z at some x. A step size, h, is chosen in the
independent variable and after a step size in independent variable, i.e., at x = x0 + h the value
of y and z are to be computed. In the Runge–Kutta fourth order method the following are
computed:
M J u H Z  [  \ (4.16)
N J u H Z  [  \ (4.17)

§    ·
M J u H ¨ Z  J [  M  \  N ¸ (4.18)
©    ¹

§    ·
N J u H ¨ Z  J [  M  \  N ¸ (4.19)
©    ¹
§    ·
M J u H ¨ Z  J [  M  \  N ¸ (4.20)
©    ¹
§    ·
N J u H ¨ Z  J [  M  \  N ¸ (4.21)
©    ¹
M J u H Z  J [  M  \  N (4.22)
N J u H Z  J [  M  \  N (4.23)

[ [  M   M   M  M (4.24)


\ \  N  N  N  N (4.25)

From the initial condition (x0, y0, z0), we have determined the value of y and z at x0 + h. Now
again, the above calculations are carried out to determine the value of y and z at x0 + 2h. But
before carrying out the next calculation the following statements are executed, due to which
the value of y1 becomes y0, z1 becomes z0 and x0 + h becomes x0:
x0 = x0 + h
y0 = y1
z0 = z1
64 Introduction to Numerical Methods in Chemical Engineering

EXAMPLE 4.7 Integrate the ordinary differential equations


dx
x  2y
dt
dy
3x  2 y
dt
using the Runge–Kutta fourth order method. The initial condition is: at t = 0, x = 6, y = 4.
Determine the values of x and y at t = 0.2. The analytical solution is given by x = 4e4t + 2e–t
and y = 6e4t – 2e–t.
FZ
Solution Take step size of h = Dt = 0.1. The functions are H Z   [ and
FV
F[
H  Z   [ . To compute the value at t = 0.1 the starting point is t0 = 0, x0 = 6 and y0
FV
= 4. The calculations are given below.
f1(0, 6, 4) = 14; therefore k1 = 1.4;
f2(0, 6, 4) = 26; therefore l1 = 2.6;
f1(0.05, 6.7, 5.3) = 17.3; therefore k2 = 1.73;
f2(0.05, 6.7, 5.3) = 30.7; therefore l1 = 3.07;
f1(0.05, 6.865, 5.535) = 17.935; therefore k3 = 1.7935;
f2(0.05, 6.865, 5.535) = 31.665; therefore l3 = 3.1665;
f1(0.1, 7.7935, 7.1665) = 22.1265; therefore k4 = 2.21265;
f2(0.1, 7.7935, 7.1665) = 37.7135; therefore l4 = 3.77135.
Thus

Z Z  M   M  M  M  (at t = 0.1)


[ N  N  N  N 
[  (at t = 0.1)

Now let us compute the value of y and z at t = 0.2. For this computation the starting point is
t0 = 0.1, x0 = 7.7766, and y0 = 7.140725. The calculations are given below.
f1(0.1, 7.7766, 7.140725) = 22.05805; therefore k1 = 2.205805;
f2(0.1, 7.7766, 7.140725) = 37.61125; therefore l1 = 3.761125;
f1(0.15, 8.8795, 9.0212875) = 26.922075; therefore k2 = 2.6922075;
f2(0.15, 8.8795, 9.0212875) = 44.681075; therefore l2 = 4.4681075;
f1(0.15, 9.12270375, 9.37477875) = 27.87226; therefore k3 = 2.787226;
f2(0.15, 9.12270375, 9.37477875) = 46.1176687; therefore l3 = 4.61176687;
f1(0.2, 10.563826, 11.75249187) = 34.06881; therefore k4 = 3.406881;
f2(0.2, 10.563826, 11.75249187) = 55.19646; therefore l4 = 5.519646.
Initial Value Problems 65

Thus at t = 0.2

Z      u    u    


[      u    u    

From the analytical solution at t = 0.2: x = 10.5396, y = 11.7158, which is close to the
numerical solution.

EXAMPLE 4.8 Solve the following ordinary differential equations:


F[
\
FZ
F\
[
FZ
with the initial condition y(0) = 2, z(0) = 1. Determine the value of y and z at x = 3. Compare
the numerical solution with the analytical solution. The analytical solution of the given
differential equations is y = Asin(x + a) and z = Acos(x + a).

Solution The two simultaneous ordinary differential equations can be written as


F[
H \
FZ
F\
H [
FZ
The initial condition is: at x = 0, y = 2, z = 1. We have to determine y and z at x = 3. The
result from Program 4.3 at step size of 0.01 is: at x = 3: y = –1.84, z = –1.27. Now let us check
the numerical result with the analytical solution. First let us determine the constants A and a.
At x = 0: y = 2, z = 1, and thus
2 = A sin(0 + a)
1 = A cos(0 + a)
Thus tan a = 2 or a = 63.435° and thus A = 2.236. From the conversion of radians to degrees
we know that 3.1416 radians = 180°. Thus x = 3 = 171.887°. At x = 3 the following is obtained:
y = 2.236 sin(171.887 + 63.435) = –1.84
z = 2.236 cos(171.887 + 63.435) = –1.27
which is the same as numerical solution.

EXAMPLE 4.9 Solve the following ordinary differential equation:


F [
 [Z
FZ 
with the initial conditions y(0) = 2, y¢(0) = 1. Determine the value of y at x = 3.
66 Introduction to Numerical Methods in Chemical Engineering

Solution Let us take


F[
\
FZ
Then the given differential equation can be written as

F\
 [Z
FZ
The two simultaneous differential equations can be written as

F[
H \
FZ

F\
H  [Z
FZ
The initial condition is at x = 0, y = 2, z = 1. We have to determine y at x = 3. Program 4.3
can be modified (only the functions func1 and func2 have to be changed) and with step size
of 0.01 we get at x = 3: y = –1.90, z = –1.15.

4.6 Series of Stirred Tanks with Coil Heater


The schematic diagram of a series of stirred tanks with coil heater is shown in Fig. 4.5. The mass
in each tank shall be assumed constant as the tank volume and density of oil are assumed
constant. The energy balance of tank 1 (accumulation = Input – Output) gives
F6
/% 2  2 6  6  7# 65  6
O%
FV
where M is the mass of oil in the tank and O is the flow rate of oil. T0 is the inlet temperature

O kg/s T1 T2 T3
T0

T1 T2 T3

Fig. 4.5 Schematic diagram of series of stirred tanks with coil heater.
Initial Value Problems 67

of the oil. T1, T2, and T3 are the temperatures of the first, second and third tank respectively.
TS is the temperature of steam. The energy balance of tank 2 gives
F6
/%2  2 6  6  7# 65  6
O%
FV
The energy balance of tank 3 gives
F6
/%2  2 6  6  7# 65  6
O%
FV
The analysis is described in the example below.

EXAMPLE 4.10 Three tanks in series are used to heat oil (see Fig. 4.5). Each tank is initially
filled with 1000 kg of oil at 20°C. Saturated steam at 250°C condenses within the coils
immersed in each tank. Oil is fed into the first tank at a rate of 2 kg/s and overflows into the
second and third tanks at the same flow rate. The temperature of the oil fed to the first tank
is 20°C. The tanks are well mixed so that the temperature inside the tanks is uniform and the
outlet stream temperature is the temperature within the tank. Cp of oil = 2000 J/kg-K. The rate
of heat transferred to the oil from the steam is given by 3 = UA(TS – T), where A is the outside
area of the coil in one tank, A = 1 m2 and the overall heat transfer coefficient is based on the
outside area of the coil, U = 200 W/m2-K. Determine the steady state temperature in all the
three tanks. What time interval is required for T3 to reach 99% of this steady state value?

Solution UA = 200 W/K. From the first differential equation we get


F6
 u   u    6     6
FV
F6
  6
FV
From the second differential equation we get

F6
 u   u  6  6     6
FV
F6
  6  6
FV
From the third differential equation we get

F6
 u   u  6  6     6
FV
F6
  6  6
FV
The initial condition is: at t = 0: T1 = T2 = T3 = 20°C. Program 4.4 for the solution of above
68 Introduction to Numerical Methods in Chemical Engineering

three ordinary differential equations by the Runge–Kutta fourth order method is given in the
Appendix. The results at step size of 0.1 is shown in Table 4.4.

Table 4.4 Results in Example 4.10.

Time (s) T1 (oC) T2 (oC) T3 (oC)


1000 29.61 36.08 39.56
2500 30.89 40.98 49.87
7500 30.95 41.38 51.31
15000 30.95 41.38 51.31
F6
The steady state temperature is obtained when in the differential equation  ; thus the
FV
steady state temperatures are given by

6  °C

 u   
6  °C

 u   
6  °C

The same steady state temperatures are also obtained from the numerical solution. Note
the temperature at 7500 s in Table 4.4. We are required to determine the time required
for temperature in tank 3 to reach 0.99 ´ 51.31 = 50.80°C. From Program 4.4 this time
is 3150 s.

4.7 Initial Value Problems in Chemical Reaction Engineering


Batch and plug flow reactors are initial value problems. The initial conditions and ordinary
differential equations for batch and plug flow reactors are shown in Table 4.5.

Table 4.5 Initial conditions and ODEs for batch and plug flow reactors

Initial ODE’s for Batch Reactor Initial ODEs for Plug Flow
Condition for Condition for Reactor
Batch Reactor Plug Flow
Reactor
# 
M
o$


F% # F% #
#VV   M% # #VZ  W  M% #
FV FZ
%#  %# 
F%$ F% $
%$  M% # %$  W M% #
FV FZ
Initial Value Problems 69

Table 4.5 (Cont.)


M M
#  o $  o%

#VV  F% # #VZ  F% #
M% # W  M% #
%#  FV %#  FZ
F%$ F%$
%$ %%  M% #  M%$ %$ %%  W M% #  M% $
FV FZ
F%% F%%
M%$ W M% $
FV FZ
#  $ 
M
o% 

$  % o &
M 

F% # F% #
#VV  M% #% $ #VZ  W  M% #%$
FV FZ
%# %$  %# %$  F% $
F%$ W  M% #%$  M%$%%
%% %&  M% #% $  M% $%% %% %& 
FV FZ
F%% F%%
M% #%$  M%$%% W M% #% $  M% $%%
FV FZ
F%& F% &
M%$%% W M% $%%
FV FZ

4.8 Batch and Stirred Tank Reactors


The solution of initial value problems in batch and stirred tank reactors is described with the
examples given below.

EXAMPLE 4.11 Consider a reaction A ® B carried out in a batch reactor. The differential
equation for species A is
F% #
 M% #
FV
The initial condition is: at t = 0, CA = 1 mol/m3. The rate constant of the reaction is 1 s–1. Using
the Runge–Kutta fourth order method, determine the concentration of A at 3 s.

Solution The differential equation is written in the form f = –kCA. Thereafter the following
are computed:
M J u H V  %
§   ·
M J u H ¨ V  J %  M ¸
©   ¹
§   ·
M J u H ¨ V   J %   M  ¸
©   ¹
70 Introduction to Numerical Methods in Chemical Engineering

M J u H V  J %  M

% %  M  M  M  M

V V  J
%  %
Program 4.1 can be modified and the results for step size of 0.01 s are presented in Table 4.6.

Table 4.6 Results in Example 4.11

t (s) CA (mol/m3) CA (mol/m3) = e–t


Numerical solution Analytical solution
0.0 1.000000 1.000000
1.0 0.367880 0.367879
2.0 0.135335 0.135335
3.0 0.049787 0.049787
5.0 0.006738 0.006738
10.0 0.000045 0.000045

EXAMPLE 4.12 A liquid phase reaction A ® B is carried out in a stirred vessel reactor. Feed
enters the reactor at a rate of F = 1 L/s and exits out also at the same flow rate. Both the
reactant and product have the same density. The concentration of reactant in the feed is CA0
= 1 mol/m3. The volume of the tank is V = 10 L and the concentration of A of the solution
in the tank is 1 mol/m3. The vessel may be considered perfectly mixed, so that the
concentration of A in the product stream equals that inside the tank. The rate of consumption
of A equals kCA, where k = 1 s–1. Determine the concentration of A at various time periods from
0 to 10 s.

Solution Mole balance on component A is given by


Accumulation = Input – Output – Consumption
Moles of A in the reactor = VCA
F 8% #
Accumulation =
FV
Input = FCA0
Output = FCA
Thus from the mole balance of component A, we get
F 8% #
(% #   (% #  M% #8
FV
Substituting the values we get
F % #
   % #  % #
FV
F% #
  % #
FV
Initial Value Problems 71

The initial condition is: at t = 0, CA = 1 mol/m3. Program 4.1 can be modified and at step size
of 0.01 the concentration of component A in the tank with time is shown in Table 4.7.

Table 4.7 Results in Example 4.12

Time (s) CA (mol/m3)


0.10 0.9053
0.25 0.7891
0.50 0.6212
1.0 0.3969
2.0 0.1927
3.0 0.1248
5.0 0.0947
10.0 0.0909

F% # 
At steady state,  ; thus % #  mol/m3. The same is also obtained from
FV 
numerical solution. Note the concentration at 10 s in the Table 4.7.

EXAMPLE 4.13 Consider reaction #  M M


o $  o % carried out in a batch reactor. The
differential equation for component A is

F% #
 M% #
FV
for component B
F% $
M% #  M %$
FV
for component C
F%%
M % $
FV
The initial condition is: at t = 0, CA = 1 mol/m3, CB = 0 mol/m3, and CC = 0 mol/m3. The rate
constants are k1 = 1 s–1 and k2 = 1 s–1. Using the Runge–Kutta fourth order method, determine
the concentration of A, B, and C up to 10 s.

Solution The differential equations are written in the form of functions


H  M #
H M #  M $
H M $
where A, B and C are the concentrations of the components A, B, and C, respectively. The
initial condition is at time t = t0, A = A0, B = B0, C = C0. Thereafter the concentrations are
computed at time t = t0 + h.
72 Introduction to Numerical Methods in Chemical Engineering

M J u H V  #  $  %
N J u H  V  #  $  %
O J u H V  #  $  %

§     ·
M J u H ¨ V  J #  M  $  N  %  O ¸
©     ¹
§     ·
N J u H  ¨ V  J #  M  $  N  %  O ¸
©     ¹
§     ·
O J u H ¨ V  J #  M  $  N  %  O ¸
©     ¹
§     ·
M J u H ¨ V  J #  M  $  N  %  O ¸
©     ¹
§     ·
N J u H  ¨ V  J #  M  $  N  %  O ¸
©     ¹
§     ·
O J u H ¨ V  J #  M  $  N  %  O ¸
©     ¹
M J u H V  J #  M  $  N  %  O
N J u H V  J #  M  $  N  %  O
O J u H V  J #  M  $  N  %  O

# #  M  M  M  M


$ $  N  N  N  N


% %  O  O  O  O

t 0 = t0 + h
A0 = A1
B0 = B1
C0 = C1
Program 4.5 for the solution of the above three simultaneous ordinary differential equations by
the Runge–Kutta fourth order method is given in the Appendix. The results for step size of 0.01
s are presented in Table 4.8.
Initial Value Problems 73

Table 4.8 Results in Example 4.13

t (s) CA (mol/m3) CB (mol/m3) CC (mol/m3)


0.0 1.000000 0.000000 0.000000
1.0 0.367880 0.367879 0.264241
2.0 0.135335 0.270671 0.593994
3.0 0.049787 0.149361 0.800852
4.0 0.018316 0.073263 0.908422
5.0 0.006738 0.033690 0.959573
10.0 0.000045 0.000454 0.999503

EXAMPLE 4.14 Consider the following two reactions taking place in a batch reactor:
M
#  $  o%
M
$  %  o&

The concentration of various species with time are given by the following differential
equations:
for component A
F% #
 M% #%$
FV
for component B
F% $
 M% #% $  M% $%%
FV
for component C
F%%
M% #%$  M%$%%
FV
for component D
F% &
M% $%%
FV
The initial conditions are: at t = 0, CA = 1 mol/m3, CB = 1 mol/m3, CC = 0 mol/m3, and CD
= 0 mol/m3. The rate constant of the reactions are k1 = k2 = 1 m3/mol-s. Using the Runge–Kutta
fourth order method determine the concentration of species A, B, C, and D up to 10 s.

Solution Program 4.6 for solution of the above four simultaneous ordinary differential
equations by the Runge–Kutta fourth order method is given in the Appendix. The results for
step size of 0.01 s are presented in Table 4.9.
74 Introduction to Numerical Methods in Chemical Engineering

Table 4.9 Results in Example 4.14

t (s) CA (mol/m3) CB (mol/m3) CC (mol/m3) CD (mol/m3)


0.0 1.000000 1.000000 0.000000 0.000000
1.0 0.528875 0.394646 0.336895 0.134230
2.0 0.404510 0.175134 0.366113 0.229376
3.0 0.357692 0.083121 0.367737 0.274571
4.0 0.337090 0.040733 0.366553 0.296357
5.0 0.327357 0.020275 0.365561 0.307082
10.0 0.318152 0.000659 0.364356 0.317492

4.9 Plug Flow Reactor


The solution of initial value problems in plug flow reactor is described with examples given
below.

EXAMPLE 4.15 Consider a reaction A ® B carried out in a plug flow reactor. The
differential equation for species A along the length of the plug flow reactor of length 10 m is
F% #
W  M% #
FZ
The initial condition is: at x = 0 (inlet), CA = 1 mol/m3.
A fluid medium comprising initially only A flows through the reactor with a mean axial
velocity u = 1 m/s. The rate constant of the reaction is 1 s–1. Using the Runge–Kutta fourth
order method, determine the concentration of A along the length of the plug flow reactor up
to 10 m.

Solution Program 4.1 can be modified and the results for step size of 0.01 m are presented
in Table 4.10.

Table 4.10 Results in Example 4.15

x (m) CA (mol/m3)
0.0 1.000000
1.0 0.367880
2.0 0.135335
3.0 0.049787
5.0 0.006738
10.0 0.000045

EXAMPLE 4.16 Consider a reaction #  M M


o $  o % carried out in a plug flow reactor.
The differential equation for component A is
F% #
W  M% #
FZ
Initial Value Problems 75

for component B
F%$
W M% #  M% $
FZ
for component C
F%%
W M% $
FZ
The initial condition is: at x = 0 (inlet), CA = 1 mol/m3, CB = 0 mol/m3, and CC = 0 mol/m3.
A fluid medium comprising initially only A flows through the reactor with a mean axial
velocity u = 1 m/s. The rate constants are: k1 = 1 s–1 and k2 = 1 s–1. Using the Runge–Kutta
fourth order method, determine the concentration of A, B, and C along the length of the plug
flow reactor up to 10 m.

Solution Program 4.5 can be modified (time replaced by distance along the length of the
tubular reactor) and the results for step size of 0.01 m are presented in Table 4.11.

Table 4.11 Results in Example 4.16

x (m) CA (mol/m3) CB (mol/m3) CC (mol/m3)


0.0 1.000000 0.000000 0.000000
1.0 0.371577 0.367861 0.260562
2.0 0.136695 0.272024 0.591281
3.0 0.050287 0.150359 0.799353
4.0 0.018500 0.073814 0.907686
5.0 0.006806 0.033960 0.959234
10.0 0.000046 0.000458 0.999496

EXAMPLE 4.17 Consider the following two reactions taking place in a plug flow reactor:
M
#  $  o%
M
$  %  o&
The concentration of various species with the length of the reactor are given by the following
differential equations:
for component A
F%
W #  M% #% $
FZ
for component B
F%
W $  M% #%$  M%$%%
FZ
for component C
F%
W % M% #%$  M%$%%
FZ
for component D
F%
W & M  % $ %%
FZ
76 Introduction to Numerical Methods in Chemical Engineering

The initial conditions are: at x = 0 (inlet), CA = 1 mol/m3, CB = 1 mol/m3, CC = 0 mol/m3, and


CD = 0 mol/m3.
The length of the plug flow reactor is 10 m. A fluid medium comprising initially only
A and B flows through the reactor with a mean axial velocity u = 1 m/s. The rate constant of
the reactions are k1 = k2 = 1 m3/mol-s. Using the Runge–Kutta fourth order method, determine
the concentration of species A, B, C, and D along the length of the plug flow reactor up to 10
m.

Solution Substituting k1 = k2 = 1 m3/mol-s and u = 1 m/s in the above ordinary differential


equations, we get
F% #
 % #% $
FZ
F% $
 % #% $  % $%%
FZ
F%%
% #%$  %$%%
FZ
F% &
% $ %%
FZ

Program 4.6 can be modified (time replaced by distance along the length of the tubular reactor)
and the results for step size of 0.01 m are presented in Table 4.12.

Table 4.12 Results in Example 4.17

x (m) CA (mol/m3) CB (mol/m3) CC (mol/m3) CD (mol/m3)


0.0 1.000000 1.000000 0.000000 0.000000
1.0 0.528875 0.394646 0.336895 0.134230
2.0 0.404510 0.175134 0.366113 0.229376
3.0 0.357692 0.083121 0.367737 0.274571
4.0 0.337090 0.040733 0.366553 0.296357
5.0 0.327357 0.020275 0.365561 0.307082
10.0 0.318152 0.000659 0.364356 0.317492

4.10 Nonisothermal Plug Flow Reactor


EXAMPLE 4.18 Consider the reaction A ® B carried out in a steam heated heat exchanger
reactor. Reactant A is fed at the rate of 1.26 kg/s per tube. The feed consisting of pure A enters
the reactor at a temperature of 21°C. It is desired to determine the height of reactor required
for 90% conversion of A. The internal diameter of the reactor tubes may be taken as 2.54 cm.
Steam at 388.71 K is available for heating purposes. The rate constant of the first order
Initial Value Problems 77

§  ·
reaction is given by M  Z GZR ¨  ¸ , where T is in Kelvin. Take the following
© 46 ¹
parameters: R = 8.314 J/mol-K, r = 980.9 kg/m3, molecular weight of reacting stream,
M = 200 g/mol, heat transfer coefficient based on inside area of reactor tube, U = 1900 W/

m2-K, Cp = 15.7 J/kg-K, '* TZP = 92.9 kJ/mol. Assume the heat of reaction to be independent
of temperature.
MP# MP#
Solution Since the reaction is first order, M% #   : , where F is the volumetric
( (

flow rate of reactant A and P# is the inlet molar flow rate of A. The rate constant of the reaction
can be written as
ª §  ·º
M M GZR «D ¨   ¸ »
¬ © G ¹¼
' 6
where D , G and M  u  GZR D .
46 6
T1 is a reference temperature and is taken to be the temperature of steam.
FP# F: P# F:
T#  P#
F8 F8 # F\

ª §  ·º
M GZR « D ¨   ¸ »   :
F: T# ¬ © G ¹¼
F8 P# (

From energy balance on reactants we get

F6
 2
O%  T# #'*   S 
F\
TZP

where q = Ua(TS – T) and a is the total area of heat transfer per unit length; thus a = pD (for
one tube). A is the cross-sectional area of the tube based on inside diameter. Thus the above
equation becomes

F6 7
 2
 O%  65  6  T# '*  
F8 &
TZP

MI  O  O
(   u  
U  MI U

' 
D 
46  u 

M  u  GZR D  u  GZR   S–1


78 Introduction to Numerical Methods in Chemical Engineering

ª §  ·º
#M   : GZR « ¨   ¸ »
F: ¬ © G ¹¼
F\ (

#M §  · 
Q¨ ¸ 
 m–1
( ©  ¹  u 
Thus
F: ª § 6 ·º
   : GZR « ¨    ¸ »
F\ ¬ © 6 ¹¼

MI , 9
 2
O%   
U MI  - -
a, A and U are all based on the internal diameter of tubes. The inlet molar flow rate of A is
given by
MI OQN OQN
P#  
U MI U
F6 7
 2
 O%  65  6  T# '*  
#F\ &
TZP

 F6  u 
  65  6  T# '*  
Q  F\ 
 TZP

ª §  ·º ª § 6 ·º
M P# GZR « D ¨   ¸ »   :  u GZR « ¨    ¸ »   :
¬ © G ¹¼ ¬ © 6 ¹¼
T# 
(  u 

ª § 6 ·º
T#    : GZR « ¨    ¸ »
¬ © 6 ¹¼

ª § 6 ·º

T# '* TZP  u    : GZR « ¨    ¸ »
¬ © 6 ¹¼

ª § 6 ·º

 u     : GZR « ¨    ¸ »
T# '* TZP
¬ © 6 ¹¼
Thus the energy balance equation becomes
F6 ª § 6 ·º
   65  6   u     : GZR « ¨    ¸ » 
F\ ¬ © 6 ¹¼
Initial Value Problems 79

Thus the two simultaneous ordinary differential equations are


F: ª §  · º
   : GZR « ¨   ¸
F\ ¬ © 6 ¹ »¼

F6 ª §  · º
   6     : GZR « ¨   ¸
F\ ¬ © 6 ¹ »¼
The initial condition is: at z = 0, X = 0 and T = 294.15 K.
Program 4.7 for the solution of the above two simultaneous ordinary differential equations by
Runge-Kutta fourth order method is given in the Appendix. The results for step size of 0.1 m
are presented in Table 4.13.

Table 4.13 Results in Example 4.18

z (m) X T
0.1 0.000026 343.87
0.2 0.000363 359.29
0.3 0.00094 361.51
0.4 0.0015 362.69
0.5 0.0015 362.69
1.0 0.005 364.87
2.0 0.011 365.35
3.0 0.017 365.40
5.0 0.029 365.49
10 0.059 365.71
15 0.088 365.93
20 0.118 366.16
25 0.147 366.40
30 0.176 366.64
35 0.204 366.89
40 0.232 367.14
45 0.260 367.39
50 0.287 367.66
100 0.542 370.65
150 0.752 374.56
200 0.903 379.76
250 0.980 385.59
300 0.998 388.33
350 0.999 388.68

Thus 90% conversion is achieved at a height of 200 m.


80 Introduction to Numerical Methods in Chemical Engineering

Exercises
4.1 Integrate the following ODEs using the Runge–Kutta fourth order method:
FZ
  Z   [
FV
F[
 Z  [  Z\
FV
F\
 \  Z[
FV
Initial condition at t = 0: x = y = z = 5. Determine x(20), y(20), z(20).
(Ans: x(20) = 6.76, y(20) = 12.61, z(20) = 10.96)
4.2 Consider the second order ordinary differential equation
F Z FZ

  Z 
FV FV
FZ
with the initial conditions x(0) = 3 and    . Compute x(5).
FZ FV F[
Hint: Take [ and thus the given ODE becomes   Z   [ . The two
FV FV
simultaneous differential equations can be solved using the Runge-Kutta fourth
order method by taking the following functions.
FZ
H [
FV
F[
H  Z   [
FV
Initial condition at t = 0: x = 3 and y = –5. Note that since the ordinary differential
equation is second order, therefore two conditions have to be given to completely
define the problem.
(Ans: x(5) = –4.9 ´ 10–6)
4.3 Consider the second order ordinary differential equation
F[ F[
 
 Z   [ 
FZ FZ
F[
with the initial conditions y(0) = 1 and   . Compute y(1).
FZ
F[ F\ Z  \   [ 
Hint: Take \ and thus the given ODE becomes . The two
FZ FZ 
simultaneous differential equations can be solved using the Runge–Kutta fourth
order method by taking the following functions:
Initial Value Problems 81

F[
\H
FZ
F\ Z  \   [ 
H
FZ 
Initial condition at x = 0: y = 1 and z = 0.
( Ans: y(1) = 0.8785)
4.4 Determine the velocity of the solid particles of diameter 0.0003 m in a pneumatic
conveyor at length of 10 m. The initial velocity of the particle is zero and
superficial velocity of air is 10 m/s. The density of the particle is 900 kg/m3. Air
is fed at 25°C and 1 atm and the viscosity of air under these conditions is 1.8 ´ 10–5 kg/
m-s. Neglect the wall effects. Use the following relation to determine CD:

%&
4G R

   4G 
R
where Re p is the particle Reynolds number based on relative velocity and is given
S I XI  X R F R
by 4G R .
N
(Ans: 8.9044 m/s)
4.5 Consider a reaction A ® B carried out in a batch reactor. The differential equation
for species A is
F% #
 M% #
FV
The initial condition is: at t = 0, CA = 1 mol/m3. The rate constant of the reaction
is 0.1 s–1. Using the Runge–Kutta fourth order method, determine the concentration
of A at 10 s.
(Ans: 0.36788 mol/m3)
4.6 Solve Exercise 4.5 for rate constant of the reaction of 0.01 s–1.
(Ans: 0.904838 mol/m3)
4.7 Consider a reaction A ® B carried out in a plug flow reactor. The differential
equation for species A is
F% #
W  M% #
F\
The initial condition is: at z = 0, CA = 1 mol/m3. The rate constant of the reaction
is 0.1 s–1. Using Runge–Kutta fourth order method, determine the concentration of
A at 5 m from entrance. Take u = 1 m/s.
(Ans: 0.606531 mol/m3)
4.8 Solve Exercise 4.7 for rate constant of the reaction of 0.01 s–1.
(Ans: 0.95123 mol/m3)
82 Introduction to Numerical Methods in Chemical Engineering

4.9 Consider reaction # 


M M
o $  o % carried out in a batch reactor. The differential
equation for component A is
F% #
 M% #
FV
for component B
F% $
M% #  M %$
FV
for component C
F%%
M % $
FV
The initial condition is: at t = 0, CA = 1 mol/m3, CB = 0 mol/m3, and CC = 0 mol/m3. The
rate constants are: k1 = 1 s–1 and k2 = 0.1 s–1. Using the Runge–Kutta fourth order
method, determine the concentration of A, B, and C at 10 s.
(Ans: CA = 4.54 ´ 10–5 mol/m3, CB = 0.408704 mol/m3, CC = 0.59125 mol/m3)
4.10 Solve Exercise 4.9 for the following rate constants: k1 = 0.1 s–1 and k2 = 1 s–1.
(Ans: CA = 0.3679 mol/m3, CB = 0.0409 mol/m3, CC = 0.5912 mol/m3)

4.11 Consider reaction #  M M


o $  o % carried out in a plug flow reactor. The
differential equation for component A is
F% #
W  M% #
FZ
for component B
F%$
W M% #  M% $
FZ
for component C
F%%
W M % $
FZ
The initial condition is: at x = 0, CA = 1 mol/m3, CB = 0 mol/m3, and CC = 0 mol/
m3. The rate constants are: k1 = 1 s–1 and k2 = 0.1 s–1. Using the Runge–Kutta fourth
order method, determine the concentration of A, B, and C at 5 m from entrance.
(Ans: CA = 0.006738 mol/m3, CB = 0.6664 mol/m3, CC = 0.3268 mol/m3)
4.12 Solve Exercise 4.11 for the following rate constants: k1 = 0.1 s–1 and k2 = 1 s–1.
(Ans: CA = 0.6065 mol/m3, CB = 0.0666 mol/m3, CC = 0.3268 mol/m3)
4.13 Consider the following two reactions taking place in a batch reactor:
M
#  $  o%
M
$  %  o&
Initial Value Problems 83

The concentration of various species with time are given by the following
differential equations:
for component A
F% #
 M% #%$
FV
for component B
F% $
 M% #% $  M% $%%
FV
for component C
F%%
M% #%$  M%$ %%
FV
for component D
F% &
M  % $ %%
FV
The initial conditions are: at t = 0, CA = 1 mol/m3, CB = 1 mol/m3, CC = 0 mol/m3,
and CD = 0 mol/m3. The rate constant of the reactions are k1 = 1 m3/mol-s and
k2 = 0.1 m3/mol-s. Using the Runge–Kutta fourth order method, determine the
concentration of species A, B, C, and D at 10 s.
(Ans: CA = 0.1392 mol/m3, CB = 0.0361 mol/m3, CC = 0.7576 mol/m3,
CD = 0.1032 mol/m3)
4.14 Solve Exercise 4.13 for the following rate constants: k1 = 0.1 m3/mol-s and
k2 = 1 m3/mol-s.
(Ans: CA = 0.5899 mol/m3, CB = 0.2447 mol/m3, CC = 0.0650 mol/m3,
CD = 0.3452 mol/m3)
4.15 Consider the following two reactions taking place in a plug flow reactor:
M
#  $  o%
M
$  %  o&
The concentration of various species are given by the following differential
equations:
for component A
F% #
W  M% #% $
FZ
for component B
F% $
W  M% #%$  M%$%%
FZ
for component C
F%%
W M% #%$  M%$%%
FZ
84 Introduction to Numerical Methods in Chemical Engineering

for component D
F%&
W M  % $ %%
FZ
The initial conditions are: at x = 0 (inlet), CA = 1 mol/m3, CB = 1 mol/m3,
CC = 0 mol/m3, and CD = 0 mol/m3. The rate constant of the reactions are
k1 = 1 m3/mol-s and k2 = 0.1 m3/mol-s. Using the Runge–Kutta fourth order method,
determine the concentration of species A, B, C, and D at 5 m from the entrance.
(Ans: CA = 0.1949 mol/m3, CB = 0.1168 mol/m3, CC = 0.7269 mol/m3,
CD = 0.0781 mol/m3)
4.16 Solve Exercise 4.15 for the following rate constants: k1 = 0.1 m3/mol-s and
k2 = 1 m3/mol-s.
(Ans: CA = 0.7009 mol/m3, CB = 0.4764 mol/m3, CC = 0.0747 mol/m3,
CD = 0.2244 mol/m3)
1 Module 11
2 Balances on Unsteady-State Processes
3
4 Ref: Richard M. Felder. Elementary Principles of Chemical Processes, 3rd edition 2005.
5

6 First Lecture
7 A system is said to be in a transient (or unsteady-state) condition if the value of any system
8 variable changes with time.
9 The general mass balance equation was given as
10 Accumulation = Input + Generation – Output – Consumption

11 There are two forms of this equation:


12 1. Differential balances are relating instantaneous rates of change with time.
13 2. Integral balances are relating changes that occur over a finite time period.
14

15 A balance on A for a period dt, The terms of a balance on A are,


16 Input rates of A enters the process = ṁin dt
17 Output rates of A leaves the process = ṁout dt
18 Generation of A by chemical reaction = ṙgen dt
19 Consumption of A by chemical reaction = ṙcons dt
20 Accumulation of A in the system = dM
21 Then, ordinary first-order differential equation
22 dM = ṁin dt + ṙgen dt – ṁout dt – ṙcons dt

23
24 M is the dependent variable and t is the independent variable.
25 Integrated from an initial time t0 to a final time tf,

26
Unsteady-state Processes 2 / 16

1 Example 11.1-1: A continuous stirred-tank reactor


2 is used to produce a compound B in the liquid-
3 phase reaction A  B.
4 Feed enters the reactor at a rate of ὐo(L/s);
5 the concentration of the reactant in the feed is
6 CA0 (mol/L).
7 The volume of the tank contents is V (L).
8 the rate of consumption of A rA = kCA [mol/(s L of reaction volume)].
9 All fluids may be taken to have the same density, (g/L).
10 Create differential balances on total mass and on moles of A.
11 Solution:
12

13 Cancel 
14 V0 is the initial volume of the tank contents.

15
16 CAo is the concentration of A in the initial tank contents.
17 CA is the output concentration
Unsteady-state Processes 3 / 16

1 Example 11.2-2
2 A liquid-phase reaction 𝐴 → 𝐵 takes place in a
3 10.0-liter continuous stirred-tank reactor. The
4 reactor may be considered perfectly mixed, so
5 that the contents are uniform and the
6 concentration of A in the product stream
7 equals that inside the tank. The tank is initially
8 filled with a solution that contains 2.0 mol A/L,
9 and the inlet and outlet flows then begin.
10 a) Create a balance on species A in the tank and provide an initial condition.
11 b) Calculate CAs at the steady-state concentration of A in the tank.
12 c) Solve the balance equation for CA, check the solution, and plot of CA versus t.
13 Solution:
14 1. The total moles of A in the reactor at any time equals V CA = 10.0 CA (mol A).

15
16 These terms are substituted into the balance equation,

17
18 2. At steady state, Setting dCA/dt = 0 and letting CA = CAS yields
t CA
19 0
20 3. by integrating yields
10
20
21 30

22
Unsteady-state Processes 4 / 16

3
4
Unsteady-state Processes 5 / 16

1 Example 11.1-2: The water level in a reservoir ‫ مستودع‬has been decreasing steadily during a
2 dry spell, and there is concern that the drought ‫جفاف‬could continue for another 60 days. The
3 local water company estimates that the consumption rate in the city is approximately 10 7
4 L/day. The Conservation Service estimates that rainfall and stream drainage ‫ ترصيف‬into the
5 reservoir coupled with evaporation from the reservoir should yield a net water input rate of
6 min = 106 exp(t /100) L/day, the reservoir contained an estimated 109 liters of water.
7 1. Create a differential balance on the water in the reservoir.
8 2. Integrate the balance to calculate the reservoir volume at the end of the 60 days of
9 continued drought.
10
11 Solution: 1. the differential balance equation is as follows:

12
13 2. Integrate the differential equation from t = 0 to 60 days.

14
Unsteady-state Processes 6 / 16

1 EXAMPLE 11.2-1 A 12.5 m3 tank is being filled with


2 water at a rate of 0.05 m3/s. At a moment when the
3 tank contains 1.2 m3 of water, a bottom leak
4 develops and gets progressively worse with time.
5 The rate of leakage can be approximated as
6 0.0025 𝑡 (𝑚3 /𝑠).
7 The density of liquid water is 1000 kg/m3.
8 1. Create a differential equation for mass balance on the tank
9 2. Solve the balance equation to obtain an expression for V(t) and plot of V versus t.
10
11 Solution:
12 1. The total mass of the tank contents is M (kg) =  V, Then

13

14
15 Substituting these terms into the water balance equation (accumulation = input – output)
16 and canceling  yields

17
18 Verify that each term in the equation (including dV/dt) has units of m3 /s.
19
20 2. integrate from the initial condition (t = 0, V = 1.2 m3), to (t and V) .

21
22 Check: When t = 0, V = 1.2 m3 (confirming the given initial condition).
23 A plot of the derived expression for V(t) is as follows:
Unsteady-state Processes 7 / 16

1
2 Initially, the filling causes the volume of the tank contents to increase, but as the leak
3 gets larger the tank begins to drain. The maximum volume is 1.7 m3, well below the tank
4 capacity of 12.5 m3. At about t = 57 s the contents drain completely. The mathematical
5 formula for V predicts negative volumes after this time, but physically the volume must
6 remain at zero.
7 The actual solution of the balance equation is therefore

8
9 The plot shown above should be changed in the range t > 57 s to a line coincident with
10 the x-axis.

11
Unsteady-state Processes 8 / 16

1 11.3 ENERGY BALANCES ON SINGLE-PHASE NONREACTIVE PROCESSES


2 The general energy balance has the form
3 𝑨𝒄𝒄𝒖𝒎𝒖𝒍𝒂𝒕𝒊𝒐𝒏 = 𝑰𝒏𝒑𝒖𝒕 – 𝑶𝒖𝒕𝒑𝒖𝒕 (𝟏𝟏. 𝟑 − 𝟏)
4 For non-reactive process, energy can neither be generated nor consumed.
5
6 We apply the balance equation (11.3-1) in a small-time interval from t to t + Δt,
7 The properties of the input and output streams remain approximately constant during time.

8
9 ΔEsys is the total energy (internal + kinetic + potential) of a system,
10 ṁin and ṁout are the mass flow rates of the system input and output streams. (If the system
11 is closed, these quantities each equal zero.)
12 Equation 11.3-1, divide by dt, and let dt approach zero, we obtain:

13
14 It is difficult to solve Equation 11.3-2 unless a number of simplifications are made.
15 The conditions are:
16 (a) Negligible kinetic and potential energy changes,
17 (b) No accumulation of mass in the system,
18 (c) Pressure independence of Û and Ĥ,
19 (d) No phase changes or chemical reactions,
20 (e) A spatially uniform system temperature.
21

22 𝑑𝑈 = ∫ 𝐶𝑉 𝑑𝑇 (𝐶𝑜𝑛𝑠𝑡 𝑉)

23 𝑑𝐻 = ∫ 𝐶𝑃 𝑑𝑇 (𝐶𝑜𝑛𝑠𝑡 𝑃)
Unsteady-state Processes 9 / 16

1 𝐶𝑉 = molar Heat capacity at constant Volume


2 𝐶𝑃 = specific Heat capacity at constant pressure
3
4 The general energy balance (Equation 11.3-2) to obtain for

6
7
8 Example 11.3-1 A well-stirred batch reactor wrapped ‫ لفافة‬in an electrical heating is charged
9 with a liquid reaction mixture. The reactants must be heated from 25 °C to 250 °C before the
10 reaction can take place at a measurable rate. Determine the time required for this heating to
11 take place. M = 4.5 kg Cv = 0.8 Cal/g °C), Q = 500 J/s
12
13 Solution
14 Equation 11.3-13, the system has constant volume, W = 0. The equation therefore becomes

15

16
17 𝑴 𝑪𝒗 (𝟐𝟓𝟎 − 𝟐𝟓) = 𝑸 ̇ 𝒕𝒇
𝟐𝟐𝟓 𝑴 𝑪𝒗
18 𝒕𝒇 =
𝑸̇
19 tf = 3220 s = 53.7 min
Unsteady-state Processes 10 / 16

1 Example 11.3-2: The air-cooled in the


2 engine housing ‫ غطاء المحرك‬is circulated
3 rapidly enough for its temperature to be
4 considered uniform and equal to the
5 temperature of the outlet air. Air passes
6 through the engine housing at a rate of
7 6.00 lb-mole/min, entering at a
8 temperature of 65 °F, and an average of
9 0.2 lb-mole of air is contained within the engine housing. (We will neglect the variation of
10 this quantity with the changing temperature of the gas.)
11 Heat is lost from the housing to its surroundings at a rate
12 Qlost (Btu/min) = [33.0 Btu/ (F min)] (T – 65 °F)
13 Generates heat at a constant rate Qgen = 8530 Btu/min.
14
15 a) Calculate the steady-state air temperature if the engine runs continuously for an
16 indefinite period of time, assuming Cv = 5.00 Btu/(lb-mole F)
17 b) Derive a differential equation for the variation of the outlet temperature with the
18 time and solve it.
19
20 Solution: System = the air within the engine housing.
21 a) At steady-state is dT/dt = 0 and W = 0 in Equation 11.3-12.

22
23 𝑄̇ = 𝑄̇𝑙𝑜𝑠𝑡 + 𝑄̇𝑔𝑒𝑛
24 Assuming ideal gas behavior

25
26 The energy balance equation then becomes
27 0 = 6.0 × 6.99 (𝑇𝑠 − 65.0) − 8530 − 33(𝑇𝑠 − 65.0)
28 Ts = 179 °F
Unsteady-state Processes 11 / 16

1 b) The unsteady-state balance equation (11.3-12) is, for our system,

2
3 By integrating:
4
5 Time (s) T (F)
6 0
7 0.5
8
1
9
1.5
10
2
11
3
12
4
13
5
14
15 Assume a number of values of time (s), a plot would appear T vs t as follows.
16
17
18
19
20
21
Unsteady-state Processes 12 / 16

1 11.4 Simultaneous Transient Balances


2 When more than one species is involved in a process or when energy balances are required,
3 several balance equations must be derived and solved simultaneously.
4 The goal is to derive a set of differential equations that have the following form:

5
6 Suppose y1(t), y2(t), ... , yn(t) are dependent variables in a process system (such as species
7 flow rates or concentrations or mole fractions or temperature).
8 The solutions of the equations may be expressed as a table of y1, y2, ..., yn for increasing
9 values of t or as plots of y1 versus t , y2 versus t ,...
10
11 Example 11.4-1 An aqueous solution containing 0.015 mol/L of species A is fed into a holding
12 tank that initially contains 75 liters of pure water. The reactant decomposes at a rate
13 r [mol A/(L s)] = 0.0375 CA
14 CA (mol A/L) is the concentration of A in the tank.
15 The volumetric feed rate of the solution, 𝑣̇ (𝑡) = 2.5 𝑡, increases linearly over a 10-second
16 period from 0 to 25 L/s and stays constant at that rate thereafter until the tank is filled to
17 the desired level. The density of the feed stream is constant.
18 a) Create transient balances for the total mass of the tank
19 contents and the mass of A in the tank. Convert the
20 equations to differential equations for (the volume of the
21 tank contents V(t) and the CA and provide initial conditions.
22 b) Sketch the shapes for V (L) and CA (mol/L) versus time
23 for the period from t = 0 to t = 60 s.
24
25 Solution
26 CA in the tank changes with time because both the moles of A in the tank and the volume of
27 the tank contents are changing.
Unsteady-state Processes 13 / 16

1 a. Total mass balance: Accumulation = Input (kg/s).


2 Accumulation (kg) = (kg/L) V (L),
3 Mass rate of the feed stream (kg/s) = (kg/L) 𝑣̇ (L/s).
4 Mass balance thus becomes 𝒅(𝑽)/𝒅𝒕 =  𝒗̇ , ( = constant).

5
6 Balance on A: Accumulation (mol A/s) = Input – Consumption.
7 Accumulation of A = V (L) × CA (mol A/L).

8
9 The initial condition in Equation 2 follows from the statement that the tank initially contains
10 pure water. In Equations 1 and 2,
11 (1) The first from t = 0 to t = 10 s when 𝑣̇ = 2.5 𝑡 3a
12 (2) The second for t > 10 s, when 𝑣̇ = 25 L/s. 3b

13
14 Equations 1 and 2 are two differential equations in two dependent variables, where V and
15 CA. These equations may be solved with any of the software programs.
16
17 b. The system of equations must be solved in two stages after Substitute 3a in Eqs 1 and 2.

18
Unsteady-state Processes 14 / 16

1 When this pair of equations is solved for V (t) and CA (t)


2 Determine that V (10 s) = 200 L and CA (10 s) = 0.00831 mol A/L.
3  Substitute 𝑣̇ (t) 25 L/s in Equations 1 and 2 and substitute the dependent variable
4 values at t = 10 s for the initial conditions:

5
6

7
8  The plot of V versus t is the initial condition starts horizontally at (t = 0, V = 75 L). The
9 slope of the curve therefore equals zero at t = 0.
10  During the first 10 seconds, 𝑑𝑉/𝑑𝑡 = 2.5 𝑡 (from Equations 1 and 3a). Increases
11 over the first 10 seconds.
12  At t 10 seconds, dV/dt reaches a value of 25 L/s and thereafter remains constant at
13 that value. A curve with a constant slope is a straight line.
14  We conclude that the plot of V versus t curves up for 10 seconds, and then becomes
15 a straight line with a slope of 25 L/s.
16  The plot of CA versus t must begin at (t = 0, CAo2. = 0), since the tank initially contains
17 pure water.
18  At t = 0, the Equation 2 for dCA/dt equals zero. The plot of CA versus t is therefore
19 horizontal at the y-axis.
Unsteady-state Processes 15 / 16

1 Brief Look Back at Calculus


2 This section reviews some calculus rules and procedures for solving differential equations.
3
4 Rule 1: Derivative of a constant times a function
5 If x is an independent variable, y(x) is a dependent variable, and a is a constant.

6
7
8 Rule 2: Product rule for differentiation

9
10 If the system volume changes with time (e.g., because the tank is being filled or discharged),

11
12 To solve for CA(t), you would have to obtain an independent expression for dV/dt and solve
13 both equations simultaneously. ‫حل معادلتين انيا‬
14
15 Rule 3: Solution of separable first-order differential equations
16 The general form of a first-order differential equation is, e.g.

17
18 To solve this equation by doing something like
19 It cannot evaluate that integral without first substituting for y(x).
20 A separable first-order differential equation is
21
22 The procedure for solving a separable equation, and then to integrate each side over its
23 respective variable from the initial value to the final value:

24
1 ‫الطرق العددية للمهندسني –االستكمال وتطابق املنحين‬
2

3 Interpolation and Curve Fitting


4 Three Lectures (3 Hours/Week)
5 Instructor: Dr. Amjed Ahmed
6

7 Outline Module
8 First Lecture.....................................................................................................................2
9 1. INTRODUCTION ................................................................................................ 2
10 3. CURVE FITTING ................................................................................................ 3
11 3.1 Fitting a Straight Line (Linear Regression ‫ ) االنحدار الخطي‬............................. 3

12 Second Lecture.................................................................................................................8
13 3.2 Fitting a Non-Linear ......................................................................................8

14 Third Lecture .................................................................................................................12


15 3.3 Fitting a Polynomial ....................................................................................12
16 3.3.1 Suitable polynomial order .................................................................. 19

17 Fourth Lecture ...............................................................................................................20


18 3.4 Fitting a Non-polynomial ............................................................................20

19 Exercises .........................................................................................................................22
20
21
22 References:
23 [1]. Numerical Methods in Engineering with MATLAB, Jaan Kiusalaas. Cambridge. UK. 2005.
24 [2]Fundamental Numerical Methods and Data Analysis, by George W. Collins, II.
25 [3]Numerical Analysis Using MATLAB® and Excel®, Third Edition, Steven T. Karris.
26
Interpolation and Curve Fitting 2 /24

1 First Lecture
2
3 INTRODUCTION
4
5 Question: In root finding, we used a given function f(x) to identify where it crossed zero.
6 Where does this given function f(x) come?
7 Answer:
8 1. An analytical model of phenomena (e.g. equations from energy balance)
9 2. A statistical model from experimental results, data pairs, etc…
10
11 Where fi is the measured value (known) at xi. We would like to find a function f(x).
12 There are two basic approaches: interpolation and curve fitting. x f(x)
13 x1 f1
x2 f2
14
⋮ ⋮
15 Curve fitting Capturing the trend in data by assigning a single function xn fn
16 across the entire range. The example below uses a straight-line function
17 .‫اخذ االجتاه العام للنتائج وإسناد دالة واحدة لتمثل مجيع القيم‬

18
19
20
21
22
23
24 a) Interpolation b) Curve Fitting
25

Dr. Amjed Ahmed


Interpolation and Curve Fitting 3 /24

1 1. CURVE FITTING
2 If the data are obtained from experiments, they typically contain an amount of random
3 noise due to measurement errors. The task of curve fitting is to find a smooth curve that
4 fits these data points with high reliability.
5
6 1.1 Fitting a Linear Regression ‫االنحدار الخطي‬
7 The general form of a straight line is (f(x) = a x + b).
8 The goal is to identify the coefficients ‘a’ and ‘b’ with best-fitted line.
9

10 ‫طريقة املربعات الصغرى‬


11 Least Squares Method (LS)
12 Data Points are (x, y), and the fitted line these points
13 on are (x, f(x)). Give the best fits that has minimum
14 error (𝜖) between fitted line and points (n).

15 .‫قيمة اخلطأ من التطابق هو املسافة العمودية بني أي نقطة وخط التطابق واليت يفضل ان تكون اقل قيمة‬
16 Sum the total minimum error (𝜖) for n points is

17 𝜖 = (𝑦1 − 𝑓(𝑥1 )) + (𝑦2 − 𝑓(𝑥2 )) + ⋯ + (𝑦𝑛 − 𝑓(𝑥𝑛 ))

18 ‫إبجياد جمموع اخلطأ‬


19 Square the error to overcome positive or negative error
20 .‫مث تربيع قيمة اخلطا للتغلب على القيم السالبة‬
2 2 2
21 𝜖 = (𝑦1 − 𝑓(𝑥1 )) + (𝑦2 − 𝑓(𝑥2 )) + ⋯ + (𝑦𝑛 − 𝑓(𝑥𝑛 ))
𝑛
2
22 𝜖 = ∑(𝑦𝑖 − 𝑓(𝑥𝑖 )) 1
𝑖=1

23 .‫بتعويض مبعادلة اخلط املستقيم‬


24 Substitute f(x) = a + b x
𝑛
2
25 𝜖 = ∑(𝑦𝑖 − (𝑎 + 𝑏 𝑥𝑖 )) 2
𝑖=1

26 Based on the calculus, the 𝜖 function can be derivative to a and b, and then set to zero
27 ‫أبخذ املشتقة لكل اثبت ومساواهتا ابلصفر‬

Dr. Amjed Ahmed


Interpolation and Curve Fitting 4 /24

𝑛
𝜕𝜖
1 = ∑ −2(𝑦𝑖 − 𝑎 − 𝑏 𝑥𝑖 ) = 0 3𝑎
𝜕𝑎
𝑖=1
𝑛
𝜕𝜖
2 = ∑ −2 𝑥𝑖 (𝑦𝑖 − 𝑎 − 𝑏 𝑥𝑖 ) = 0 3𝑏
𝜕𝑏
𝑖=1

3 Then
𝑛

4 ∑(𝑦𝑖 − 𝑎 − 𝑏 𝑥𝑖 ) = 0
𝑖=1
𝑛

5 ∑ 𝑥𝑖 (𝑦𝑖 − 𝑎 − 𝑏 𝑥𝑖 ) = 0
𝑖=1

6 After Re-arrange
𝑛 𝑛

7 𝑎 × 𝑛 + 𝑏 ∑ 𝑥𝑖 = ∑ 𝑦𝑖
𝑖=1 𝑖=1
𝑛 𝑛 𝑛
2
8 𝑎 ∑ 𝑥𝑖 + 𝑏 ∑ 𝑥𝑖 = ∑ 𝑥𝑖 𝑦𝑖
𝑖=1 𝑖=1 𝑖=1

9 Solve these equations by Gauss-elimination method is:


𝑎
𝑛 ∑ 𝑥𝑖 ∑ 𝑦𝑖
10 | | | | =| |
∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑥𝑖 𝑦𝑖
𝑏
11 Finally, can be calculate a and b values.
∑ 𝑦𝑖 ∑ 𝑥𝑖2 − ∑ 𝑥𝑖 ∑ 𝑥𝑖 𝑦𝑖 𝑦̅ ∑ 𝑥𝑖2 − 𝑥̅ ∑ 𝑥𝑖 𝑦𝑖
12 𝑎= = 4𝑎
𝑛 ∑ 𝑥𝑖2 −(∑ 𝑥𝑖 )2 ∑ 𝑥𝑖2 − 𝑛 𝑥̅ 2
𝑛 ∑ 𝑥𝑖 𝑦𝑖 − ∑ 𝑥𝑖 ∑ 𝑦𝑖 ∑ 𝑥𝑖 𝑦𝑖 − 𝑛 𝑥̅ 𝑦̅
13 𝑏= = 4𝑏
𝑛 ∑ 𝑥𝑖2 −(∑ 𝑥𝑖 )2 ∑ 𝑥𝑖2 − 𝑛 𝑥̅ 2
∑ 𝑦𝑖 − 𝑎 ∑ 𝑥𝑖
14 𝑂𝑟 𝑏= 4𝑐
𝑛
15 These expressions are susceptible ‫ سريعة التأثير‬to round-off errors ‫ أخطاء التقريب‬.
16 It is better to compute the parameters from
17 LS Method. ‫الصيغة النهائية لطريقة املربعات الصغرى‬
∑ 𝑦𝑖 (𝑥𝑖 − 𝑥̅ )
18 𝑏= 5𝑎
∑ 𝑥𝑖 (𝑥𝑖 − 𝑥̅ )
19 𝑎 = 𝑦̅ − 𝑥̅ 𝑏 5𝑏

Dr. Amjed Ahmed


Interpolation and Curve Fitting 5 /24

∑ 𝑥𝑖 ∑ 𝑦𝑖
1 𝑥̅ = and 𝑦̅ = 5𝑐
𝑛 𝑛
2
3 Standard Deviation (σ) is quantified of the data spread about the fitting curve, as
2
∑𝑛 (𝑦𝑖 − 𝑓(𝑥𝑖 ))
4 𝜎 = √ 𝑖=1 6
𝑛−𝑚

5 n : ‫عدد النقاط‬ m: ‫عدد احلدود‬


6 .‫كلما كانت قيمة مقياس التشتت قليلة دل ذلك على فعايل تطابق املنحين‬
7
8 Example [1]: Fit a straight line to the data shown and compute the standard deviation.

x 0.0 1.0 2.0 2.5 3.0

y 2.9 3.7 4.1 4.4 5.0


9
10 Solution: The averages of the data are

11
Point Fitting Standard Deviation
𝒙 𝒚 ̅) 𝒙(𝒙 − 𝒙
𝒚(𝒙 − 𝒙 ̅) 𝑓(𝑥) (𝑦 − 𝑓(𝑥)) (𝑦 − 𝑓(𝑥))2
1 0.0 2.9 –4.93 0 2.927 –0.027 0.000729
2 1.0 3.7 –2.59 0.7 3.570 0.13 0.0169
3 2.0 4.1 1.23 –0.6 4.213 –0.113 0.012769
4 2.5 4.4 3.52 –2 4.535 –0.135 0.018225
5 3.0 5.0 6.5 –3.9 4.856 0.144 0.020736
∑ 8.5 20.1 11.25 –5.8 0.069359

Dr. Amjed Ahmed


Interpolation and Curve Fitting 6 /24

1
2 Therefore, the regression line is f (x) = 2.927 + 0.6431 x, which is shown in the figure
3 with the data points.

4
5 So that the standard deviation becomes
2
∑(𝑦𝑖 − 𝑓(𝑥𝑖 )) 0.06936
6 𝜎=√ =√ = 0.152
𝑛−𝑚 5−2

7 .‫قيمة قليلة ملقياس التشتت ليدل على فعايل تطابق املنحين‬


8

Dr. Amjed Ahmed


Interpolation and Curve Fitting 7 /24

1 Example: Find the best fitting line though six points and Standard Deviation:
x 0 5.0 1 1.0 2 2.0
y 5 1.0 3 5.0 6 5.0
2
3 Solution:

Point Fitting Standard Deviation


𝒙 𝒚 ̅) 𝒙(𝒙 − 𝒙
𝒚(𝒙 − 𝒙 ̅) 𝑓(𝑥) (𝑦 − 𝑓(𝑥)) (𝑦 − 𝑓(𝑥))2
1 0.0 5.5
2 5.0 1.0
3 1.5 3.5
4 1.5 5.0
5 2.5 6.5
6 2.0 5.0
7.5 22.5
4
5
6 Answer
7 f(x) = 3.561 x – 0.975

Dr. Amjed Ahmed


Interpolation and Curve Fitting 8 /24

1 Second Lecture
2 1.2 Fitting a Non-Linear Regression
3 General shape of non-linear relationships are exponential, power, and growth-rate
4 functions:
5
6 Q: When we take partial derivatives with respect to minimum error function, and set to
7 zero, then obtain two nonlinear function. what to do?
8
9 Ans. #1: Use Newton Raphson Method.
10
11 Ans. #2: Use linearization and then Applied LS Method:
𝑛 𝑛
2 2
12 𝜖 = ∑(𝑦𝑖 − 𝑓(𝑥𝑖 )) = ∑(𝑦𝑖 − 𝑓(𝑎𝑒 𝑏 𝑥𝑖 )) 2
𝑖=1 𝑖=1

13

Dr. Amjed Ahmed


Interpolation and Curve Fitting 9 /24

Function Linearization Constants


1 Exponential 𝑙𝑛 𝑦 = 𝑙𝑛 𝑎 + 𝑏 𝑥  𝑌 = 𝐴 + 𝑏𝑥 𝑌 = ln 𝑦

𝑦 = 𝑎 𝑒 𝑏𝑥 Plot: ln y vs. x 𝑎 = 𝑒𝐴
ln 𝑦

𝑆𝑙𝑜𝑝𝑒 = 𝑏
𝑏𝑥 Linearization
𝑦=𝑎𝑒
𝐼𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 = ln 𝑎

2 Power 𝑙𝑛 𝑦 = 𝑙𝑛 𝑎 + 𝑏 𝑙𝑛 𝑥  𝑌 = 𝐴 + 𝑏 𝑋 𝑌 = 𝑙𝑛 𝑦 , 𝑋 = 𝑙𝑛 𝑥
𝑦 = 𝑎 𝑥𝑏 Plot: 𝑙𝑛 𝑦 𝒗𝒔. 𝑙𝑛 𝑥 𝑎 = 𝑒𝐴

3 Growth-rate 1 1 𝑏 1 1
= +  𝑌 = 𝐴 + 𝐵𝑋 𝑎=
𝑎𝑥 𝑦 𝑎 𝑎 𝑥 𝐴
𝑦= 1 1 𝑏=𝐵𝑎
𝑥+𝑏 𝐏𝐥𝐨𝐭: 𝐯𝐬.
𝑦 𝑥 1
𝑦 𝑏
𝑆𝑙𝑜𝑝𝑒 =
𝑎𝑥 𝑎
𝑦=
𝑥+𝑏 1
𝐼𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 =
𝑎
1 𝑥

4 𝑦 = 𝑎 𝑏𝑥 𝑙𝑛 𝑦 = 𝑙𝑛 𝑎 + (𝑙𝑛 𝑏)𝑥  𝑌 = 𝐴 + 𝐵 𝑥 𝑌 = ln 𝑦 , 𝑎 = 𝑒 𝐴, 𝑏 = 𝑒𝐵

𝑦
5 𝑦 = 𝑎 𝑥 𝑒 𝑏𝑥 𝑙𝑛 ( ) = 𝑙𝑛 𝑎 + 𝑏 𝑥  𝑌 = 𝐴 + 𝑏 𝑥 𝑌 = (𝑙𝑛 𝑦/𝑥) , 𝑎 = 𝑒𝐴
𝑥
𝑏 1 1
6 𝑦=𝑎+ 𝑦 =𝑎+𝑏 ( )  𝑌 =𝑎+𝑏𝑋 𝑋=
𝑥 𝑥 𝑥

7 𝑦 = c − 𝑎 𝑒 𝑏𝑥 𝑙𝑛 (𝑐 − 𝑦) = ln 𝑎 + 𝑏𝑥  𝑌 = 𝐴 + 𝑏 𝑥 𝑌 = 𝑙𝑛 (𝑐 − 𝑦) , 𝑎 = 𝑒 𝐴

c 𝑐 𝑐
8 𝑦= 𝑙𝑛 ( − 1) = 𝑙𝑛 𝑎 + 𝑏𝑥  𝑌 = 𝐴 + 𝑏𝑥 𝑌 = 𝑙𝑛 ( − 1) , 𝑎 = 𝑒 𝐴
1 + 𝑎 𝑒 𝑏𝑥 𝑦 𝑦

9 𝑦 = 𝑎 𝑙𝑛 𝑥 + 𝑏 𝑦 = 𝑎𝑋 + 𝑏 𝑋 = 𝑙𝑛 𝑥

Dr. Amjed Ahmed


Interpolation and Curve Fitting 10 /24

1 Example 3.9 [1]: Determine the parameters a and b so that f (x) = a ebx fits the following
2 data in the LS-Method. Compute the standard deviation

x 1.2 2.8 4.3 5.4 6.8 7.9


y 7.5 16.1 38.9 67.0 146.6 266.2
3
4 Solution: the problem is to fit the function 𝑙𝑛(𝑎𝑒𝑏𝑥 ) = 𝑙𝑛 𝑎 + 𝑏 𝑥 to the data

Point Fitting Standard Deviation


𝒙 𝒚 𝒀 = 𝒍𝒏 𝒚 ̅)
𝒀(𝒙 − 𝒙 ̅)
𝒙(𝒙 − 𝒙 𝑓(𝑥) 𝑦 − 𝑓(𝑥) (𝑦 − 𝑓(𝑥))2
1.2 7.5 2.015 –7.113 –4.236 7.21 0.29 0.0841
2.8 16.1 2.779 –5.363 –5.404 17.02 −0.92 0.8464
4.3 38.9 3.661 –1.574 –1.849 38.07 0.83 0.6889
5.4 67 4.205 2.817 3.618 68.69 −1.69 2.8561
6.8 146.6 4.988 10.325 14.076 145.6 1.0 1
7.9 266.2 5.584 17.702 25.043 262.72 3.48 12.1104
28.4 23.232 16.794 31.248 17.586
5
6 We are dealing with linear regression, where the parameters to be found are A = ln a and b.
∑𝑛𝑖=1 𝑥𝑖 28.4
7 𝑥̅ = = = 4.73
𝑛 6
∑𝑛𝑖=1 𝑌𝑖 23.23
8 𝑌̅ = = = 3.87
𝑛 6
∑ 𝑦𝑖 (𝑥𝑖 − 𝑥̅ ) 16.716
9 𝑏= = = 0.537
∑ 𝑥𝑖 (𝑥𝑖 − 𝑥̅ ) 31.153
10 𝐴 = 𝑌̅ − 𝑥̅ 𝑏 = 3.87 − 4.73 × 0.537 = 1.33
11
12 𝑎 = 𝑒 𝐴 = 𝑒 1.33 = 3.78
13 The fitting line becomes 𝒚 = 𝒆𝑨 = 𝟑. 𝟕𝟖 𝒆𝟎.𝟓𝟑𝟕 𝒙 . as shown in the next figure.

Dr. Amjed Ahmed


Interpolation and Curve Fitting 11 /24

1
2 Here is the computation of standard deviation

2
∑(𝑦𝑖 − 𝑓(𝑥𝑖 )) 17.89
3 𝜎=√ =√ = 2.1
𝑛−𝑚 6−2

4 .‫قيمة التشتت قليلة ليدل على فعايل تطابق املنحين‬


5

6 Example: Find the best power function passing through four points:
7 (1, 3), (2, 8), (3, 27), (4, 80)
8
9 Solution:

Point 𝒙 𝒚

1 1 3

2 2 8

3 3 27

4 4 80

∑ 10
10

Dr. Amjed Ahmed


Interpolation and Curve Fitting 12 /24

1 Third Lecture
2 3.3 Fitting a Polynomial
3 Many shapes depend on coefficients of function. We can choose a form depend on
4 experience or trial/error. A general form for a polynomial of m order is,

5 𝑓(𝑥) = 𝑎0 + 𝑎1 𝑥 + 𝑎1 𝑥 2 + 𝑎2 𝑥 3 + ⋯ + 𝑎𝑚 𝑥 𝑚 7

6 For example: 𝑓(𝑥) = 3.2 − 3 𝑥𝑖 + 6 𝑥𝑖2 − 8.7 𝑥𝑖3 + 7 𝑥𝑖4

7
8
9 It can use the same idea by LS Method,
𝑛
2
10 𝜖 = ∑(𝑦𝑖 − 𝑓(𝑥𝑖 )) 2
𝑖=1

11 Now substitute eq. 7 into eq. 2:


𝑛

12 𝜖 = ∑(𝑦𝑖 − 𝑎0 − 𝑎1 𝑥𝑖 − 𝑎2 𝑥𝑖2 − ⋯ − 𝑎𝑚 𝑥𝑖𝑚 )2 7


𝑖=1

Dr. Amjed Ahmed


Interpolation and Curve Fitting 13 /24

1 Again, by take the derivative of error to a0 , a1 , a2 , a3 … am, and then set to zero
𝑛
𝜕𝜖
2 = −2 ∑(𝑦𝑖 − 𝑎0 − 𝑎1 𝑥𝑖 − 𝑎2 𝑥𝑖2 − ⋯ − 𝑎𝑚 𝑥𝑖𝑚 ) = 0
𝜕𝑎0
𝑖=1
𝑛
𝜕𝜖
3 = −2 ∑ 𝑥𝑖 (𝑦𝑖 − 𝑎0 − 𝑎1 𝑥𝑖 − 𝑎2 𝑥𝑖2 − ⋯ − 𝑎𝑚 𝑥𝑖𝑚 ) = 0
𝜕𝑎1
𝑖=1
𝑛
𝜕𝜖
4 = −2 ∑ 𝑥𝑖2 (𝑦𝑖 − 𝑎0 − 𝑎1 𝑥𝑖 − 𝑎2 𝑥𝑖2 − ⋯ − 𝑎𝑚 𝑥𝑖𝑚 ) = 0
𝜕𝑎2
𝑖=1
5 ⋮
𝑛
𝜕𝜖
6 = −2 ∑ 𝑥𝑖𝑚 (𝑦𝑖 − 𝑎0 − 𝑎1 𝑥𝑖 − 𝑎2 𝑥𝑖2 − ⋯ − 𝑎𝑚 𝑥𝑖𝑚 ) = 0
𝜕𝑎𝑚
𝑖=1
7 Then
𝑛 𝑛 𝑛 𝑛 𝑛

8 ∑ 𝑦𝑖 − ∑ 𝑎0 − ∑ 𝑎1 𝑥𝑖 − ∑ 𝑎2 𝑥𝑖2 − ⋯ − ∑ 𝑎𝑚 𝑥𝑖𝑚 = 0
𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
𝑛 𝑛 𝑛 𝑛 𝑛

9 ∑ 𝑦𝑖 𝑥𝑖 − ∑ 𝑎0 𝑥𝑖 − ∑ 𝑎1 𝑥𝑖2 − ∑ 𝑎2 𝑥𝑖3 − ⋯ − ∑ 𝑎𝑚 𝑥𝑖𝑚+1 = 0


𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
𝑛 𝑛 𝑛 𝑛 𝑛

10 ∑ 𝑦𝑖 𝑥𝑖2 − ∑ 𝑎0 𝑥𝑖2 − ∑ 𝑎1 𝑥𝑖3 − ∑ 𝑎2 𝑥𝑖4 − ⋯ − ∑ 𝑎𝑚 𝑥𝑖𝑚+2 = 0


𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
11 ⋮
𝑛 𝑛 𝑛 𝑛 𝑛

12 ∑ 𝑦𝑖 𝑥𝑖𝑚 − ∑ 𝑎0 𝑥𝑖𝑚+1 − ∑ 𝑎1 𝑥𝑖𝑚+2 − ∑ 𝑎2 𝑥𝑖𝑚+3 − ⋯ − ∑ 𝑎𝑚 𝑥𝑖𝑚+𝑚 = 0


𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
13 Re-arrangement:
𝑛 𝑛 𝑛 𝑛 𝑛

14 ∑ 𝑎0 + ∑ 𝑎1 𝑥𝑖 + ∑ 𝑎2 𝑥𝑖2 +⋯+ ∑ 𝑎𝑚 𝑥𝑖𝑚 = ∑ 𝑦𝑖


𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
𝑛 𝑛 𝑛 𝑛 𝑛

15 ∑ 𝑎0 𝑥𝑖 + ∑ 𝑎1 𝑥𝑖2 + ∑ 𝑎2 𝑥𝑖3 + ⋯ + ∑ 𝑎𝑚 𝑥𝑖𝑚+1 = ∑ 𝑦𝑖 𝑥𝑖


𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
𝑛 𝑛 𝑛 𝑛 𝑛

16 ∑ 𝑎0 𝑥𝑖2 + ∑ 𝑎1 𝑥𝑖3 + ∑ 𝑎2 𝑥𝑖4 + ⋯ + ∑ 𝑎𝑚 𝑥𝑖𝑚+2 = ∑ 𝑦𝑖 𝑥𝑖2


𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
17 ⋮
𝑛 𝑛 𝑛 𝑛 𝑛

18 ∑ 𝑎0 𝑥𝑖𝑚+1 + ∑ 𝑎1 𝑥𝑖𝑚+2 + ∑ 𝑎2 𝑥𝑖𝑚+3 − ⋯+ ∑ 𝑎𝑚 𝑥𝑖𝑚+𝑚 = ∑ 𝑦𝑖 𝑥𝑖𝑚


𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
19
20 After re-arrangement for linear equation system,

Dr. Amjed Ahmed


Interpolation and Curve Fitting 14 /24

𝑎0
𝑛 ∑ 𝑥𝑖 ∑ 𝑥𝑖2 ⋯ ∑ 𝑥𝑖𝑚 ∑ 𝑦𝑖

∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑥𝑖3 ⋯ ∑ 𝑥𝑖𝑚+1 𝑎1 ∑ 𝑥𝑖 𝑦𝑖

1 ∑ 𝑥𝑖4 = ∑ 𝑥𝑖2 𝑦𝑖
∑ 𝑥𝑖2 ∑ 𝑥𝑖3 ⋯ ∑ 𝑥𝑖𝑚+2
⋮ 𝑎2
⋮ ⋮ ⋮ ⋮
∑ 𝑥𝑖𝑚 ∑ 𝑥𝑖𝑚+1 ∑ 𝑥𝑖𝑚+2 ⋯ ∑ 𝑥𝑖𝑚+𝑚 ] [𝑎⋮ ] 𝑚
[ 𝑚 [∑ 𝑥𝑖 𝑦𝑖 ]
2 By Gaussian Elimination to find a0 , a1 , a2 , a3, … am .
3

Dr. Amjed Ahmed


Interpolation and Curve Fitting 15 /24

1 Example: Find the best parabola (second order) representing five points:
2 (0, 1), (1, 3), (2, 4), (3, 11), (4, 15)?
3
4 Solution:
5 𝑓(𝑥) = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2
𝑎0
𝑛 ∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑦𝑖

6 ∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑥𝑖3 𝑎 1 = ∑ 𝑥𝑖 𝑦𝑖

[∑ 𝑥𝑖
2
∑ 𝑥𝑖3 ∑ 𝑥𝑖4 ] [ 𝑎 ] 2
[∑ 𝑥𝑖 𝑦𝑖 ]
2

7 .‫جيب ترتيب املعادالت مث املصفوفة بعد ذلك اجلدول‬


Point 𝒙 𝒚 𝒙𝟐 𝒙𝟑 𝒙𝟒 𝒚𝒙 𝒚𝒙𝟐
1 0 1 0 0 0 0 0
2 1 3 1 1 1 3 3
3 2 4 4 8 16 8 16
4 3 11 9 27 81 33 99
5 4 15 16 64 256 60 240
∑ 10 34 30 100 354 104 358
8
5 10 30 𝑎0 34

9 10 30 100 𝑎1 = 104

[30 100 354] [ 𝑎2 ] [358]


10
11 Then find by Gauss Elimination or Jordon Methods (H.W.).
12 a0 = a1 = a2 =
13

Dr. Amjed Ahmed


Interpolation and Curve Fitting 16 /24

1 Example: Fit a second and third orders polynomial to the following data and the
2 compared standard deviation between these fitting.

x 0.0 5.0 1.0 1.0 2.0 2.0


y 5.0 0.25 1.0 2.25 4.0 6.25
3
4 Solution:
5 (a) Second order polynomial: 𝑓(𝑥) = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2
𝑎0
𝑛 ∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑦𝑖

6 ∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑥𝑖3 𝑎 1 = ∑ 𝑥𝑖 𝑦𝑖

[∑ 𝑥𝑖
2
∑ 𝑥𝑖3 ∑ 𝑥𝑖4 ] 2
[∑ 𝑥𝑖 𝑦𝑖 ]
[ 𝑎2 ]
7

Point 𝒙 𝒚 𝒙𝟐 𝒙𝟑 𝒙𝟒 𝒚𝒙 𝒚𝒙𝟐

1 0.0 0.0

2 0.5 0.25

3 1.0 1.0

4 1.5 2.25

5 2.0 4.0

6 2.5 6.25

∑ 7.5 13.75 13.75 28.12 61.18 28.12 61.18


8
6 𝑎

9 𝑎1 =

[ ] [ 𝑎2 ] [ ]
10
11 Ans: f(x) = x2

Dr. Amjed Ahmed


Interpolation and Curve Fitting 17 /24

0
1 0 0.5 1 1.5 2 2.5
2
3 (b) Third order polynomial: 𝑓(𝑥) = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + 𝑎3 𝑥 3
𝑎0
𝑛 ∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑥𝑖3 ∑ 𝑦𝑖

∑ 𝑥𝑖 ∑ 𝑥𝑖2 ∑ 𝑥𝑖3 ∑ 𝑥𝑖4 𝑎 1 ∑ 𝑥𝑖 𝑦𝑖


4 =
∑ 𝑥𝑖2 ∑ 𝑥𝑖3 ∑ 𝑥𝑖4 ∑ 𝑥𝑖5 𝑎2 ∑ 𝑥𝑖2 𝑦𝑖
3
[∑ 𝑥𝑖 ∑ 𝑥𝑖4 ∑ 𝑥𝑖5 ∑ 𝑥𝑖6 ] 3
[∑ 𝑥𝑖 𝑦𝑖 ]
[ 𝑎3 ]
5

Point 𝒙𝟓 𝒙𝟔 𝒚𝒙𝟑


6

Dr. Amjed Ahmed


Interpolation and Curve Fitting 18 /24

6 𝑎0

𝑎1
1 =
𝑎2

[ ] [ 𝑎3 ] [ ]
2
3 Example: Fit a second order polynomial to the following data:

x −0.04 0.93 1.95 2.90 3.83 5.00 5.98 7.05 8.21 9.08 10.09
y −8.66 −6.44 −4.36 −3.27 −0.88 0.87 3.31 4.63 6.19 7.40 8.85
4
5 Solution
6 Because the quadratic f (x) = −0.042 x2 + 2.15 x − 8.57 produces the smallest standard
7 deviation, it can be considered as the “best” fit to the data. The plot of our data indicates
8 that the quadratic (solid line) is indeed a reasonable choice for the fitting function.

Dr. Amjed Ahmed


Interpolation and Curve Fitting 19 /24

1 3.3.1 Suitable polynomial order

2 Over-fit
3 We are not sure which order will fit well.
4
6th order
5
2nd order
6
7
8  Linear regression is not suitable.
9  2nd and 6th orders look similar,
10  But 6th order has a squiggle ‫ متعرج‬to it.
11
12
13
14
15 Under-fit: If 1st order is too low, No
16 inflection points ‫نقاط متكسرة‬, 4th order
17
18 But order < 4th is recommended.
19
20
21
22
23
24 ‫االنحراف المعياري غير كافي لتقييم تطابق المنحني فيجب مالحظة شكل وانسياب المنحني‬
25
26 General Rules:
27 1. View results first, Start with linear and increase order until trends are matched.
28 2. Select a polynomial order lower than the number of points.
29

Dr. Amjed Ahmed


Interpolation and Curve Fitting 20 /24

1 Fourth Lecture
2 3.4 Fitting a Non-polynomial
3 The process is similar when fitting to a function that is a polynomial. For instance,
4 𝑓(𝑥) = 𝑎 𝑙𝑛 𝑥 + 𝑏 𝑐𝑜𝑠 𝑥 + 𝑐𝑒 𝑥
5 The adjustable parameters are a, b and c.
𝑛 2
𝑥𝑖 )
6 ∈= ∑(𝑦𝑖 − 𝑎 𝑙𝑛 𝑥𝑖 − 𝑏 𝑐𝑜𝑠 𝑥𝑖 − 𝑐𝑒
𝑖=1

7 The ∈ can be evaluated by take the derivative to a, b, c and then set to zero

𝜕𝜖 𝑥
8 = −2 ∑ 𝑙𝑛𝑥𝑖 (𝑦𝑖 − 𝑎 𝑙𝑛 𝑥𝑖 − 𝑏 𝐶𝑜𝑠 𝑥𝑖 − 𝑐 𝑒 𝑖 ) = 0
𝜕𝑎
𝜕𝜖 𝑥
9 = −2 ∑ 𝐶𝑜𝑠 𝑥𝑖 (𝑦𝑖 − 𝑎 𝑙𝑛 𝑥𝑖 − 𝑏 𝐶𝑜𝑠 𝑥𝑖 − 𝑐 𝑒 𝑖 ) = 0
𝜕𝑏
𝜕𝜖 𝑥 𝑥
10 = −2 ∑ 𝑒 𝑖 (𝑦𝑖 − 𝑎 𝑙𝑛 𝑥𝑖 − 𝑏 𝐶𝑜𝑠 𝑥𝑖 − 𝑐 𝑒 𝑖 ) = 0
𝜕𝑐

11

12 𝑎 ∑(𝑙𝑛 𝑥𝑖 )2 + 𝑏 ∑ 𝑙𝑛 𝑥𝑖 𝑐𝑜𝑠 𝑥𝑖 + 𝑐 ∑ 𝑙𝑛 𝑥𝑖 𝑒 𝑥𝑖 = ∑ 𝑦𝑖 𝑙𝑛 𝑥𝑖

13 𝑎 ∑ 𝑙𝑛 𝑥𝑖 𝑐𝑜𝑠 𝑥𝑖 + 𝑏 ∑(𝑐𝑜𝑠 𝑥𝑖 )2 + 𝑐 ∑ 𝑐𝑜𝑠 𝑥𝑖 𝑒 𝑥𝑖 = ∑ 𝑦𝑖 𝑐𝑜𝑠 𝑥𝑖

14 𝑎 ∑ 𝑙𝑛 𝑥𝑖 𝑒 𝑥𝑖 + 𝑏 ∑ 𝑐𝑜𝑠 𝑥𝑖 𝑒 𝑥𝑖 + 𝑐 ∑(𝑒 𝑥𝑖 )2 = ∑ 𝑦𝑖 𝑒 𝑥𝑖

ln x ln x yi yi
xi yi (ln x)2 (cos x)2 (ex)2 ln x cos x ex cos x ex yi ex
cos x ex ln x cos x
0.24 0.23
0.65 –0.26
0.95 –1.10
1.24 –0.45
1.73 0.27
2.01 0.10
2.23 –0.29
2.52 0.24
2.77 0.56
2.99 1.00

15

Dr. Amjed Ahmed


Interpolation and Curve Fitting 21 /24

1 6.794𝑎 − 5.348𝑏 + 63.259𝑐 = 1.616


2 −5.347𝑎 + 5.108𝑏 − 49.009𝑐 = −2.383
3 63.259𝑎 − 49.009𝑏 + 1002.506𝑐 = 26.773
4
5 When solved by the Gauss-Jordan method, yield
6 a = –1.041, b = –1.261 c = 0.031
7
8 𝒇(𝒙) = −𝟏. 𝟎𝟒𝟏 𝒍𝒏 𝒙 − 𝟏. 𝟐𝟔𝟏 𝒄𝒐𝒔 𝒙 + 𝟎. 𝟎𝟑𝟏𝒆𝒙

0.8

0.3
f(x)

-0.2

-0.7
data
fit
-1.2
0 0.5 1 1.5 2 2.5 3
x

Dr. Amjed Ahmed


Interpolation and Curve Fitting 22 /24

1 Exercises
2 Tip: Plot the data and the fitting function whenever appropriate.
3 1. Use linear regression to find the line that fits the data and determine the standard
4 deviation.

x −1.0 −0.5 0 0.5 1.0


y −1.00 −0.55 0.00 0.45 1.00
5

6 2. Three tensile tests were carried out on an aluminum bar. In each test, the strain was
7 measured at the same values of stress. The results were

Stress (MPa) 34.5 69.0 103.5 138.0


Strain ( Test 1) 0.46 0.95 1.48 1.93
Strain ( Test 2) 0.34 1.02 1.51 2.09
Strain ( Test 3) 0.73 1.10 1.62 2.12
8 Where the units of strain are mm/m. Use linear regression to estimate the modulus of
9 elasticity of the bar (modulus of elasticity = stress/strain).
10

11 3. Solve Prob. 2 assuming that the third test was performed on an inferior machine, so
12 that its results carry only half the weight of the other two tests.
13

14 4. Fit a straight line to the following data and compute the standard deviation.
x 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
y 3.076 2.810 2.588 2.297 1.981 1.912 1.653 1.478 1.399 1.018 0.794
15
16 5. The relative density ρ of air was measured at various altitudes h. The results were:

h (km) 0 1.525 3.050 4.575 6.10 7.625 9.150


ρ 1 0.8617 0.7385 0.6292 0.5328 0.4481 0.3741
17
18 Use a quadratic LS fit to determine the relative air density at h = 10.5 km.
19 6. Kinematic viscosity µk of water varies with temperature T as shown in the table.
20 Determine the cubic that best fits the data, and use it to compute µ at T = 10◦, 30◦, 60◦,
k

21 and 90◦ C.
T (◦ C) 0 21.1 37.8 54.4 71.1 87.8 100
µk (10−3 m2 /s) 1.79 1.13 0.696 0.519 0.338 0.321 0.296

Dr. Amjed Ahmed


Interpolation and Curve Fitting 23 /24

1 7. The table displays the mass M and average fuel consumption φ of motor vehicles. Fit
2 a straight-line φ = a + bM to the data and compute the standard deviation.

Model M (kg) φ (km/liter)


Contour 1310 10.2
Crown Victoria 1810 8.1
Escort 1175 11.9
Expedition 2360 5.5
Explorer 1960 6.8
F-150 2020 6.8
Ranger 1755 7.7
Taurus 1595 8.9
Accord 1470 9.8
CR-V 1430 10.2
Civic 1110 13.2
Passport 1785 7.7
3
4 8. Fit a straight line and a quadratic to the data, which is a better fit.

x 1.0 2.5 3.5 4.0 1.1 1.8 2.2 3.7


y 6.008 15.722 27.130 33.772 5.257 9.549 11.098 28.828
5
6 9. The table shows the variation of the relative thermal conductivity k of sodium with
7 temperature T. Find the quadratic that fits the data in the LS-Method.

T (◦ C) 79 190 357 524 690


k 1.00 0.932 0.839 0.759 0.693
8
9 10. Determine a and b for which f (x) = a sin (π x/2) + b cos (π x/2) fits the following
10 data in the LS-Method.
x −0.5 −0.19 0.02 0.20 0.35 0.50
y −3.55 −2.87 −1.99 −1.04 −0.06 0.677
8 4 5 0 8
11 12. Determine a and b so that f (x) = a xb fits the following data in the LS-Method.
x 0.5 1.0 1.5 2.0 2.5
y 0.49 1.60 3.36 6.44 10.16
12
13
14

Dr. Amjed Ahmed


Interpolation and Curve Fitting 24 /24

1 11. The table displays thermal efficiencies of some early steam engines. Determine the
2 polynomial that provides the best fit to the data and use it to predict the thermal efficiency
3 in the year 2000.

Year Efficiency (%) Type


1718 0.5 Newcomen
1767 0.8 Smeaton
1774 1.4 Smeaton
1775 2.7 Watt
1792 4.5 Watt
1816 7.5 Woolf compound
1828 12.0 Improved Cornish
1834 17.0 Improved Cornish
1878 17.2 Corliss compound
1906 23.0 Triple expansion
4

5 13. Fit the function f (x) = axebx to the data and compute the standard deviation.
x 0.5 1.0 1.5 2.0 2.5
y 0.541 0.398 0.232 0.106 0.052
6
7 14. The intensity of radiation of a radioactive substance was measured at half-year
8 intervals. The results were:
t (years) 0 0.5 1 1.5 2 2.5
γ 1.000 0.994 0.990 0.985 0.979 0.977
t (years) 3 3.5 4 4.5 5 5.5
γ 0.972 0.969 0.967 0.960 0.956 0.952
9
10 Where γ is the relative intensity of radiation. Knowing that radioactivity decays

11 exponentially with time: γ (t) = ae−bt, estimate the radioactive half-life of the substance.

Dr. Amjed Ahmed

You might also like