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

Numerical Analysis Measuring Errors: Lecture # 2

Uploaded by

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

Numerical Analysis Measuring Errors: Lecture # 2

Uploaded by

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

Numerical Analysis

Measuring Errors

Lecture # 2
Tuesday, Sept 14, 2021

Dr. Zohaib Atiq Khan


Assistant Professor
zohaib.atiq@uet.edu.pk
Department of Chemical, Polymer & Composite Materials
Engineering (New Campus)

1
Measuring Errors

UET
LAHORE Copyright ® Dr Zohaib Atiq Khan
Why measure errors?

1) To determine the accuracy of numerical results.


2) To develop stopping criteria for iterative algorithms.

UET 3
LAHORE Copyright ® Dr Zohaib Atiq Khan
True Error

• Defined as the difference between the true value in a


calculation and the approximate value found using a
numerical method etc.

True Error = True Value – Approximate Value

UET 4
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example—True Error

The derivative, f (x) of a function f (x) can be


approximated by the equation,
f ( x + h) − f ( x)
f ' ( x) 
h

If f ( x) = 7e and h = 0.3
0.5 x

a) Find the approximate value of f ' (2)


b) True value of f ' (2)
c) True error for part (a)

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

Following from the previous example for true error,


find the relative true error for f ( x) = 7e 0.5 x at f ' (2)
with h = 0.3
From the previous example,
Et = −0.722
Relative True Error is defined as
True Error
t =
True Value
− 0.722
= = −0.075888
9.5140
as a percentage,
t = −0.075888  100% = −7.5888%

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.

Approximate Error ( E a ) = Present Approximation – Previous Approximation

UET 10
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example—Approximate Error

For f ( x) = 7e 0.5 x at x = 2 find the following,


a) f (2) using h = 0.3
b) f (2) using h = 0.15
c) approximate error for the value of f (2) for part b)
Solution:
a) For x = 2 and h = 0.3
f ( x + h) − f ( x)
f ' ( x) 
h
f ( 2 + 0.3) − f ( 2)
f ' ( 2) 
0 .3

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

c) So the approximate error, E a is


Ea = Present Approximation – Previous Approximation
= 9.8800 − 10.263
= −0.38300

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%

Absolute relative approximate errors may also need to


be calculated,
a =| −0.038765 | = 0.038765 or 3.8765 %

UET 16
LAHORE Copyright ® Dr Zohaib Atiq Khan
How is Absolute Relative Error
used as a stopping criterion?

If |a |  s where s is a pre-specified tolerance, then


no further iterations are necessary and the process is
stopped.

If at least m significant digits are required to be


correct in the final answer, then
|a | 0.5  10 2−m %

UET 17
LAHORE Copyright ® Dr Zohaib Atiq Khan
Table of Values

For f ( x) = 7e at x = 2 with varying step size, h


0.5 x

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

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

• Caused by representing a number approximately

1
 0.333333
3
2  1.4142...

UET 21
21
LAHORE Copyright ® Dr Zohaib Atiq Khan
Truncation error

• Error caused by truncating or approximating a mathematical procedure.

UET 22
22
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example of Truncation Error

Taking only a few terms of a Maclaurin series to


approximate e x

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

Figure 1. Approximate derivative using finite Δx

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

6 terms are required. How many are required to get


at least 1 significant digit correct in your answer?26
UET 26
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example 2 —Differentiation

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

The actual value is


f ' ( x ) = 2 x, f ' (3) = 2  3 = 6

Truncation error is then, 6 − 6.2 = −0.2


Can you find the truncation error with x = 0.127
UET 27
LAHORE Copyright ® Dr Zohaib Atiq Khan
Example 3 — Integration

Use two rectangles of equal width to


approximate the area under the curve for
f ( x) = x 2 over the interval [3,9]
y

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.)

Choosing a width of 3, we have


9

 = (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

You might also like