Numerical Analysis Measuring Errors: Lecture # 2
Numerical Analysis Measuring Errors: Lecture # 2
Measuring Errors
Lecture # 2
Tuesday, Sept 14, 2021
1
Measuring Errors
UET
LAHORE Copyright ® Dr Zohaib Atiq Khan
Why measure errors?
UET 3
LAHORE Copyright ® Dr Zohaib Atiq Khan
True Error
UET 4
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example—True Error
If f ( x) = 7e and h = 0.3
0.5 x
UET 5
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example (cont.)
Solution:
a) For x = 2 and h = 0.3
f ( 2 + 0.3) − f ( 2)
f ' ( 2)
0 .3
f (2.3) − f (2)
=
0. 3
7e 0.5( 2.3) − 7e 0.5( 2 )
=
0.3
22.107 − 19.028
= = 10.263
0.3
UET 6
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example (cont.)
Solution:
b) The exact value of f ' (2) can be found by using
our knowledge of differential calculus.
f ( x) = 7e 0.5 x
f ' ( x ) = 7 0.5 e 0.5 x
= 3.5e 0.5 x
So the true value of f ' (2) is
f ' ( 2) = 3.5e 0.5( 2 )
= 9.5140
True error is calculated as
Et = True Value – Approximate Value
= 9.5140 − 10.263 = −0.722
UET 7
LAHORE Copyright ® Dr Zohaib Atiq Khan
Relative True Error
• Defined as the ratio between the true error, and the true value.
True Error
Relative True Error ( t ) =
True Value
UET 8
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example—Relative True Error
UET 9
LAHORE Copyright ® Dr Zohaib Atiq Khan
Approximate Error
• What can be done if true values are not known or are very difficult to obtain?
• Approximate error is defined as the difference between the present approximation and the
previous approximation.
UET 10
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example—Approximate Error
UET 11
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example (cont.)
Solution: (cont.)
f (2.3) − f (2)
=
0. 3
7e 0.5( 2.3) − 7e 0.5( 2 )
=
0.3
22.107 − 19.028
= = 10.263
0.3
b) For x = 2 and h = 0.15
f (2 + 0.15) − f (2)
f ' (2)
0.15
f (2.15) − f (2)
=
0.15
UET 12
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example (cont.)
Solution: (cont.)
7e 0.5( 2.15 ) − 7e 0.5( 2)
=
0.15
20.50 − 19.028
= = 9.8800
0.15
UET 13
LAHORE Copyright ® Dr Zohaib Atiq Khan
Relative Approximate Error
• Defined as the ratio between the approximate error and the present approximation.
Approximate Error
Relative Approximate Error ( a) =
Present Approximation
UET 14
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example—Relative
Approximate Error
For f ( x) = 7e 0.5 x
at x = 2 , find the relative approximate
error using values from h = 0.3 and h = 0.15
Solution:
From Example 3, the approximate value of f (2) = 10.263
using h = 0.3 and f (2) = 9.8800 using h = 0.15
Ea = Present Approximation – Previous Approximation
= 9.8800 − 10.263
= −0.38300
UET 15
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example (cont.)
Solution: (cont.)
Approximate Error
a =
Present Approximation
− 0.38300
= = −0.038765
9.8800
as a percentage,
a = −0.038765 100% = −3.8765%
UET 16
LAHORE Copyright ® Dr Zohaib Atiq Khan
How is Absolute Relative Error
used as a stopping criterion?
UET 17
LAHORE Copyright ® Dr Zohaib Atiq Khan
Table of Values
h f (2) a m
0.3 10.263 N/A 0
UET 18
LAHORE Copyright ® Dr Zohaib Atiq Khan
Sources of Error
UET 19
LAHORE Copyright ® Dr Zohaib Atiq Khan
Two sources of numerical
error
1) Round off error
2) Truncation error
UET 20
20
LAHORE Copyright ® Dr Zohaib Atiq Khan
Round off Error
1
0.333333
3
2 1.4142...
UET 21
21
LAHORE Copyright ® Dr Zohaib Atiq Khan
Truncation error
UET 22
22
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example of Truncation Error
2 3
x x
e x = 1 + x + + + ....................
2! 3!
If only 3 terms are used,
x 2
Truncation Error = e − 1 + x +
x
2!
UET 23
23
LAHORE Copyright ® Dr Zohaib Atiq Khan
Another Example of
Truncation Error
Using a finite x to approximate f (x)
f ( x + x) − f ( x)
f ( x)
x
secant line
P
tangent line
UET 24
24
LAHORE Copyright ® Dr Zohaib Atiq Khan
Another Example of
Truncation Error
Using finite rectangles to approximate an
integral.
y
90
y = x2
60
30
0 x
0 1.5 3 4.5 6 7.5 9 10.5 12
UET 25
25
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example 1 —Maclaurin series
1.2
Calculate the value of e with an absolute
relative approximate error of less than 1%.
1.2 2 1.2 3
e 1.2
= 1 + 1.2 + + + ...................
2! 3!
n
e 1.2
Ea 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
f ( x) = x 2 f ( x + x) − f ( x)
Find f (3)
for using f ( x)
x
and x = 0.2
f (3 + 0.2) − f (3)
f ' (3) =
0.2
f (3.2) − f (3) 3 .2 2 − 3 2 10.24 − 9 1.24
= = = = = 6.2
0.2 0.2 0.2 0 .2
90
9
y = x2 2
60
x dx
30 3
0 x
0 3 6 9 12
UET 28
28
LAHORE Copyright ® Dr Zohaib Atiq Khan
Integration example (cont.)
= (6 − 3) + ( x 2 ) (9 − 6)
2 2
x dx ( x )
x =3 x =6
3
= (3 2 )3 + (6 2 )3
= 27 + 108 = 135
Actual value is given by
9 9
x 93 − 33
3
3 x dx = 3 = 3 = 234
2
3
Truncation error is then
234 − 135 = 99
Can you find the truncation error with 4 rectangles?
29
UET 29
LAHORE Copyright ® Dr Zohaib Atiq Khan