You are on page 1of 35

MEEN-3432 Computational

Methods

Approximations, Errors & Taylor Series


Ch: 3, 4
Chapter 3
Approximations and Round-Off Errors
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.

• How confident we are in our approximate result?

• The answer is “how much error is present in our


calculation and is it tolerable?”
Significant Figures
 Number of significant figures indicates precision.

 Significant digits of a number are those that can be used with


confidence, or which are meaningful

 Significant figures = number of certain digits plus one estimated digit

48.5 (3 Significant)

87324.45 (7 Significant)
Significant Figures

53,800 How many significant figures?


May have three, four, or five significant digits, depending on whether the zeros
are known with confidence

5.38 x 104 3
5.380 x 104 4
5.3800 x 104 5

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

0.00001753 4
0.0001753 4
0.001753 4
Accuracy & Precision
• Accuracy. How close is a
computed or measured value to
the true value
• Precision (or reproducibility).
How close is a computed or
measured value to previously
computed or measured values.
• Inaccuracy (or bias). A
systematic deviation from the
actual value.
• Imprecision (or uncertainty).
Magnitude of scatter.
Errors
Why measure errors?

Defined as the difference between the true value in a


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

1) To determine the accuracy of numerical results.

2) To develop criterion to stop iterative algorithms.


Types of Error
True Error
Absolute True Error
Et  true value  approximation

Absolute Relative True Error !Can be computed if


true value  approximation
t  the true value is
true value
known
Absolute Percent Relative True Error
true value  approximation
t  *100
true value
Types of Error
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 current
approximation and the previous approximation.
Approximate Absolute Error
Ea  current approximation  previous approximation
Approximate Absolute Relative Error
current approximation  previous approximation
a 
current approximation
Approximate Absolute Percent Relative Error
current approximation  previous approximation
a  *100
current approximation
Types of Error
True and Approximate Error
Example
The derivative, f (x) of a function f ( x)  7e
0.5 x
can be approximated by the equation:

f ( x  h)  f ( x)
f ' ( x) 
h

using h  0.3 f (2) using


f) h  0.15
a) Find the approximate value of f ' ( 2)
g) Approximate error for the value of f (2)
b) True value of f ' ( 2)
h) Relative approximate error
c) True error
i) Percent Relative approximate error
d) Relative true error
e) Percent relative true error
Types of Error
True and Approximate Error
Example c) True error is calculated as
a) For x  2 and h  0.3 Et  True Value – Approximate Value
f ( 2  0.3)  f ( 2)
f ' ( 2)   9.5140 10.263  0.722
0.3
f (2.3)  f (2)
 d) Relative True Error is calculated as
0.3 True Error
t 
7e 0.5( 2.3)  7e 0.5( 2 ) True Value
  0.722
0.3   0.075888
9.5140
22.107  19.028
  10.263 e) Percent relative true error
0.3 t  0.075888  100%  7.5888%
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 So the true value of f ' ( 2) is f ' ( 2)  3.5e 0.5( 2 )
 3.5e 0.5 x  9.5140
Types of Error
True and Approximate Error
Example Approximate Error
h ) a 
f ) For x  2 and h  0.15 Present Approximation
f (2  0.15)  f (2)  0.38300
f ' (2)    0.038765
0.15 9.8800
f (2.15)  f (2)

0.15 i ) as a percentage,
7e 0.5( 2.15 )  7e 0.5( 2 ) a  0.038765  100%  3.8765%

0.15
20.50  19.028 Absolute relative approximate errors may
  9.8800 also need to be calculated,
0.15
a | 0.038765 |  0.038765 or 3.8765 %
g) So the approximate error, E a is
Ea  Present Approximation – Previous Approximation
 9.8800  10.263
 0.38300
How is Absolute Relative Error
used as a stopping criterion?
• Use absolute value.
• Computations are repeated until stopping criterion is
satisfied.

 a  s Pre-specified % tolerance based


on the knowledge of your solution

• If the following criterion is met

 s  (0.510 (2-n)
)%
you can be sure that the result is correct to at least n
significant figures.
How is Absolute Relative Error
used as a stopping criterion?

Estimate e0.5
Solution Determine the error criterion that ensures a result is correct to at least three
significant figures:
Sources of numerical error
Round-Off error
1)Round-off error 2)Truncation error
1
1. Numbers such as p, e, , 2  1.4142... or
7
3
 0.333333
cannot be
expressed by a fixed number of significant figures.
2. So these numbers are expressed approximately and significant
numbers are omitted.
3. Fractional quantities are typically represented in computer using
“floating point” form, e.g.,

Integer part
Mantissa: A number
exponent
represented approximately
to a fixed number
m.be
of significant digits mantissa Base of the number system
used
Sources of numerical error
Round-Off error
Storage of a floating point number in a word

Round-off errors are introduced because mantissa holds only a finite


number of significant figures.

Rounding: Replace the number by the nearest machine number.


Chopping: Throw all extra digits.
Rounding & Chopping

Example:
p=3.14159265358 to be stored on a base-10 system carrying
7 significant digits.
p=3.141592 chopping error t=0.00000065
If rounded p=3.141593 t=0.00000035

• Some machines use chopping, because rounding adds to


the computational overhead. Since number of significant
figures is large enough, resulting chopping error is
negligible.
17
Homework-1 (Ch3, Ch4)
Chapter 3: 3.6 (Also Generate Excel program), 3.7, 3.8
Don’t submit yet
Chapter 4
Truncation Errors and the Taylor Series
Truncation Errors & Taylor Series

• Non-elementary functions such as trigonometric,


exponential, and others are expressed in an
approximate fashion using Taylor series when their
values, derivatives, and integrals are computed.

• Any smooth function can be approximated as a


polynomial. Taylor series provides a means to
predict the value of a function at one point in terms of
the function value and its derivatives at another point.
General Taylor Series
The general form of the Taylor series is given by
f x  2 f x  3
f x  h   f x   f x h  h  h 
2! 3!
“Give me the value of the function at a single point, and the value of all (first, second,
and so on) its derivatives at that single point, and I can give you the value of the
function at any other point”
General Taylor Series
Some examples of Taylor series which you must have seen

x2 x4 x6
cos( x)  1    
2! 4! 6!
x3 x5 x7
sin( x)  x    
3! 5! 7!
2 3
x x
e  1  x     Maclaurian series
x

2! 3!
2 3 4
x x x
log (1  x)  x     Logrithmic series
e

2 3 4
Truncation Errors & Taylor Series
Any smooth function can be approximated as a polynomial.
f(xi+1) ≈ f(xi) zero order approximation, only true if xi+1
and xi are very close to each other.
f(xi+1) ≈ f(xi) + f′(xi) (xi+1-xi) first order approximation, in
form of a straight line
Truncation Errors & Taylor Series
nth order approximation

f 
f ( xi 1 )  f ( xi )  f ( xi )( xi 1  xi )  ( xi 1  xi ) 2  
2!
f (n)
 ( xi 1  xi ) n  Rn
n!
(xi+1-xi)= h step size (define first)

f ( n 1)
(c) ( n 1) R x  
 x  h
n 1

f  n1 c 
Rn  h n
(n  1)!
(n  1)! c lies between xi and xi+1
Remainder term, Rn, accounts for all terms from (n+1) to infinity
Example—Taylor Series
Find the value of f 6  given that f 4  125, f 4  74,
f 4   30, f 4  6 and all other higher order derivatives
of f  x  at x  4 are zero.

Solution:
h2 h3
f x  h   f x   f x h  f x   f x   
2! 3!
x4
h  64  2

22 23
f 4  2  f 4  f 42  f 4  f 4
2! 3!
 2 2   23 
f 6  125  742  30   6 
 2!   3! 
 125  148  60  8
 341
Example—Taylor Series

True value of function at x = 1


is 0.2

Solution:

f (1) = 0.95
Example—Taylor Series

True value of function at x = 1


is 0.2

Solution:

By Additional terms

f ( n 1) (c) ( n 1)


Rn  h
f (1) = 0.45 The truncation error 0.2 − 0.45=−0.25 (n  1)!
Example—Taylor Series

Self Practice at home

Sin
Truncation Errors & Taylor Series

• Error caused by truncating or approximating a


mathematical procedure.
• Truncation error is decreased by addition of terms to
the Taylor series.
• If h is sufficiently small, only a few terms may be
required to obtain an approximation close enough to
the actual value for practical purposes.
Error in Taylor series
x 2 x3 x 4 x5
The Taylor series for e is given by e  1  x 
x
    x

2! 3! 4! 5!
As the number of terms used increases, the error bound decreases and hence a
better estimate of the function can be found.
How many terms would it require to get an approximation of e1 within a magnitude of true
error less than 10-6

Solution: Since
x  c  xh
Using (n+1) terms of Taylor series gives error
1  c  1 0
Rn x  
 x  h
n 1
f n 1 c  x  1, h  0, f ( x)  e x 1 c 1
n  1! e e
Rn 1  (n  1)!
 10  6
(n  1)!
1  0
n 1
1n 1
(n  1)! 10 6 e
R 1  f  n 1
c   e c
So 9 terms or more
n
n  1! n  1! are needed to get a (n  1)! 10 6  3
true error n9
Truncation Errors
Maclaurin series

Solution
Determine the error criterion that ensures a result is correct to at least three significant figures:

Excel Program
Truncation Errors
Differentiation
Error caused by truncating or approximating a mathematical procedure.

For example:

secant line
P

tangent
line
Q

Approximate derivative using finite Δx


f ( x  x)  f ( x)
f ( x) 
x
Truncation Errors
Integration
Error caused by truncating or approximating a mathematical procedure.

Using finite rectangles to approximate an integral


y For example:
90

y = x2
60

Solution:
30

0 x
0 1.5 3 4.5 6 7.5 9 10.5 12
Error Propagation & Total Numerical Error
Error propagation
Errors in numbers can propagate through mathematical functions. For example, if we
multiply two numbers that have errors, we would like to estimate the error in the product.

Total numerical error


This is the summation of the truncation and round-off
errors.
• The only way to minimize round-off errors is to
increase the number of significant figures of the
computer.
• Round-off error will increase due to an increase in the
number of computations in an analysis.
• Truncation error can be reduced by decreasing the step
size.
• Because a decrease in step size can lead to an increase in
computations, the truncation errors are decreased as the
round-off errors are increased.
Homework-1 (Ch3, Ch4)
Chapter 4: 4.2, 4.4, 4.5, 4.6, 4.17, 4.19
Submit by:………

Quiz-1 (on…..

You might also like