Introduction to
Numerical
Methods
Numerical Methods (ME 212)
Author:Dr.ShoebAhmed Syed
Papua New Guinea University of Technology
Department of Mechanical Engineering
1
Problem(cont.)
Theshift calculatedin the rangingsystem
ofthe missilewas 687 meters.
•
•Thetargetwas consideredto beout of
137rangeat
meters.
adistancegreaterthan
8
Some disasters caused by
numerical errors?
➢Explosion of the Ariane 5
➢EURO page: Conversion Arithmetic's
➢The Vancouver Stock Exchange
➢Rounding error changes Parliament makeup
Truncationerror
•Errorcausedbytruncatingor
mathematicalapproximating
procedure.
a
ExampleofTruncationError
Takingonly a fewtermsofaMaclaurinseriesto
e
x
approximate
2 3
x x
e
x
=1+x+++....................
2!3!
Ifonly 3 termsareused,
x
2
x
Error=e −1+x+
Truncation
2!
AnotherExampleof Truncation
Error
f(x)xUsingafinite toapproximate
f(x+x)−f(x)
f(x)
x
P
ine
Figure1.Approximatederivativeusing finiteΔx
secant line
tangent l
Q
AnotherExampleof Truncation
Error
Usingfinite
integral.
rectanglestoapproximatean
y
90
y =x
2
60
30
0 x
0 1.5 3 4.5 6 7.5 9 10.5 12
Example1—Maclaurinseries
e
1.2
Calculatethevalueofwithanabsolute
relativeapproximateerroroflessthan1%.
2 3
=1+1.2+
1.2
+
1.2
e
1.2
+...................
2!3!
6termsarerequired.Howmanyarerequiredtoget
atleast1 significantdigitcorrectinyouranswer?
n
e
1.2
E
a
a%
1 1
2 2.2 1.2 54.545
3 2.92 0.72 24.658
4 3.208 0.288 8.9776
5 3.2944 0.0864 2.6226
6 3.3151 0.020736 0.62550
Example2—Differentiation
f(x+x)−f(x)
x
2
f(x)=f(3)Find
and
for usingf(x)
x
x=0.2
f(3+0.2)−f(3)
f
'
(3)=
0.2
f(3.2)−f(3)
2 2
3.2 −3 10.24−9 1.24
0.2
== 6.2= ==
0.2 0.2 0.2
Theactualvalueis
f
'
(x)=2x,f
'
(3)=23=6
Truncationerroristhen,6−6.2=−0.2
Canyou find thetruncationerrorwithx=0.1
Example3—Integration
Usetworectanglesofequalwidthto
approximatethearea underthecurvefor
overtheinterval[3,9]x
2
(x)=f
9
3
x
2
dx
y
90
y=x
2
60
30
0 x
0 3 6 9 12
PropagationofErrors
Innumerical methods,the calculations are not
madewithexactnumbers.How dothese
inaccuraciespropagatethroughthecalculations?
Example1:
Findthebounds for thepropagationin addingtwo
if one is calculating X+Ywhere
X= 1.5 0.05
Y= 3.4 0.04
Solution
numbers.Forexample
Maximumpossiblevalue of X1.55andY= 3.44=
Maximumpossiblevalue of XY=1.55+ 3.44= 4.99+
possiblevalue of X=1.45and Y= 3.36.Minimum
possiblevalue of X+Y= 1.45+ 3.36= 4.81Minimum
Hence
4.81≤ X + Y≤4.99.
Propagationof ErrorsInFormulas
Iff is a functionofseveralvariables
possible value of
X
1,X
2,X
3,.......,X
n−1,
is
X
n
thenthemaximum the errorinf
∂f ∂f ∂f ∂f
∆f≈ ∆X
1+ ∆X
2+.......+ ∆X
n−1+ ∆X
n
∂X
1 ∂X
2 ∂X
n−1 ∂X
n
Example2:
squareThestrain inanaxial member
sectionis given by
ofa cross-
F
∈=
Given
h
2
E
F=72±0.9N
h=4±0.1mm
E=70±1.5GPa
Findthe maximumpossible
strain.
error in themeasured
Example—TrueError
can bef′(x)Thederivative, ofa functionf(x)
approximatedby theequation,
f(x+h)−f(x)
f'(x)≈
h
h=0.3and7e
0.5x
f(x)=
a)
b)
c)
If
Findthe approximatevalueoff'(2)
True
True
value of
error for
f'(2)
part (a)
Example(cont.)
Solution:
b)The exactvalue of can be foundbyusingf'(2)
ourknowledge ofdifferentialcalculus.
7e
0.5x
f(x)=
f'(x)=7×0.5×e
0.5x
3.5e
0.5x
=
So thetrue value of is
f'(2)
3.5e
0.5(2)
f'(2)=
=9.5140
Trueerror is calculatedas
E
t =TrueValue –ApproximateValue
=9.5140−10.263=−0.722
Example—RelativeTrueError
Followingfromthe previousexample fortrue error,
findthe relative true error for atf'(2)7e
0.5x
f(x)=
withh=0.3
Fromtheprevious example,
E
t =−0.722
Relative True Error is definedas
TrueError
∈=
t
TrueValue
−0.722
= =−0.075888
9.5140
as a percentage,
∈
t=−0.075888×100%=−7.5888%
ApproximateError
◼Whatcan be done
knownor are very
◼Approximate error
iftrue values are not
difficulttoobtain?
isdefined asthe
difference between the present
approximationand theprevious
approximation.
ApproximateError(E
a)=PresentApproximation–PreviousApproximation
Example—ApproximateError
For at findthe following,x=27e
0.5x
f(x)=
f′(2)
f′(2)
a)
b)
c)
using
using
h=0.3
h=0.15
f′(2)approximateerror forthevalueof forpartb)
Solution:
a)For andx=2 h=0.3
f(x+h)−f(x)
f'(x)≈
h
f(2+0.3)−f(2)
f'(2)≈
0.3
Example
Solution:(cont.)
f(2.3)−f(2)
(cont.)
=
0.3
7e
0.5(2.3)
−7e
0.5(2)
=
0.3
22.107−19.028
= =10.263
0.3
andb)Forx=2 h=0.15
f(2+0.15)−f(2)
f
'
(2)≈
0.15
f (2.15)−f (2)
=
0.15
Example
Solution:(cont.)
(cont.)
7e
0.5(2.15)
−7e
0.5(2)
=
0.15
20.50−19.028
=9.8800=
0.15
c)So
E
a
the approximateerror,isE
a
=PresentApproximation–PreviousApproximation
=9.8800−10.263
=−0.38300
RelativeApproximateError
◼Defined astheratio between the
approximate error
approximation.
(∈
a)
and the present
ApproximateError
RelativeApproximateError =
PresentApproximation
Example—Relative Approximate Error
7e
0.5x
f(x)=
For at ,findtherelative approximatex=2
errorusingvalues from
Solution:
andh=0.3 h=0.15
f′(2)=10.263From
using
E
a
Example 3,the approximatevalue of
and usingh=0.3 h=0.15f′(2)=9.8800
=PresentApproximation–PreviousApproximation
=9.8800−10.263
=−0.38300
Example
Solution:(cont.)
ApproximateError
(cont.)
∈
a=
PresentApproximation
−0.38300
=−0.038765=
9.8800
as a percentage,
∈
a =−0.038765×100%=−3.8765%
Absoluterelative approximateerrors
becalculated,
may alsoneed to
∈
a=|−0.038765|=0.038765or3.8765
%
HowisAbsoluteRelative Error usedas
stopping criterion?
a
If whereis a pre-specified tolerance,then|∈
a|≤∈
s ∈
s
nofurtheriterationsare necessaryand the process
stopped.
is
Ifat leastmsignificant digitsarerequiredtobe
correct in the finalanswer,then
0.5×10
2−m
%|∈ |≤
a
TableofValues
7e
0.5x
=f(x)
For at withvaryingstepsize,x=2 h
h
f′(2) ∈
a m
0.3 10.263 N/A 0
0.15 9.8800 3.877% 1
0.10 9.7558 1.273% 1
0.01 9.5378 2.285% 1
0.001 9.5164 0.2249% 2