CE 205: Numerical Methods
2.00 Credits, 2hrs/week
Dr. Tanvir Ahmed
Assistant Professor
What are Numerical Methods?
Techniques by which mathematical problems are formulated
so that they can be solved with simple arithmetic operations
Addition (+)
(+), Subtraction(
Subtraction(-),
) Division (/)
(/), Multiplication (*)
This may involve a large number of tedious calculations
Thanks to digital computers!!
CE 205: Numerical Methods Dr. Tanvir Ahmed
Example: Newton’s 2nd law of motion
F = ma
The Bungee Jumper Problem
the change in velocity is determined by the
gravitational forces acting on the jumper
versus the drag force.
dv cd 2
= g− v
dt m
cd = drag coefficient
m = mass of the jumper
g = gravitational acceleration
CE 205: Numerical Methods Dr. Tanvir Ahmed
Analytical solution
dv cd 2 gm ⎛ gc ⎞
= g− v v(t) = tanh⎜ d
t⎟
dt m cd ⎝ m ⎠
Considering
m = 68.1 kg
cd = 0.25
0 25 kkg/m
/
CE 205: Numerical Methods Dr. Tanvir Ahmed
Numerical solution
Need to make some approximation regarding the time rate
change of velocity
dv Δv v(ti+1) − v(ti )
≈ =
dt Δt ti+1 − ti
dv cd 2
=g− v
dt m
cd
v(ti+1) = v(ti) + g − v(ti)2 (ti+1 − ti)
m
CE 205: Numerical Methods Dr. Tanvir Ahmed
Comparison with analytical solution
cd
v(ti+1) = v(ti) + g − v(ti)2 (ti+1 − ti)
m
CE 205: Numerical Methods Dr. Tanvir Ahmed
Why learn numerical methods?
•Analytical solutions can be derived for only a limited class of
problems.
problems
•A broad spectrum of problems can be solved.
- complicated,
p nonlinear p
problems
- large systems of equations
•Intelligently use commercially available computer programs
(“packages”)
•To make your own customized program to tackle problems
which p packages
g cannot solve
•Bolster your understanding of mathematics
CE 205: Numerical Methods Dr. Tanvir Ahmed
Computers and numerical methods practice
Pre computer Computer era
era
CE 205: Numerical Methods Dr. Tanvir Ahmed
Historical evidence of numerical approximation
Babylonian tablet BC 7289, which gives a sexagesimal
numerical approximation of square root of 2
2 = 1 + 24 + 51 2 + 10 3 = 1.41421296...
60 60 60
CE 205: Numerical Methods Dr. Tanvir Ahmed
Modern applications
• Numerical weather prediction
• C
Computing
ti th
the ttrajectory
j t off a spacecraft
ft (requires
( i the
th
solution of a system of ODE)
• Simulations of car crashes by car companies
(Numerical PDE solution)
• Sophisticated optimization algorithms to decide ticket
prices, airplane and crew assignments and fuel f needs.
• Insurance companies use numerical programs for
actuarial analysis
analysis.
• And many more….
CE 205: Numerical Methods Dr. Tanvir Ahmed
CE205 Course Outline
•Systems
y of linear algebraic
g equations
q
•Interpolation and Curve-fitting
•Roots of Equations
•Numerical differentiation
•Numerical integration
•Initial value problems
•Two-point boundary value problems
CE 205: Numerical Methods Dr. Tanvir Ahmed
References
•Any standard undergraduate textbook on Numerical
Methods
•Some examples:
-Numerical Methods for Engineers: Chapra & Canale
-Numerica
Numerica Methods: E Balagurusamy
-Introductory Methods of Numerical Analysis: Sastry
-Numerical Analysis: Goel and Mittal
CE 205: Numerical Methods Dr. Tanvir Ahmed
Characteristics of Numerical Computing
•Accuracy (all numerical methods introduce errors)
- truncation errors
- round
round-off
off errors
•Rate of convergence (how quickly we can arrive at
a solution)
•Numerical stability
•Efficiency (computational burden)
CE 205: Numerical Methods Dr. Tanvir Ahmed
Errors in Numerical Methods
In numerical methods, approximations are used to express
exact mathematical operations
This gives rise to errors errors
How can we quantify it?
True error (Et) = True value - approximation
Percent relative error (εt) = (True error (Et) / True value)*100
CE 205: Numerical Methods Dr. Tanvir Ahmed
Errors in Numerical Methods
If the problem cannot be analytically solved, the true value
will not be known
We normalize the error with t
true error
approximate value
Numerical methods use
an iterative approach
- Present approximation
pp is made based on p
previous approximation
pp
CE 205: Numerical Methods Dr. Tanvir Ahmed
Errors in Numerical Methods
Use absolute value
Continue computations until a stopping criterion is
satisfied
ti fi d
εa < εs A prespecified tolerance level
The criteria used to ensure that the result is correct upto n
significant figures:
ε s = (0.5 ×10 2− n )%
CE 205: Numerical Methods Dr. Tanvir Ahmed
Roundoff errors
Quantities such as π, 1/3 cannot be expressed by a fixed
number of significant figures
Roundoff
R d ff errors arise
i b because di
digital
it l computers
t cannott
represent some quantities exactly.
- Digital computers have size and precision limits on their ability to
represent numbers.
- Certain numerical manipulations are highly sensitive to roundoff
errors
CE 205: Numerical Methods Dr. Tanvir Ahmed
Truncation errors
Result from the use of approximations instead of exact
mathematical procedures.
Example: using finite number of terms to estimate the sum of
an infinite series, say
x3 x5 x7
sin x = x − + − + ...
3! 5! 7!
Another example: using discrete steps in the solution of a
differential equation
dv Δv v(t i+1) − v(t i )
≅ =
dt Δt t i+1 − t i
CE 205: Numerical Methods Dr. Tanvir Ahmed
How to quantify truncation errors
The Taylor series: any smooth function can be approximated
as a polynomial
f '' ( xi ) 2 f (3) ( xi ) 3 f ( n ) ( xi ) n
f ( xi +1 ) = f ( xi ) + f (xi )h +
'
h + h +L+ h + Rn
2! 3! n!
remainder term is
of the order hn+1
The more terms are used,
used the smaller the error
smaller the spacing, smaller the error for a given number of terms.
CE 205: Numerical Methods Dr. Tanvir Ahmed
Truncation errors
P bl
Problem 1.
1 f ( x ) = −0.1x 4 − 0.15 x 3 − 0.5 x 2 − 0.25 x + 1.2
Use the Taylor’s series to approximate xi+1 using h = 1 and xi = 0.
Compare your results and the truncation error for 0-th
0-th, 1st and 2nd
order approximations.
Problem 2.
The Mclaurin series expansion for sinx is the following:
x3 x5 x7
sin x = x − + − + ...
3! 5! 7!
Starting from sinx = x, add terms one at a time to estimate sin(π/3).
Compute the true
true, approximate % relative errors at each step after
a new term is added.
CE 205: Numerical Methods Dr. Tanvir Ahmed
Truncation errors
f ( xi +1 ) = f ( xi ) + f ' ( xi )h +
f ''
( xi ) h2 +
f ( 3)
( xi ) h3 + L +
f (n)
(xi ) h n + R
n
2! 3! n!
The first order Taylor series is used to approximate the derivative
(e.g. the bungee jumper problem)
f (x i+1 ) = f (x i ) + f ' (x i )h + O(h 2 )
f (x i+1 ) − f (x i ) dv Δv v(t i+1) − v(t i )
≅ =
f (x i ) =
'
+ O(h)
h dt Δt t i+1 − t i
This is also called “Forward Difference” because it uses the
data at i and i+1 to estimate the derivative
CE 205: Numerical Methods Dr. Tanvir Ahmed
Numerical Differentiation
There are also backward and centered
difference approximations, depending
on the
th points
i t used:
d
Forward:
( i+1 ) − f (x
f (x ( i)
f (x i ) =
'
+ O(h)
h
Backward:
f (x i ) − f (x i−1 )
f (x i ) =
'
+ O(h)
h
Centered
Centered:
f (x i+1 ) − f (x i−1 )
f (x i ) =
'
+ O(h 2 )
2h
CE 205: Numerical Methods Dr. Tanvir Ahmed
Problem: T.E. in numerical diff.
f ( x ) = −0.1x 4 − 0.15 x 3 − 0.5 x 2 − 0.25 x + 1.2
Using forward, backward and centered differences, calculate the
derivative of f(x) using step size of h = 0
0.5
5 and h = 0
0.25.
25 Compute
the truncation errors for each of the methods applied.
CE 205: Numerical Methods Dr. Tanvir Ahmed
Total Numerical Error
The total numerical error is the summation of the truncation
and roundoff errors.
The truncation error generally increases as the step size
increases, while the roundoff error decreases as the step size
increases - this leads to a point of diminishing returns for step
size.
CE 205: Numerical Methods Dr. Tanvir Ahmed
Other Errors
Blunders - errors caused by malfunctions of the computer or
human imperfection.
Model errors - errors resulting from incomplete mathematical
models.
models
Data uncertaintyy - errors resulting
g from the accuracyy and/or
precision of the data.
CE 205: Numerical Methods Dr. Tanvir Ahmed