0% found this document useful (0 votes)
4 views

lecture 3 updated

The document outlines the course CHE 358, focusing on numerical methods for chemical engineers, covering topics such as modeling, error analysis, and various methods for solving nonlinear equations. It details learning objectives and methods for root-finding, including graphical methods, iterative methods like bisection, Regula Falsi, fixed-point iteration, Newton-Raphson, and the secant method. Examples are provided to illustrate the application of these methods in locating roots of equations.

Uploaded by

princood70
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

lecture 3 updated

The document outlines the course CHE 358, focusing on numerical methods for chemical engineers, covering topics such as modeling, error analysis, and various methods for solving nonlinear equations. It details learning objectives and methods for root-finding, including graphical methods, iterative methods like bisection, Regula Falsi, fixed-point iteration, Newton-Raphson, and the secant method. Examples are provided to illustrate the application of these methods in locating roots of equations.

Uploaded by

princood70
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

CHE 358

Numerical Methods for


Chemical Engineers
M. MENSAH
Department of Chemical Engineering
KNUST

1
COURSE OUTLINE
• Modelling, Computers & Error Analysis.
• Linear Algebraic & Non-linear Equations.
• Finite difference methods and interpolation.
• Numerical differentiation and integration.
• Numerical solution of ordinary differential equations.
• Numerical solution of partial differential equations.

2
Learning objectives
• At the end of the lecture, students must be able to deal with a wide
variety of engineering problems dealing with roots of equation.

• Students should have mastered the techniques and be capable of


choosing the best method(s) for the solution of any particular non
linear equation problem.

• Understand the difference between bracketing and open methods


for root location.

3
NON-LINEAR EQUATIONS
ROOTS AND THEIR APPROXIMATION
• All nonlinear equations can be written in the general form
𝑓 𝑥 =0 (1.1)
• where x is a single variable that can have multiple values (roots) that satisfy this equation.

• The function 𝑓(𝑥) may assume a variety of nonlinear functionalities such as a polynomial
equation whose canonical form is
𝑓 𝑥 = 𝑎𝑛 𝑥 𝑛 + 𝑎𝑛−1 𝑥 𝑛−1 +. . . +𝑎1 𝑥 + 𝑎0 = 0
• Or transcendental equations, which involve trigonometric, exponential, and logarithmic
terms.
𝑓 𝑥 = 𝑙𝑛𝑥 2 − 1 and 𝑓 𝑥 = 𝑒 −0.2𝑥 sin(3𝑥 − 0.5)

22
NON-LINEAR EQUATIONS
ROOTS AND THEIR APPROXIMATION

• Methods for finding roots of nonlinear equations:

Direct methods
• Gives values of all the roots in a finite number of steps
Eg roots of quadratic equations 𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0, 𝑎 ≠ 0
Can be obtained by:
1
𝑥= −𝑏 ± 𝑏 2 − 4𝑎𝑐
2𝑎

22
GRAPHICAL METHODS
• A simple method for obtaining an estimate of the root of the equation
f (x) = 0 is to make a plot of the function and observe where it crosses
the x axis.
• This point, which represents the x value for which f (x) = 0, provides a
rough approximation of the root.

• Graphical methods are used to provide visual insight to the


techniques.
• They are important for understanding the properties of the functions
and anticipate the pitfalls of the numerical methods.

24
GRAPHICAL METHODS

Fig. 1 is a plot of the polynomial


equation:

𝑥 4 + 6𝑥 3 + 7𝑥 2 − 6𝑥 − 8 = 0

It has four real and distinct roots at


-4, -2, -1, and 1, as indicated by the
intersections of the function with
the x axis.

Figure 1 Roots of fourth-degree polynomial equation


24
NON LINEAR EQUATIONS: Iterative methods
1. Bracketing methods: two initial guesses that brackets the root ie. on
either side of the root. There are two bracketing methods:
a. Bisection(internal halving)/binary chopping/Bolzano’s method
b. False position (Regula falsi)

2. Open Methods: one or more initial guess, no need for them to bracket the
root
a. Fixed-point iteration method
b. Newton-Raphson
c. Secant method
d. Wegsteins’s method
NON LINEAR EQUATIONS
Iterative methods
1a Bisection method
Step 1:
choose lower 𝑥𝑙 and upper 𝑥𝑢 guesses for the root such that the
function changes signs over the interval. This can be checked by
ensuring that 𝑓(𝑥𝑙 ). 𝑓 𝑥𝑢 < 0

Step 2
An Estimate of the root 𝑥𝑟 is determined by
𝑥𝑙 + 𝑥𝑢
𝑥𝑟 =
2
Bisection method
Step 3:
Make the following evaluations to determine in which
subinterval the root lies:
i. 𝑓(𝑥𝑙 ). 𝑓 𝑥𝑟 < 0, the root lies in the lower
subinterval therefore, 𝑥𝑢 = 𝑥𝑟 And return to step 2
ii. If 𝑓(𝑥𝑙 ). 𝑓 𝑥𝑟 > 0 the root lies in the upper
subinterval therefore, 𝑥𝑙 = 𝑥𝑟 And return to step 2
iii. If 𝑓(𝑥𝑙 ). 𝑓 𝑥𝑟 = 0 the root equals 𝑥𝑟 ; terminate
the computation

iv. Approximate percent relative error

𝑥𝑟𝑛𝑒𝑤 − 𝑥𝑟𝑜𝑙𝑑
𝜺𝒂 = 𝑛𝑒𝑤 × 100%
𝑥𝑟
Bisection method

• Example:
• Use the bisection method to find the root of the function below

𝑓(𝑥) = 𝑒 𝑥 𝑠𝑖𝑛𝑥 − 2
on the interval [3,4] given 𝜺𝒔 = 𝟎. 𝟓% (to be solved in class)
1b. Regula Falsi (method of false position/linear
interpolation method)
Step 1:
choose lower 𝑥𝑙 and upper 𝑥𝑢 guesses for the
root such that the function changes signs
over the interval. This can be checked by
ensuring that 𝑓(𝑥𝑙 ). 𝑓 𝑥𝑢 < 0

Step 2
An Estimate of the root 𝑥𝑟 is determined by
𝑓(𝑥𝑢 ) (𝑥𝑙 − 𝑥𝑢 )
𝑥𝑟 = 𝑥𝑢 −
𝑓 𝑥𝑙 − 𝑓(𝑥𝑢 )

NB: Step 3 continues in the same manner as the


bisection method
Regula Falsi method

Try:
• Use the Regula Falsi method to find the root of the function below

𝑓(𝑥) = 𝑒 𝑥 𝑠𝑖𝑛𝑥 − 2
on the interval [3,4] given 𝜺𝒔 = 𝟎. 𝟓%
Fixed-point iteration method
• The simplest one-point iterative root-finding technique
can be developed by rearranging the function 𝑓(𝑥) so
that x is on the left-hand side of the equation
𝑥=𝑔 𝑥 (3.1)
• The function 𝑔(𝑥) is a formula to predict the root.
• This transformation can be obtained by algebraic
manipulation or by adding x to both sides of the
equation
• For example:
sin 𝑥 = 0 becomes 𝑥 = 𝑠𝑖𝑛𝑒 𝑥 + 𝑥
𝑒 −𝑥 − 𝑥 = 0 becomes 𝑥 = 𝑒 −𝑥 NB: Fixed point Iteration will
• Starting with an initial value of xi, we obtain the value of only converge if
xi+1: 𝒈′ 𝒙 < 𝟏
𝑥𝑖+1 = 𝑔 𝑥𝑖 (3.12)
Fixed-point iteration method
• Example
Use fixed point iteration to locate the root of 𝑓 𝑥 = 𝑒 −𝑥 − 𝑥

Solution:
The function can be separated directly into 𝑥𝑖+1 = 𝑒 −𝑥𝑖

Starting with an initial guess of 𝑥0 = 0 .


𝑥1 = 𝑒 −0 = 1; 𝑥2 = 𝑒 −1 = 0.367879; 𝑥3 = 𝑒 −0.367879 = 0.692201;

𝑥4 = 𝑒 −0.692201 = 0.500473; 𝑒𝑡𝑐


Fixed-point iteration method
Solution continued:

Thus each iteration brings the estimate closer to the true value of 0.56714329
TEST 2

Employ the fixed point iteration to locate the root of


𝑓 𝑥 = sin( 𝑥) − 𝑥

Use an initial guess of 𝑥0 = 0.5 and iterate until 𝜀𝑎 ≤ 0.5%.


If the true root is 0.76865, find the relative true error of the root
computed above.

(NB: Work in Radians) 12 mins


THE NEWTON-RAPHSON METHOD

• The most widely used, technique • If the initial guess at the root is xi, a
for locating roots of nonlinear tangent can be extended from the
equations is the Newton-Raphson point [xi, f(xi)].
method. • The point where this tangent
crosses the x axis usually represents
an improved estimate of the root
(xi+1).
′ 𝑓 𝑥𝑖 −0
• 𝑓 𝑥𝑖 = rearranging
𝑥𝑖 −𝑥𝑖+1
gives:

𝑓(𝑥𝑖 )
𝑥𝑖+1 = 𝑥𝑖 − (4.1)
𝑓′ (𝑥𝑖 )
33
THE NEWTON-RAPHSON METHOD
• Newton-Raphson method can also be derived from the Taylor series.
′′ 𝒏

𝒇 𝒙 𝒊 2
𝒇 𝒙𝒊 𝒏
𝒇 𝒙𝒊+𝟏 = 𝒇 𝒙𝒊 + 𝒇 𝒙𝒊 (𝑥𝑖+1 − 𝑥𝑖 ) + (𝑥𝑖+1 − 𝑥𝑖 ) + ⋯ + 𝒉 + 𝑹𝒏
𝟐! 𝒏!

• An approximate version is obtainable by truncating the series after the first derivative
term. At an intersection with the x-axis, 𝒇 𝒙𝒊+𝟏 = 𝟎

0 = 𝒇 𝒙𝒊 + 𝒇′ 𝒙𝒊 (𝑥𝑖+1 − 𝑥𝑖 )

𝑓(𝑥𝑖 )
• Rearranging results 𝑥𝑖+1 = 𝑥𝑖 − ′
𝑓 (𝑥𝑖 )

NB: Newton-Raphson method performs poorly for some selected functions (slow
convergence) as its convergence depends on the nature of the function and on the accuracy
of the initial guesses. Initial guess must be sufficiently close to the root as possible.
35
EXAMPLE

Use the Newton-Raphson method to estimate the root of


𝑓(𝑥) = 𝑒 −𝑥 − 𝑥, employing an initial guess of 𝑥0 = 0.

37
SOLUTION

• The first derivative of the function can be evaluated as

𝑓 ′ 𝑥𝑖 = −𝑒 −𝑥𝑖 − 1

• Which can be substituted with the original function into


Eqs. (4.1) to give

𝑒 −𝑥𝑖 − 𝑥𝑖 Thus, the approach rapidly


𝑥𝑖+1 = 𝑥𝑖 −
−𝑒 −𝑥𝑖 − 1 converges on the true
root.
• Starting with an initial guess of 𝑥0 = 0, this iterative
equation can be applied to compute
37
THE SECANT METHOD

• A potential problem in implementing


the Newton-Raphson method is the ′
• 𝑓 𝑥𝑖 ≅
𝑓 𝑥𝑖−1 −𝑓 𝑥𝑖
(4.2)
evaluation of the derivative. 𝑥𝑖−1 −𝑥𝑖

• There are certain functions whose


derivatives may be extremely difficult
or inconvenient to evaluate.
• For these cases, the derivative can be
approximated by a backward finite
divided difference, as in (Fig.4.3).

38
Graphical depiction of the secant method.
THE SECANT METHOD

• This approximation can be substituted into the newton Raphson formulae


to yield

𝑓(𝑥𝑖 )(𝑥𝑖−1 −𝑥𝑖 )


• 𝑥𝑖+1 = 𝑥𝑖 − (4.3)
𝑓 𝑥𝑖−1 −𝑓(𝑥𝑖 )

• Equation (4.3) is the formula for the secant method.

• Notice that the approach requires two initial estimates of x, ie 𝑥𝑖 and


𝑥𝑖−1 40
EXAMPLE

Use the secant method to estimate the root


−𝑥
of 𝑓 𝑥 = 𝑒 − 𝑥. Start with initial
estimates of 𝑥−1 = 0 and 𝑥0 = 1.0.

41
Finite divided difference
• From the Taylor series first derivatives can be approximated numerically by
truncating the expansion after the first term. This can be done in 3 ways:

1. Forward divided difference: Calculates the derivative based on the


current value and the next value. ie it utilizes the data at 𝑥𝑖 and 𝑥𝑖+1

𝒇 𝒙𝒊+𝟏 = 𝒇 𝒙𝒊 + 𝒇′ 𝒙𝒊 (𝑥𝑖+1 − 𝑥𝑖 )

𝒇 𝒙𝒊+𝟏 −𝒇 𝒙𝒊
𝒇′ 𝒙𝒊 = or
(𝑥𝑖+1 −𝑥𝑖 )

𝒇 𝒙𝒊+𝟏 −𝒇 𝒙𝒊
𝒇′ 𝒙𝒊 =
𝒉
Finite divided difference
2.Backward divided difference: Calculates the derivative based on the
previous value and current value. It utilizes the data at 𝑥𝑖−1 and 𝑥𝑖


𝒇 𝒙𝒊 − 𝒇 𝒙𝒊−𝟏
𝒇 𝒙𝒊 ≅
𝒉
Finite divided difference
3. Centered difference approximation: Calculates the derivative based
on step values on both sides of the point. It utilizes the data at 𝑥𝑖−1 and
𝑥𝑖+1

𝒇 𝒙𝒊−𝟏 − 𝒇 𝒙𝒊+𝟏
𝒇′ 𝒙𝒊 ≅
𝟐𝒉
Example:

Use the forward and backward difference and centered approximation to


estimate the first derivative of

𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2


At x=0.5 using a step size h=0.5. Calculate the true error in each case if
the true value is -0.9125.

Repeat the computation using h=0.25


Try:
A batch reactor was charged with reactant A, at Time(t, min) Concentration
(CA, mol/L)
time t=0 at a concentration of 1.0mol/L. as the
assumed first order reaction evolved, the
concentration were recorded over time. 0 1

5 0.84

10 0.72
Use the centered finite approximation to estimate 30 0.47
𝑑𝐶𝐴 (𝑡)
45 0.37
𝑑𝑡
At t=20 min using a step size h=10. 60 0.3

You might also like