The Taylor Series

```COMPUTATIONAL
MODELING FOR
ENGINEERING
MECN 6040
Professor: Dr. Omar E. Meza Castillo
[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
Department of Mechanical Engineering
FINITE DIFFERENCES
Best known numerical method
of approximation
FINITE DIFFERENCE FORMULATION
OF DIFFERENTIAL EQUATIONS
finite difference
form of the first
derivative
Taylor series expansion of the function f
The smaller the x, the smaller
the error, and thus the more
accurate the approximation.
3
THE
BIG QUESTION:
How good are the FD approximations?

This leads us to Taylor series....
4
EXPASION OF TAYLOR SERIES
▪ Numerical Methods express functions in an
approximate fashion: The Taylor Series.
▪ What is a 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!
x2 x3
e  1 x 


2! 3!
x
5
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], where h=∆x
What does this mean in plain English?
As Archimedes would have said, “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”
6
▪ Example: 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: x=4, x+h=6  h=6-x=2
▪ 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
7
THE TAYLOR SERIES
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)
▪ Reminder term, Rn, accounts for all terms from
(n+1) to infinity.
f ( n 1) ( ) ( n1)
Rn 
h
(n  1)!
8
▪ Zero-order approximation
f (x i1 )  f (x i )
▪ First-order approximation
f (x i1 )  f (x i )  f (x i )(x i1  x i )
▪ Second-order approximation
f 
f ( x i 1 )  f ( x i )  f ( x i )( x i 1  x i )  ( x i 1  x i ) 2
2!
9
▪ Example: Taylor Series Approximation of a
polynomial Use zero- through fourth-order Taylor
Series approximation to approximate the function:
f x   0.1x 4  0.15x3  0.5x 2  0.25x  1.2
▪ From xi=0 with h=1. That is, predict the function’s
value at xi+1=1
▪ f(0)=1.2
▪ f(1)=0.2 - True value
10
▪ Zero-order approximation
f x i 1   f x i   f (0)  1.2
f (1)  1.2
E t  T rue value  approximation
E t  0.2  1.2  1.0
▪ First-order approximation
f x i 1   f x i   f ' ( x i )h
f ' ( x i )  0.4x 3  0.45x 2  1x  0.25
f ' (0)  0.25
f 1  f 0  f ' (0)h  1.2  0.25(1)  0.95
11
E t  0.2  0.95  0.75
▪ Second-order approximation
f ' ' ( x i )h 2
f x i 1   f x i   f ' ( x i )h 
2!
f ' ' ( x i )  1.2x 2  0.9x  1
f ' ' (0)  1
12
12
f ' ' (0)h 2
1 2
f 1  f 0  f ' (0)h 
 1.2  0.25(1)  1  0.45
2!
2
E t  0.2  0.45  0.25
▪ Third-order approximation
f ' ' ( x i )h 2 f ' ' ' ( x i )h 3

f x i 1   f x i   f ' ( x i )h 
3!
2!
f ' ' ' ( x i )  2.4x  0.9
f ' ' (0)  0.9
f ' ' (0)h 2 f ' ' ' (0)h 3

f 1  f 0  f ' (0)h 
3!
2!
3
1 2 0.91
 0.3
 1.2  0.25(1)  1 
6
2
E t  0.2  0.3  0.1
13
▪ Fourth-order approximation
f ' ' ( x i )h 2 f ' ' ' ( x i )h 3 f iv ( x i )h 4


f x i 1   f x i   f ' ( x i )h 
4!
3!
2!
f iv ( x i )  2.4
f iv (0)  2.4
f ' ' (0)h 2 f ' ' ' (0)h 3 f iv (0)h 4


f 1  f 0  f ' (0)h 
4!
3!
2!
4
3

1
1 2 0.91
 0.2
 2.4
 1.2  0.25(1)  1 
24
6
2
E t  0.2  0.2  0
14
15
TAYLOR SERIES TO ESTIMATE
TRUNCATION ERRORS
v' '
v( t i 1 )  v( t i )  v' ( t i )(t i 1  t i )  ( t i 1  t i ) 2  
2!
v(n )

( t i 1  t i ) n  R n
n!
▪ If we truncate the series after the first derivative term
v(t i1 )  v(t i )  v' (t i )(t i1  t i )  R1
v( t i 1 )  v( t i )
R1
v' ( t i ) 

( t i 1  t i )
( t i 1  t i )
16
First-order approximation
O( t i 1  t i )
Truncation Error
NUMERICAL DIFFERENTIATION
▪ Forward Difference Approximation
f ( x i 1 )  f ( x i )
f ' (x i ) 
 O( x i 1  x i )
( x i 1  x i )
17
NUMERICAL DIFFERENTIATION
• The Taylor series expansion of f(x) about xi is
f ( xi 1 )  f ( xi )  f ( xi )(xi 1  xi )
• From this:
f ( xi ) 
f ( xi 1 )  f ( xi ) f ( xi 1 )  f ( xi )

xi 1  xi
h
• This formula is called the first forward divided
difference formula and the error is of order O(h).
18
• Or equivalently, the Taylor series expansion of f(x)
about xi can be written as
• From this:
f ( xi 1 )  f ( xi )  f ( xi )(xi 1  xi )
f ( xi ) 
f ( xi 1 )  f ( xi ) f ( xi )  f ( xi 1 )

xi 1  xi
h
• This formula is called the first backward divided
difference formula and the error is of order O(h).
19
• A third way to approximate the first derivative is to
subtract the backward from the forward Taylor series
expansions:
f ( xi 1 )  f ( xi )  f ( xi )h

f ( xi 1 )  f ( xi )  f ( xi )h
• This yields to
__________
__________
_____
f ( xi 1 )  f ( xi 1 )  2 f ( xi )h
• This formula is called the centered divided difference
formula and the error is of order O(h2).
20
f ( xi ) 
f ( xi 1 )  f ( xi 1 )
2h
NUMERICAL DIFFERENTIATION
▪ Forward Difference Approximation
f ( x i 1 )  f ( x i )
f ' (x i ) 
 O( x i 1  x i )
( x i 1  x i )
21
▪ Backward Difference Approximation
f ( x i )  f ( x i 1 )
f ' (x i ) 
 O( h )
h
22
▪ Centered Difference Approximation
f ( x i 1 )  f ( x i 1 )
f ' (x i ) 
 O( h 2 )
2h
23
▪ Example: To find the forward, backward and
centered difference approximation for f(x) at
x=0.5 using step size of h=0.5, repeat using h=0.25.
The true value is -0.9125
f x   0.1x 4  0.15x 3  0.5x 2  0.25x  1.2
f ' x   0.4x 3  0.45x 2  1x  0.25
▪ h=0.5
▪ xi-1=0 - f(xi-1)=1.2
▪ xi=0.5 - f(xi)=0.925
▪ Xi+1=1 - f(xi+1)=0.2
24
▪ Forward Difference Approximation
f ( xi 1 )  f ( xi ) 0.2  0.925
f ' (0.5) 

 1.45
h
0.5
 t  58.9%
▪ Backward Difference Approximation
f ( xi )  f ( xi 1 ) 0.925 1.2
f ' (0.5) 

 0.55
h
0.5
 t  39.7%
25
▪ Centered Difference Approximation
f ( xi 1 )  f ( xi 1 ) 0.2  1.2
f ' (0.5) 

 1
2h
1
 t  9.6%
26
▪ h=0.25
▪ xi-1=0.25 - f(xi-1)=1.10351563
▪ xi=0.5 - f(xi)=0.925
▪ Xi+1=0.75 - f(xi+1)=0.63632813
▪ Forward Difference Approximation
f ( x i 1 )  f ( x i ) 0.63632813 0.925
f ' (0.5) 

 1.155
h
0.25
 t  26.5%
27
▪ Backward Difference Approximation
f ( x i )  f ( x i 1 ) 0.925 1.10351563
f ' (0.5) 

 0.714
h
0.25
 t  21.7%
▪ Centered Difference Approximation
f ( xi 1 )  f ( xi 1 ) 0.63632813 1.10351563
f ' (0.5) 

 0.934
2h
0.5
 t  2.4%
28
FINITE DIFFERENCE APPROXIMATION
OF HIGHER DERIVATIVE
• The forward Taylor series expansion for f(xi+2) in terms
of f(xi) is
f ( xi )
f ( xi  2 )  f ( xi )  f ( xi )(2h) 
( 2h) 2
2
• Combine equations:
f ( xi  2 )  f ( xi )  f ( xi )(2h) 

f ( xi )
( 2h) 2
2
f ( xi ) 2 

2  f ( xi 1 )  f ( xi )  f ( xi )h 
h 
2


__________
__________
__________
_________
29
f ( xi  2 )  2 f ( xi 1 )   f ( xi )  f ( xi )h 2
• Solve for f ''(xi):
f ( xi ) 
f ( xi  2 )  2 f ( xi 1 )  f ( xi )
h2
• This formula is called the second forward finite divided
difference and the error of order O(h).
• The second backward finite divided difference which
has an error of order O(h) is
f ( xi ) 
30
f ( xi )  2 f ( xi 1 )  f ( xi  2 )
h2
• The second centered finite divided difference which has
an error of order O(h2) is
f ( xi ) 
31
f ( xi 1 )  2 f ( xi )  f ( xi 1 )
h2
• High accurate estimates can be obtained by retaining
more terms of the Taylor series.
High-Accuracy Differentiation Formulas
• The forward Taylor series expansion is:
f ( xi 1 )  f ( xi )  f ( xi )(xi 1  xi ) 
• From this, we can write
f ( xi 1 )  f ( xi ) f ' ' ( xi )
f ( xi ) 

h
h
2
32
f ' ' ( xi ) 2
h
2
• Substitute the second derivative approximation into the
formula to yield:
f ( xi  2 )  2 f ( xi 1 )  f ( xi )
2
f ( xi 1 )  f ( xi )
h
f ( xi ) 

h
h
2
• By collecting terms:
 f ( xi  2 )  4 f ( xi 1 )  3 f ( xi )
f ( xi ) 
2h
• Inclusion of the 2nd derivative term has improved the
accuracy to O(h2).
• This is the forward divided difference formula for the first
derivative.
33
Forward Formulas
34
Backward Formulas
35
Centered Formulas
36
Example
Estimate f '(1) for f(x) = ex + x using the centered formula of O(h4)
with h = 0.25.
Solution
• From Tables
f ( xi ) 
 f ( xi  2 )  8 f ( xi 1 )  8 f ( xi 1 )  f ( xi  2 )
12h
xi  2  xi  2h  1  0.5  0.5
xi 1  xi  h  1  0.25  0.75
xi  1
xi 1  xi  h  1  0.25  1.25
xi  2  xi  2h  1  0.5  1.5
37
• In substituting the values:
 f (1.5)  8 f (1.25)  8 f (0.75)  f (0.5)
12(0.25)
 5.982 8(4.740)  8(2.867)  (2.149)

3
 3.717
f ( xi ) 
38
ERROR
▪ Truncation Error: introduced in the solution
by the approximation of the derivative
▪ Local Error: from each term of the
equation
▪ Global Error: from the accumulation of
local error
▪ Roundoff
Error:
introduced
in
the
computation by the finite number of digits
used by the computer
39
INTRODUCTION TO FINITE
DIFFERENCE
▪ Numerical solutions can give answers at only discrete points in the
(i,j)
domain, called grid points.
40
▪ If the PDEs are totally replaced by a system of algebraic equations
which can be solved for the values of the flow-field variables at the
discrete points only, in this sense, the original PDEs have been
discretized. Moreover, this method of discretization is called the
method of finite differences.

Discretization:

Explicit Methods
 Simple
 No

stable
Implicit Methods
 More
complex
 Stables
PDE
FDE
∆x
yn+1
yn
yn-1
 
∆y
u m,n
x m-1 x m x m+1
SUMMARY OF NODAL FINITEDIFFERENCE RELATIONS FOR VARIOUS
CONFIGURATIONS:
Case 1: Interior Node
Case 2: Node at an Internal Corner with Convection
Case 3: Node at Plane Surface with Convection
Case 4: Node at an External Corner with Convection
Case 5: Node at Plane Surface with Uniform Heat Flux
SOLVING THE FINITE
DIFFERENCE EQUATIONS
Heat Transfer Solved Problems
THE MATRIX INVERSION METHOD
JACOBI ITERATION METHOD
GAUSS-SEIDEL ITERATION
ERROR DEFINITIONS
▪ Use absolute value.
▪ Computations are
criterion is satisfied.
 a  s
repeated
until
stopping
Pre-specified % tolerance
based on the knowledge of
▪ If the following Scarborough criterion is met
63
s  (0.510(2-n) )%
USIG EXCEL
Matrix Inversion Method
=MMULT(A7:C9,E2:E4)
64
=MINVERSE(A2:C4)
65
Jacobi Iteration Method using Excel
66
Gauss-Seidel Iteration Method using Excel
A large industrial furnace is supported on a long column of
fireclay brick, which is 1 m by 1 m on a side. During steady-state
operation is such that three surfaces of the column are
maintained at 500 K while the remaining surface is exposed to
300 K. Using a grid of ∆x=∆y=0.25 m, determine the twodimensional temperature distribution in the column.
(1,3)
(2,3)
(3,3)
(1,2)
(2,2)
(3,2)
(1,1)
(2,1)
(3,1)
Ts=300 K
T11
-4
1
0
1
0
0
0
0
0
T12
1
-4
1
0
1
0
0
0
0
T13
0
1
-4
0
0
1
0
0
0
T21
1
0
0
-4
1
0
1
0
0
T22
0
1
0
1
-4
1
0
1
0
T23
0
0
1
0
1
-4
0
0
1
T31
0
0
0
1
0
0
-4
1
0
T32
0
0
0
0
1
0
1
-4
1
System of Linear Equations
T33
0
0
0
0
0
1
0
1
-4
T11
T12
T13
T21
T22
T23
T31
T32
T33
=
-800
-500
-1000
-300
0
-500
-800
-500
-1000
69
Matrix Inversion Method
70
Iteration Method using Excel
71
Jacobi Iteration Method using Excel
72
Error Iteration Method using Excel
73
Gauss-Seidel Iteration Method using Excel
74
Error Iteration Method using Excel
78
Iteration Method using Excel
```