Professional Documents
Culture Documents
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 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.
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
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 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
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.
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
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
25
Chapter 4
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 510.
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.
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 106 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 RungeKutta 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)
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.
dy y
dx 1 x
with the initial condition y(0) = 2. Determine y at x = 2.5 using the fourth-order RungeKutta
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.
2
6\ 6TGH
O% 2
6\ '\ 6TGH
O%
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.
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.
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.
O O
M = Mass
of fluid
in tank
TS
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
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
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.
#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
EXAMPLE 4.6 Determine the velocity of the solid particles of diameter 3 ´ 104 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 ´ 105 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 ´ 104 m
vg = 12 m/s
m = 1.8 ´ 105 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
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 RungeKutta 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.
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
§ ·
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
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.
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.
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?
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 RungeKutta fourth order method is given in the
Appendix. The results at step size of 0.1 is shown in Table 4.4.
Table 4.5 Initial conditions and ODEs for batch and plug flow reactors
Initial ODEs 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
#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
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 s1. Using
the RungeKutta 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.
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 s1. Determine the concentration of A at various time periods from
0 to 10 s.
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.
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.
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 s1 and k2 = 1 s1. Using the RungeKutta fourth order method, determine
the concentration of A, B, and C up to 10 s.
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 RungeKutta 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
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 RungeKutta
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 RungeKutta 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
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 s1. Using the RungeKutta 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.
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
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 s1 and k2 = 1 s1. Using the RungeKutta
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.
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
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.
§ ·
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# (
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 : GZR « ¨ ¸ »
F: ¬ © G ¹¼
F\ (
#M § ·
Q¨ ¸
m1
( © ¹ 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
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.
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
Exercises
4.1 Integrate the following ODEs using the RungeKutta 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 ´ 106)
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 RungeKutta 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 ´ 105 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 s1. Using the RungeKutta 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 s1.
(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 s1. Using RungeKutta 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 s1.
(Ans: 0.95123 mol/m3)
82 Introduction to Numerical Methods in Chemical Engineering
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 RungeKutta 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 RungeKutta 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
15 .قيمة اخلطأ من التطابق هو املسافة العمودية بني أي نقطة وخط التطابق واليت يفضل ان تكون اقل قيمة
16 Sum the total minimum error (𝜖) for n points is
26 Based on the calculus, the 𝜖 function can be derivative to a and b, and then set to zero
27 أبخذ املشتقة لكل اثبت ومساواهتا ابلصفر
𝑛
𝜕𝜖
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
∑ 𝑥𝑖 ∑ 𝑦𝑖
1 𝑥̅ = and 𝑦̅ = 5𝑐
𝑛 𝑛
2
3 Standard Deviation (σ) is quantified of the data spread about the fitting curve, as
2
∑𝑛 (𝑦𝑖 − 𝑓(𝑥𝑖 ))
4 𝜎 = √ 𝑖=1 6
𝑛−𝑚
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
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
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:
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
𝑦 = 𝑎 𝑒 𝑏𝑥 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 𝑦 = 𝑎 𝑙𝑛 𝑥 + 𝑏 𝑦 = 𝑎𝑋 + 𝑏 𝑋 = 𝑙𝑛 𝑥
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
1
2 Here is the computation of standard deviation
2
∑(𝑦𝑖 − 𝑓(𝑥𝑖 )) 17.89
3 𝜎=√ =√ = 2.1
𝑛−𝑚 6−2
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
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
7
8
9 It can use the same idea by LS Method,
𝑛
2
10 𝜖 = ∑(𝑦𝑖 − 𝑓(𝑥𝑖 )) 2
𝑖=1
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
𝑛 𝑛 𝑛 𝑛 𝑛
𝑎0
𝑛 ∑ 𝑥𝑖 ∑ 𝑥𝑖2 ⋯ ∑ 𝑥𝑖𝑚 ∑ 𝑦𝑖
1 ∑ 𝑥𝑖4 = ∑ 𝑥𝑖2 𝑦𝑖
∑ 𝑥𝑖2 ∑ 𝑥𝑖3 ⋯ ∑ 𝑥𝑖𝑚+2
⋮ 𝑎2
⋮ ⋮ ⋮ ⋮
∑ 𝑥𝑖𝑚 ∑ 𝑥𝑖𝑚+1 ∑ 𝑥𝑖𝑚+2 ⋯ ∑ 𝑥𝑖𝑚+𝑚 ] [𝑎⋮ ] 𝑚
[ 𝑚 [∑ 𝑥𝑖 𝑦𝑖 ]
2 By Gaussian Elimination to find a0 , a1 , a2 , a3, … am .
3
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
9 10 30 100 𝑎1 = 104
1 Example: Fit a second and third orders polynomial to the following data and the
2 compared standard deviation between these fitting.
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
9 𝑎1 =
[ ] [ 𝑎2 ] [ ]
10
11 Ans: f(x) = x2
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 ∑ 𝑦𝑖
Point 𝒙𝟓 𝒙𝟔 𝒚𝒙𝟑
∑
6
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.
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
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 + 𝑏 ∑ 𝑙𝑛 𝑥𝑖 𝑐𝑜𝑠 𝑥𝑖 + 𝑐 ∑ 𝑙𝑛 𝑥𝑖 𝑒 𝑥𝑖 = ∑ 𝑦𝑖 𝑙𝑛 𝑥𝑖
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
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
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.
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
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:
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
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.
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.
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.