0% found this document useful (0 votes)
30 views28 pages

Numerical Methods With Applications

This document discusses numerical methods for approximating functions using Taylor series expansions. It provides examples of using Taylor series to estimate values and derivatives of functions. The key points are: 1) Taylor series can be used to approximate functions as polynomials based on their values and derivatives at a specific point. 2) Higher order Taylor series approximations incorporate more derivative terms and are generally more accurate, especially for smaller step sizes. 3) There is an inherent truncation error associated with numerical approximations that decreases with higher order terms or smaller step sizes.

Uploaded by

razlan ghazali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views28 pages

Numerical Methods With Applications

This document discusses numerical methods for approximating functions using Taylor series expansions. It provides examples of using Taylor series to estimate values and derivatives of functions. The key points are: 1) Taylor series can be used to approximate functions as polynomials based on their values and derivatives at a specific point. 2) Higher order Taylor series approximations incorporate more derivative terms and are generally more accurate, especially for smaller step sizes. 3) There is an inherent truncation error associated with numerical approximations that decreases with higher order terms or smaller step sizes.

Uploaded by

razlan ghazali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

NUMERICAL METHODS WITH

APPLICATIONS
(MEC500)

Dr. Siti Rabizah Makhsin


Faculty of Mechanical Engineering
Office: T1-A14-1A
e-mail: [email protected]
Outcomes of Chapter 1

 Describe numerical techniques as compared to analytical


methods
 Perform error analysis associated with numerical
methods
 Use Taylor series expansion to approximate a function
Learning outcome
 Knowing how to use the Taylor series to estimate
truncation errors.
 Understanding how to write forward, backward, and
centered finite-difference approximations of the first and
second derivatives.
 Recognizing that truncation errors occur when exact
mathematical formulations are represented by
approximations.
 Recognizing that efforts to minimize truncation errors can
sometimes increase round off errors.
What is a Taylor series?
 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.
 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!
x 2 x3
e  1 x   
x

2! 3!

http://numericalmethods.eng.usf.edu
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!

 provided that all derivatives of f(x) are continuous and


exist in the interval [x,x+h]
Order of Taylor Series Expansion (TSE)

 zero order approximation, only true if xi+1 and xi are very close to
each other.
f ( xi 1 )  f ( xi )

 first order approximation, in form of a straight line.


f ( xi 1 )  f ( xi )  f ( xi )( xi 1  xi )
 nth order approximation, ( xi 1  xi )step
 h size
f ( xi ) 2 f 3 ( xi ) 3 f n ( xi ) n
f ( xi 1 )  f ( xi )  f ( xi )h  h  h  ...  h  Rn
2! 3! n!
f ( n 1) ( ) ( n 1) Remainder term, Rn, account for all
Rn  h terms form (n+1) to ∞
(n  1)! = Truncation Error
xi    xi 1
Example 1
Taylor Series
Find the value of f given
6 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
Example 1
Since the higher order derivatives are zero,
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

f  6
Note that to find exactly, we only need the value of the function and all its
derivatives at some other point, in this case
x4
Example 2
Taylor series approximation of a polynomial
Use zero through third order TSE to approximate the function

f  x   0.5 x 3
 0.1
At x = 1.0 and the base pointx 2
 0.8(a)
x  0x.07=0 and (b) x0=0.8. Also
calculate both the true and approximate percent relative
errors for each order.

f 1  0.5(1) 3  0.1(1) 2  0.8(1)  0.7  0.5


(a) with h = x-x0=1.0,

f  x   0.5 x 3  0.1x 2  0.8 x  0.7 f  0  0.7


f  x   1.5 x 2  0.2 x  0.8 f  0  0.8
f  x   3.0 x  0.2 f  0  0.2
f  x   3.0 f  0  3.0
f 4 ( x)  0.0
Example 2

We observe that though the true percent relative error is zero, the approximate
percent relative error is 100%. In practice, when using numerical method (in
the absent of the true value), we will continue with higher order
approximation(s) that is

(0)
f 1  0.5  (1.0)3  0.5 and  a  0%
4!
(b) with h = x-x0=0.2,

Using the derivatives from part (a), we obtain


f  0.8  0.132
f  0.8  1.6
f  0.8  2.2
f  0.8  3.0
f 4 ( x)  0.0
In practice, we usually require the result to be within a specified
tolerance. For example, we may want the result to be accurate to at
least 3 d.ps. If this is the case, then we will have to continue with
higher order approximations(s).

p = 3,
 s  0.05%

4th-order approximation:

(0)
f 1  0.5  (1.0)3  0.5 and  a  0%
4!
Since , we stop the calculation.
a  s
Remark..
 The function and its n+1 derivatives are assumed to be continuous
in the interval of interest [x0,x].
 Order of approximation is the highest order of the derivatives.
 Accuracy of the approximation improves as order of TSE increases
or when the step size h decreases. Higher order terms become
apparent when the nonlinearities of the function increases or when
the step size increases.
 When the function is linear (i.e. a polynomial), the first-order TSE
with reasonably small step size is usually adequate.
 TSE is used when the function is not known or in order to obtain
approximate solutions for trigonometric and logarithmic functions.

In practice, we may use the known function to illustrate the practicality


of the TSE.
Remainder, Rn
 In general, the nth order Taylor series expansion will be exact
for an nth order polynomial.
 In other functions (eg. Exponential & sinusoids), finite number
of terms will not yield an exact estimate. Thus the remainder
term Rn is of the order of hn+1, meaning:
 The more terms are used, the smaller the error, and
 The smaller the spacing, the smaller the error for a given
number of terms.

 In most cases, inclusion of only a few terms will give an


approximation close enough for practical purpose.
 So how many terms are required to get ‘close enough’?
Remainder, Rn
 Recall the derivative form of the remainder

f ( n 1) ( ) ( n 1)
Rn  h
(n  1)!

 Two major drawbacks:


 ξ is not known exactly. It lies between x0 and x1.
 In order to evaluate Rn, we need to know the (n+1)th derivative of
the f(x).
If we know f(x), we don’t need TSE!

 However, we do have control over:


 The term hn+1 (we can choose how far away from x0 to evaluate f(x)
 The number of terms to be included in TSE.
Remainder, Rn
 Consequently, Rn can be expressed as:

Rn  (h n 1 )

 Θ(hn+1) means the order of truncation error is hn+1  we can control


h
 If error = Θ(h), halving the step size will halve the error.
 If error = Θ(h2), halving the step size will quarter the error.

 Truncation error is decrease 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.
Truncation Error Associated With TSE

 Truncations Errors: error that result from using an


approximation in place of an exact mathematical procedures

 Denoting xi = x0 and xi+1 = x

 The zero-order TSE will be f ( xi 1 )  f ( x)

f ( xi ) f ( xi ) 2
 With the remainder,
R0  h h  ...  Rn
1! 2!

 We may approximate the zero-order remainder as


R0  f ( xi )h
Truncation Error Associated With TSE
 Illustrating the concept of error approximation in TSE

“ if a function f(x) and its first derivative are continuous over an


interval from xi and xi+1, then there exists at least one point on
the function that has a slope, designated by f’(ξ), that is parallel
to the line joining f(xi) and f(xi+1). “ (derivative mean-value theorem)
Truncation Error Associated With TSE

 Thus, if the slope is equal to the rise R0 divided by the run


h,
R0
f ( )  R0  f ( )h
h

 Similarly, the first order and second-order remainders are:

f ( ) 2
R1  h
2!
f ( ) 3
R2  h
3!
Truncation Error Associated With TSE

 We conclude that the estimate of the first derivative using


TSE has a truncation error of order of h.
 The error of the first derivative approximation is
proportional to the step size.
 It follows that the error will be halved if the step size is
halved.
Example 4
Using Taylor Series to estimate truncation errors

Denote that:
f ( x)  x 4
Estimate the truncation error from x = 1 to x = 2 and h=1

3
TSE (first order): f ( xi 1 )  f ( xi )  4 xi h

f (2)  1  4(1) 3 (1)  5

f ( xi ) 2 f ( xi ) 3 f 4 ( xi ) 4
Remainder: R1  h  h  h  ...
2! 3! 4!
12 2 24 3 24 4
R1  1  1  1  0  0  ...  11
2 6 24
Finite Difference Approximations of
First Derivative
There are three different methods for the approximation of the first derivative:
1. Forward difference method (FDM)

Given: f ( xi 1 )  f ( xi )  f ( xi )h  (h)

Then: f ( xi 1 )  f ( xi )
f ( xi )   ( h )
h
Where the expression Θ(h) represents the remaining terms of the series and
indicates that the leading term is of order h.
It is termed a “forward” difference because it utilizes data i and
i+1 to estimate the derivatives.
Finite Difference Approximations of
First Derivative
2. Backward difference method (BDM)

f ( xi ) 2 f ( xi ) 3
Given: f ( xi 1 )  f ( xi )  f ( xi )h  h  h  ...
2! 3!
Then: f ( xi )  f ( xi 1 )
f ( xi )   ( h )
h

3. Centered (or central) difference method (CDM)


f ( xi ) 3
f ( xi 1 )  f ( xi 1 )  2 f ( xi )h  h  ...
Given: 3!

Then: f ( xi 1 )  f ( xi 1 )
f ( xi )   ( h 2 )
2h
Finite Difference Approximations of
First Derivative
 Notice that the error for the central different method is of the
order of h2 as compared to h for the forward and backward
difference methods.
 Therefore, central difference method gives better
approximation of the derivative than the other two methods.
Example 5
Numerical Differentiation for First Derivative
Use forward, backward and centered difference to estimate
the first derivative of the function

f ( x)  0.1x 4  0.15 x 3  0.5 x 2  0.25 x  1.2

For x = 0.5 using h = 0.5


f (0.5)  0.4 x 3  0.45 x 2  1.0 x  0.25  0.9125

With h = 0.5 and x = 0.5, they imply that

xi 1  0.0 f ( xi 1 )  1.2
xi  0.5 f ( xi )  0.925
xi 1  1.0 f ( xi 1 )  0.2
Numerical Differentiation for First
Derivative
1. Forward divided difference
0.2  0.925
f (0.5)   1.45  t  58.9%
0. 5
2. Backward divided difference

0.925  1.2
f (0.5)   0.55  t  39.7%
0.5
3. Centered divided difference

0.2  1.2  0.9125  (1.0)


f (0.5)   1.00 t   9.6%
1.0  0.9125

We observe that the CDM is more accurate than the FDM and BDN.
Total Numerical Error
 The total numerical error is the summation of the truncation and
round-off errors.
 The truncation error generally increases as the step size
increases.
 Round off error decreases as the step size increases
Control of numerical error
 For most practical cases, exact numerical error is not known.
 Therefore, we must settle for estimate of errors.

 Error estimates are based on the experience and judgment of


the engineers.

 Error analysis is to a certain extent an art, always observe the


following guides;
 Careful with arithmetic manipulations
 Use extended-precision arithmetic
 Attempt to predict total numerical error using Taylor
series
 Perform numerical experiments –try different step sizes.

You might also like