0% found this document useful (0 votes)
7 views26 pages

Numerical Methods in Engineering Course

Uploaded by

he21no07k
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views26 pages

Numerical Methods in Engineering Course

Uploaded by

he21no07k
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Debre Berhan University

College of Engineering

Department of Chemical Engineering

Course Title: Numerical Methods (Course Hand out)

Course Code: ChEg3041

Instructor:

Tsegay G/Medhin (MSc.)

March 15, 2025

Debre Berhan, Ethiopia


1 Introduction to Numerical Methods

Definition
Numerical methods are techniques to approximate mathematical processes
(examples of mathematical processes are integrals, differential equations, nonlinear
equations) that are not solvable analytically or are too complex to solve directly.
Solving scientific, engineering, and other problems often requires the use of
numerical methods and computers.
Why Learn Numerical Methods?
Analytical Limitations: Some equations (like higher-order polynomials or
integrals) cannot be solved exactly.
Practical Applications: Problems such as analyzing trusses or solving
simultaneous equations in engineering require computational approaches
➢ Importance of Numerical Methods
1. Real-World Applications: Many mathematical models used in physics,
engineering, finance, and other fields cannot be solved analytically.
Numerical methods enable practical solutions.
2. Computational Efficiency: It focuses on creating algorithms that can
efficiently utilize computer resources to solve large-scale problems, making it
essential in the age of big data.
3. Ease of Use: With the advent of powerful computing tools and languages, the
implementation of numerical methods has become easier. A clear example is
Python, which specializes in scientific computing and data analysis.
4. Flexibility: Whether your equation is linear or nonlinear, a single variable or
multivariate, numerical root finding is flexible enough to tackle the problem
adeptly.
➢ Numerical methods are applied to the following main topics:
 Roots of nonlinear equations
 Solving simultaneous linear and non-linear equations
 Curve fitting through interpolation and regression
 Numerical differentiation and integration
 Solving ordinary differential equations

There is no single best method because there are many tradeoffs that must be
considered when applying the methods. The Numerical Methods available to solve
any particular type of problem involve the type of trade offs

a. The number of initial guesses or starting points


b. Rate of convergence (some converges rapidly than others) faster is not always
better.
c. Stability (may not be always diverge/converge)
d. Accuracy and precision (some Numerical methods are more accurate or
precise than others e.g the various equations of numerical integration.
e. Applicability (limited class of problems)
f. Ease of application
1.1 Mathematical Modeling and Engineering Problem solving
• Requires understanding of engineering systems
– By observation and experiment
– Theoretical analysis and generalization
• Computers are great tools, however, without fundamental understanding of
engineering problems, they will be useless.
Fig 1.1: The Engineering Problem Solving Process

• Numerical methods are used by engineers and scientists to solve problems.


However, numerical methods are just one step in solving an engineering
problem. There are four steps for solving an engineering problem.

• The first step is to describe the problem. The description would involve
writing the background of the problem and the need for its solution. The
second step is developing a mathematical model for the problem, and this
could include the use of experiments or/and theory. The third step involves
solving the mathematical model. The solution may consist of analytical or/and
numerical means. The fourth step is implementing the solution to see if the
problem is solved.

• A mathematical model can be broadly defined as a formulation or equation


that expresses the essential features of a physical system or process in
mathematical terms.

• Models are used to predict the dependent variables as a function of


independent v, parameters, and forcing functions.

• A mathematical model is represented as a functional relationship of the form

Dependent Variable = f  Independent variable,Parameters,forcingfunctions............Eq(1.1)

• Dependent variable: Characteristic that usually reflects the state of the system
behavior

• Independent variables: Dimensions such as time and space along which the
systems behavior is being determined.

• Parameters: reflect the system’s properties or composition

• Forcing functions: external influences acting upon the system

For example; on the basis of observations, Newton formulated his


Newton’s 2nd law of Motion, which:

• States that “the time rate change of momentum of a body is


equal to the resulting force acting on it.”
• The model is formulated as
F = m a ……………………………………………………..… Eq(1.2)
F=net force acting on the body (N)
m=mass of the object (kg)
2
a=its acceleration (m/s )
The second law can be recast in the format of Eq(1.1) by merely dividing
both sides by m to give
𝐹
𝑎= ………………………………………………………….. Eq (1.3)
𝑚

Where, a= the dependent variable, F= forcing function and m = a


parameter representing the property of the system. Note that for this
simple case there is no independent variable because we are not yet
predicting how acceleration varies in time or space.
nd
➢ Formulation of Newton’s 2 law has several characteristics that are
typical of mathematical models of the physical world:
– It describes a natural process or system in
mathematical terms
– It represents an idealization and simplification of
reality
– Finally, it yields reproducible results, consequently,
can be used for predictive purposes.
• Some mathematical models of physical phenomena may be
much more complex.
• Complex models may not be solved exactly or require more
sophisticated mathematical techniques than simple algebra for
their solution
• To illustrate a more complex model of this kind, Newton’s 2nd
law can be used to determine the terminal velocity of a free -
falling body near the earth’s surface. Our falling body will be a
parachutist.
– modeling of a falling parachutist:

dv F
= Eq (1.4)
dt m

F = FD + FU Eq (1.5)
FD = mg Eq (1.6)
FU = −cv Eq (1.7)
dv mg − cv
= Eq (1.8)
dt m

dv c
=g− v Eq(1.9)
dt m

• This is a differential equation and is written in terms of the differential rate of


change dv/dt of the variable that we are interested in predicting.
• If the parachutist is initially at rest (v=0 at t=0), using calculus
Independent variable

v(t ) =
gm
c
(1 − e− ( c/ m)t ) Eq (1.10)

Parameters
Dependent variable Forcing function

Example 1: A parachutist of mass 68.1kg jumps out of a stationary hot air balloon.
Use the above equation to compute the velocity for every two seconds. The drag
coefficient is equal to 12.5kg/s. Analytical Solution:

v(t ) =
gm
c
( (
1 − e − ( c / m ) t ) = v(t ) = 53.39 1 − e−0.18355t )
t,s 0 2 4 6 8 10 12 ∞
V(m/s) 0 16.40 27.77 35.64 41.10 44.87 47.49 53.39

According to the model, the parachutist accelerates rapidly. A velocity of 44.87m/s


is attained after 10s. Note also that after a sufficiently long time, a constant velocity
called the terminal velocity of 53.39m/s is reached. This velocity is constant because,
eventually the force of gravity will be in balance with the air resistance. Thus, the
net force is zero and acceleration has ceased.
The above equation is called an analytical or exact solution b/c it exactly satisfies
the original differential equation. Unfortunately, there are many mathematical
models that cannot be solved exactly. In many of these cases the only alternative is
to develop a numerical solution that approximates the exact solution. As mentioned
previously, numerical methods are those in which the mathematical problem is
reformulated so it can be solved by arithmetic operations.

To illustrate this for newton’s second law by realizing that the time rate of change of
velocity can be approximated by: Fig (1.4)

Fig 1.2 The use of finite difference to approximate the first derivative of v with respect to t

dv v v(ti + 1) − v(ti )
 = Eq (1.11)
dt t ti + 1 − ti
𝑑𝑣 Δ𝑣
Note that ≅ is approximate because ∆𝑡 is finite.
𝑑𝑡 Δ𝑡

Eq (1.11) is called a finite divided difference approximation of the derivative at time


ti. It can be substituted into Eq(1.9) to give

v(ti + 1) − v(ti ) c
= g − v(ti )
ti + 1 − ti m
This equation can then be rearranged to yield

 c 
v(ti + 1) = v (ti ) +  g − v (ti )  ( ti + 1 − ti ) Eq (1.12)
 m 

Thus, the differential equation has been transformed into an equation that can be
used to determine the velocity algebraically at ti-1 using the slope and previous
values of v and t. if you are given an initial value for velocity at some time ti, you
can easily compute velocity at later time ti+1. This new value of velocity at time ti+1
can in turn be employed to extend the computation to velocity at time ti+2 and so
on. Thus, at any time along the way,

New value = old value + slope × step size

Note that this approach is formally called Euler’s Method.

Example 2 Apply numerical solution to the problem in Example 1.


Perform the same computation but use Eq (1.12) to compute the velocity. Employ a
step size of 2 s for the calculation. At the start of the computation (ti = 0), the velocity
of the parachutist is zero. So, the velocity at ti+1 = 2 s.

12.5
V = 0 + [9.8 − (0)] ∗ 2 = 19.60𝑚/𝑠
68.1

For the next interval t = 2 to 4 s, the computation is repeated, with the result

12.5
V = 19.60 + [9.8 − (19.60)] ∗ 2 = 32.00𝑚/𝑠
68.1

The calculation is continued in a similar fashion to obtain additional values.

t,s 0 2 4 6 8 10 12 ∞
v(m/s) 0 19.60 32.00 39.85 44.82 47.97 49.96 53.39
The results are plotted in Fig 1.5 along with the exact solution. It can be seen that
the numerical method captures the essential features of the exact solution. However,
because we have employed straight line segments to approximate a continuously
curving function, there is some discrepancy between the two results.
One way to minimize such discrepancy is to use a smaller step size. For example,
applying Eq (1.12) at a 1s interval results in a smaller error, as the straight-line
segments track closer to the true solution.
Using hand calculations, the effort associated with using smaller and smaller step
sizes would make such numerical solutions impractical. However, with the aid of
the computer, large number of calculations can be performed easily. Thus, you can
accurately model the velocity of the falling parachutist without having to solve the
differential equation exactly. Thus, there is a tradeoff b/n accuracy and
computational effort.

Fig 1.3 Comparisons of the numerical and analytical solutions for the falling parachutist problem
Suppose that we started a computation at t = 0, and wanted to predict the
velocity at t = 4 s using a time step of ∆𝑡 = 0.5 𝑠. We would therefore need to
apply Eq 1.12 eight times, that is
4
N= = 8, where N = number of iterations of the loop. Because the result is exact,
0.5

i.e, the ratio is an integer.


1.2 Conservation Laws and Engineering (for predicting changes)
❖ Conservation laws are the most important and fundamental laws that are
used in engineering.

Change = increases – decreases Eq (1.13)

• Change implies changes with time (transient). If the change is nonexistent


(steady-state), Eq. 1.13 becomes

Increases =Decreases Eq (1.14)

Fig 1.4 A flow balance for steady incompressible fluid flow at the junction or pipes
• For steady-state incompressible fluid flow in pipes:

Flow in = Flow out

or

100 + 80 = 120 + Flow


4

Flow = 60
4

Most of the chemical engineering applications will focus on mass balance for
reactors. The mass balance is derived from the conservation of mass.
1.3 Approximations and Errors
➢ For many engineering problems, we cannot obtain analytical
solutions.
➢ Numerical methods yield approximate results, results that are
close to the exact analytical solution. Thus, we cannot exactly
compute the errors associated with numerical methods.
– Only rarely given data are exact, since they originate from
measurements. Therefore, there is probably error in the input
information.
– Algorithm itself usually introduces errors as well, e.g.,
unavoidable round-offs, etc…
– The output information will then contain error from both of
these sources.
1.3.1 Error Definitions
Numerical errors arise from the use of approximations to represent exact
mathematical operations and quantities. These include truncation errors, which
result when approximations are used to represent exact mathematical procedures,
and round of errors, which result when numbers having limited significant figures
are used to represent exact numbers.

Round-off Errors

• Is due to the fact that computers can represent only quantities with a finite
number of digits during a calculation

• Numbers such as pi, e, or 7 cannot be expressed by a fixed number of


significant figures. Therefore, they cannot be represented exactly by the
computer.
• In addition, because computers use a base - 2 representation, they cannot
precisely represent certain exact base-10 numbers.
• The discrepancy introduced by this omission of significant figures is
called round-off errors.
Chopping

Example:

p=3.14159265358 to be stored on a base-10 system carrying 7 significant digits.

p=3.141592 chopping error e =0.00000065


t

If rounded

p=3.141593 e =0.00000035
t

▪ Some machines use chopping, because rounding adds to the computational


overhead. Since number of significant figures is large enough, resulting
chopping error is negligible.
Total number error: the total number error is the summation of the truncation and
round off errors.
NB: In general, the only way to minimize round off errors is to increase the number
of significant figures of the computer. In addition, the truncation error can be reduced
by decreasing the step size. The truncation errors are decreased the round off errors
are increased.
For both types, the relationship between the exact or true result and the
approximation can be formulated as

True Value = Approximation + Error Eq 1.31

By rearranging Eq 3.1, we find that the numerical error is equal to the discrepancy
between the truth and the approximation as in
Et = True value – Approximation (+/-) Eq 1.32

True error
true error
True fractional relative error =
true value
true error
True percent relative error,  t = 100%
true value Eq 1.33
➢ For numerical methods, the true value will be known only when we deal with
functions that can be solved analytically (simple systems). In real world
applications, we usually not know the answer a priori. Then

 a = Approximate error 100%


Approximation
• Certain Numerical methods use an Iterative approach, to compute the errors.
So, percent relative error is determined according to the formula given below.

 a = Current approximation - Previous approximation 100%


Current approximation
The signs of the error may be either positive or negative. Often, when performing
computations, we may not be concerned with the sign of the error, but we are
interested in whether the percent absolute value is lower than a prespecified percent
tolerance 𝜀 s.

• Use absolute value.

• Computations are repeated until stopping criterion is satisfied.


 a  s Pre-specified % tolerance based on
the knowledge of your solution

It is also convenient to relate these errors to the number of significant figures in the
approximation.

• If the following criterion is met,

 s = (0.5  10(2-n) )% Eq 1.34

▪ you can be sure that the result is correct


to at least n significant figures.
➢ How confident we are in our approximate result?
➢ The question is “how much error is present in our calculation and is it
tolerable?”
1.4 Significant Figures

• Number of significant figures indicates precision. Significant digits


of a number are those that can be used with confidence, e.g., the
number of certain digits plus one estimated digit.
53,800 How many significant figures? Depending on whether the 0’s are
known with confidence. Such uncertainty can be resolved by using scientific
notation.
4
5.38 x 10 3
4
5.380 x 10 4
4
5.3800 x 10 5

▪ Zeros are sometimes used to locate the decimal point not significant figures.
0.00001753 4

0.0001753 4

0.001753 4

➢ The concept of significant figures has two important implications for our
study of numerical methods.
1. Numerical methods yield approximate results. So, we must develop criteria
to specify how confident we are in our approximate result. One way to do
this is in terms of significant figures. For example, we might decide that
our approximation is acceptable if it is correct to four significant figures.
2. Although quantities such as 𝜋, √7, or e represent specific quantities, they
cannot be expressed exactly by a limited number of digits. For example,
𝜋 = 3.141592653589793238462643…
Because computers retain only a finite number of significant figures, such
numbers can never be represented exactly. The omission of the remaining
significant figures is called round off error.
➢ The concept of significant figures will have relevance in our definition of
accuracy and precision.

1.5 Accuracy and Precision


• Accuracy. How closely a computed or measured value agrees with the
true value
• Precision (or reproducibility). How closely individual computed or
measured values agree with each other.
• Inaccuracy (or bias). A systematic deviation from the actual value.
• Imprecision (or uncertainty). Magnitude of scatter.
These concepts can be illustrated graphically, as below
Fig 1.7 an example from marksmanship illustrating the concept of accuracy and
precision. (a) Inaccurate and imprecise, (b) accurate and imprecise, (c) Inaccurate
and precise (d) accurate and precise

• We use a collective term error to represent both the inaccuracy and the
imprecision of our predictions.
Example – 1 error estimate for iterative methods

In mathematics, functions can often be represented by infinite series. For


instance, the exponential function can be computed using Maclaurin
series expansion.
𝑥
𝑥2 𝑥3 𝑥𝑛
𝑒 = 1 + 𝑥 + + + ⋯+
2 3! 𝑛!

Solution: for x = 0.5, the true value is 𝑒 0.5 = 1.648721 … and determine
the error criterion that ensures a result is correct to at least three significant
figures.

𝜀 s = (0.5*10(2−3) ∗ 100% = 0.05%

Thus, as more terms are added in sequence, the approximation becomes a


better and better estimate of the true value of 𝑒 𝑥 . Thus, we will add terms
to the series until 𝜀 a falls below this level.

The first estimate is equals to 1

The second estimate is then generated by adding the second term as in

𝑒 𝑥 = 1 + 𝑥, or for x = 0.5, we obtained 1.5

Then, the true percent relative error becomes


1.648721−1.5
𝜀t = *100% = 9.02%
1.648721

Again, determine an approximate estimate of the error, as in


1.5−1
𝜀a = ∗ 100% = 33.3%
1.5

Because 𝜀 a is not less than the required value of 𝜀 s, we would continue computation
by adding another term and repeating the error calculations. The process is continued
until 𝜀 a < 𝜀 s. The entire computation can be summarized as
Terms Result 𝜀𝑡% 𝜀𝑎%
1 1 39.3
2 1.5 9.02 33.3
3 1.625 1.44 7.69
4 1.645833333 0.175 1.27
5 1.648437500 0.0172 0.158
6 1.648697917 0.00142 0.0158
Thus, after six terms are included, the 𝜀 a falls below 𝜀 s. and the computation is
terminated.

3.4.1 Computer Representation of Numbers


▪ The fundamental unit whereby information is represented is called a word.
This is an entity that consists of a string of binary digits or a bit.
▪ Numbers are typically stored in one or more words.
Number systems: a number system is merely a convention for representing
quantities. Because we have 10 fingers and 10 toes, the number system that we
are most familiar with is the decimal or base 10 number system.
o A base is the number that is used as a reference for constructing the system.
o The base 10 system uses the 10 digits – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to represent
numbers. By themselves these digits are satisfactory for counting from 0
to 9.
o For larger quantities, combinations of these basic digits are used, with the
position or place value specifying the magnitude.
o Fig 3.5a provides the visual representation of how a number is formulated
in the base 10 system. This type of representation is called positional
notation.
o Although base 10 system is so familiar, there are alternative number
systems. Example, numbers on the computer are represented with a binary
or a base 2 system which is 0 and 1.
o As with the decimal system, quantities can be represented using positional
notation. For example, the binary number 11 is equivalent to (1∗ 21 ) + (1∗
20 ) = 2 + 1 = 3 in the decimal system. Fig 3.5b illustrates base 2 system

Fig 3.5 (a) decimal base 10 system (b) binary or base 2 system
Integer representation: how integer are represented in a computer. The most
straightforward approach called the signed magnitude method employs the first bit
of a word to indicate the sign with a 0 for positive and a 1 for negative. The remaining
bits are used to store a number. For example:
Fig 3.6 The representation of the decimal integer -173 on a 16-bit computer using
the signed magnitude method
Example – 2: determine the range of integers in base 10 that can be represented on
a 16-bit computer. Solution
Of the 16-bits, the first bit holds the sign. The remaining 15 bit can hold binary
numbers. When you want to convert to decimal system use 215 − 1 = 32767. This
implies a 16-bit computer word can store decimal integers ranging from -32,767 to
32,767.
Floating point representation
▪ Fractional quantities are typically represented in computer using “floating
point” form. In this approach, the number is expressed as a fractional part
called mantissa and an integer part, called an exponent or characteristic as in

Integer part

[Link] exponent

mantissa Base of the number system used


Fig 3.7 a floating-point number stored in a word. The first bit is reserved for the sign,
the next series of bits for the signed exponent and the last bit for the mantissa.

E.g., 156.78 could be represented as

3
156.78  0.15678x10 in a floating-point base-10 system
1
= 0.029411765
34
1
Suppose only 4 decimal
0.0294 100  m 1
2 places to be stored
• Normalized to remove the leading zeroes. Multiply the
mantissa by 10 and lower the exponent by 1
-1
0.2941 x 10

Additional significant figure is retained


1
 m 1
b
Therefore

for a base-10 system 0.1 ≤m<1

for a base-2 system 0.5 ≤m<1


▪ Floating point representation allows both fractions and very large
numbers to be expressed on the computer. However, it has some
disadvantages.
– Floating point numbers take up more room.
– Take longer to process than integer numbers.
– Round-off errors are introduced because mantissa
holds only a finite number of significant figures.
The Taylor series: The theorem states that any smooth function can be
approximated as a polynomial. If the function f and its first n + 1 derivatives are
continuous on an interval containing xi and xi+1. Then the value of the function at xi+1
is given by

𝑓′′ (𝑥𝑖) 𝑓𝑛 (𝑥𝑖)


F(xi+1) = f(xi) + f′(xi)(xi+1 - xi) + (xi+1 - xi)2 + … + + (xi+1 - xi)n + Rn
2! 𝑛!

Eq 1.15

Where the remainder Rn is defined as


𝑓𝑛+1 ()
Rn = (𝑛+1)!
(xi+1 - xi)n+1

Where  is the value x that lies between xi and xi+1

A remainder term is included to account for all terms from n+1 to infinity.
Eq 1.15 is an infinite series and is commonly called Taylor series expansion formula.
If we define the step size h = xi+1 – xi. Then, we can express as

𝑓′′ (𝑥𝑖) 2 𝑓𝑛 (𝑥𝑖) n


F(xi+1) = f(xi) + f′(xi)h + h +…++ h + Rn and the remainder is now
2! 𝑛!

𝑓𝑛+1 ()
Rn = (𝑛+1)!
hn+1

Exercise

1. The Maclaurin series expansion for 𝑐𝑜𝑠𝑥 is


𝑥2 𝑥4 𝑥6 𝑥8
𝑐𝑜𝑠𝑥 = 1 − + − + −⋯
2 4! 6! 8!

Starting with the smallest version, 𝑐𝑜𝑠𝑥 = 1, add terms one at a time to
𝜋
estimate cos ( ). After each new term is added, compute the true and
3

approximate percent relative errors. Use your pocket calculator to determine


the true value. Add terms until the absolute value of the approximate error
estimate falls below an error criterion conforming to two significant figures.
2. Convert the following base 2 numbers to base 10
a) 1011001
b) 11000101
c) 0.01011

You might also like