CH 23
CH 23
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Where do we use numerical techniques?
– A complicated continuous function that is difficult or
impossible to differentiate or integrate directly
– When we have a sampling of points representing a
function as with the experiments results
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Numerical Differentiation
4
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Forward Divided Difference method uses the value of points in
front of and at the point where the derivative is calculated.
5
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
First derivative with forward divided difference
Consider a function f(xi+1) which can be expanded in a Taylor
series in the neighborhood of a point xi
h xi 1 xi : step size
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
f ( n 1) () ( n 1)
Rn h O(hn+1),
(n 1)!
f ' ( xi )
f ( xi 1 ) f ( xi ) h R1
1!
6
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solve for the 1st derivative
' f ( xi 1 ) f ( xi )
f ( xi ) O ( h) 2 pt. formula
h
f ( xi 1) f ( xi ) f ( xi )
1st forward divided difference
' f ( xi )
f ( xi ) O
( h)
h
order of the 1st order accurate
1st derivative truncation error
estimate
7
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
First derivative with backward divided difference
8
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Consider a function f(xi-1) which can be expanded in a Taylor
series in the neighborhood of a point xi and
h xi xi 1 : step size
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
Truncate the series after the 1st derivative term and solve for the 1st
derivative
' f ( xi ) f ( xi 1 )
f ( xi ) O ( h) 2 pt. formula
h
xi 1 xi 1 2h
f ' ( xi ) f ( 3) ( xi ) 3 f ( n ) ( xi ) n
f ( xi 1 ) f ( xi 1 ) 2 h2 h 2 h Rn
1! 3! n!
n is odd.
Truncate the series after the 1st derivative term and solve for the
1st derivative
11
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
2 pt. formula
f ( xi 1 ) f ( xi 1 )
f ( xi )
'
O(h 2 ) 2nd order accurate
2h
f ( xi )
f ( xi )
'
O(h 2 )
2 h
order of the
1st derivative truncation error
estimate
f (0.5) 0.9344
13
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Higher order derivatives
Second derivative with forward divided difference
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
f ' ( xi ) f " ( xi ) f ( n)
( xi )
f ( xi 2 ) f ( xi ) 2h ( 2h)
2
(2h) n Rn
1! 2! n!
xi 1 xi h
xi 2 xi 2h 14
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Truncate the series after the 2nd derivative term
f ' ( xi ) f " ( xi ) 2
f ( xi 1 ) f ( xi ) h h R2
1! 2!
f ' ( xi ) f " ( xi )
f ( xi 2 ) f ( xi ) 2h (2h) 2 R2
1! 2!
Multiply f(xi+1) by 2 and subtract that from f(xi+2)
f ( xi 2 ) 2 f ( xi 1 ) f ( xi ) f ( xi )h 2 O(h3 )
15
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solve for the 2nd derivative
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f '' ( xi ) O
( h)
2
h
order of the
2 nd derivative truncation error
estimate
j n
n
f ( xi ) (1) f ( xi (n j )h)
n
j 0 j
fi 3 fi 1 3 fi 2 fi 3
Example:
f ' ' ' x 3
O h
h
17
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Second derivative with backward divided difference
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
f ' ( xi ) f " ( xi ) 2 f ( n)
( xi )
f ( xi 2 ) f ( xi ) 2h ( 2h) (2h n ) Rn
1! 2! n!
xi xi 1 h
xi xi 2 2h 18
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Truncate the series after the 2nd derivative term
f ' ( xi ) f " ( xi ) 2
f ( xi 1 ) f ( xi ) h h R2
1! 2!
f ' ( xi ) f " ( xi )
f ( xi 2 ) f ( xi ) 2h (2h) 2 R2
1! 2!
Multiply f(xi-1) by 2 and subtract that from f(xi-2)
f ( xi 2 ) 2 f ( xi 1 ) f ( xi ) f ( xi )h 2 O(h3 )
19
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solve for the 2nd derivative
'' f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi ) O
( h)
2
h
order of the
2 nd derivative truncation error
estimate
2 f ( xi )
f ( xi ) O ( h) 1st order accurate
h2
For the nth derivative
n
f ( xi )
O(h) f ( xi )
n nth backward divided
( n)
f ( xi ) difference
n
h
20
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
General equation for nth order backward divided difference
j n
n
f ( xi ) (1) f ( xi jh)
n
j 0 j
Example: f '''
x fi 3 3 fi 23 3 fi 1 fi
Oh
h
21
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Second derivative with central divided difference
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
Add these terms and truncate the series after the 2nd derivative term
f ( xi 1 ) f ( xi 1 ) 2 f ( xi ) f " ( xi )h 2 O(h 4 )
" f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
f ( xi ) O(h 2 ) 2nd order accurate
h2
22
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
2 f ( xi ) f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
2
f ( xi )
f " ( xi ) 2
O ( h 2
)
h
n f ( xi )
f ( n) ( xi ) O(h 2 )
hn
23
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
General equation for nth order central divided difference
j n
n
n
f ( xi ) (1) f ( xi ( j )h)
n
j 0 j 2
h h
When n is odd, f ( xi ) f ( xi )
n n
2 2
2
• Write the equation for δn(x) and then substitute x-(h/2) and
x+(h/2) for x and take the average.
Example: 1 1
f i 2 f i 1 f i 1 f i 2
f ' ' ' x 2
h3
2 O h 2
24
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 23.2: Use the following data to find velocity and
acceleration. Use the appropriate divided difference equations
which give the most accurate result.
Time (s) 0 1 2 3 4 5 6 7 8
Position (m) 0 0.7 1.8 3.4 5.1 6.5 7.3 8.0 8.4
Answer:
velocity 0.7 0.9 1.35 1.65 1.55 1.1 0.75 0.55 0.4
(m/s)
acceleration 0.4 0.4 0.5 0.1 -0.3 -0.6 -0.1 -0.3 -0.3
(m/s2)
25
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
High Accuracy Differentiation Equations
• High-accuracy divided-difference formulas can be generated by
including additional terms from the Taylor series expansion.
1st derivative with forward divided difference
f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi )h h R2
2
f ( xi 1 ) f ( xi ) f ( xi )
f ( xi ) h O(h 2 )
h 2
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi )
h2
26
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
f ( xi 1 ) f ( xi ) f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi ) 2
h O ( h 2
)
h 2h
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ( xi ) O(h 2 )
2h
27
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1st derivative with backward divided difference
f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi )h h R2
2
f ( xi ) f ( xi 1 ) f ( xi )
f ( xi ) h O(h 2 )
h 2
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi )
h2
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ( xi ) O(h 2 )
2h
28
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Coefficient Tables for Calculating Derivatives with an Error Order of O(h2)
Forward Divided Differences
h2f''(x) 2 -5 4 -1 O h
2
h3f'''(x) -5/2 18/2 -24/2 14/2 -3/2
h4fıv(x) 3 -14 26 -24 11 -2
f ( xi 2 ) 8 f ( xi 1 ) 8 f ( xi 1 ) f ( xi 2 )
f ( xi ) O(h 4 )
12h
Drive the formula for the central divided difference for the 1st
derivative and show that it’s 4th order accurate.
Central Divided Differences
30
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Richardson Extrapolation
D D(h ) E (h )
D(h1 ) E (h1 ) D(h2 ) E (h2 )
31
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
2
E (h1 ) h 2
h1
1
2
E (h1 ) E (h2 )
E (h2 ) h 2 h2
D(h2 ) D(h1 )
D(h1 ) E (h2 )h1 / h2 2
D(h2 ) E (h2 ) E (h2 )
h1 / h2 2 1
D D(h2 ) E (h2 )
D D(h2 )
1
D(h2 ) D(h1 )
h1 / h2 1
2
If (h2 h1 / 2) 4 1
D D(h2 ) D(h1 )
3 3
Improved estimate of the
derivative It can be shown that the
error of this estimate is O(h4).
32
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 23.3 : Determine the 1st derivative of
f ( x) 2 x sin x
Answer:
33
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Derivatives of Unequally Spaced Data
34
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
f ( x) f ( xi 1 )
x xi x xi 1 f ( x ) x xi 1 x xi 1 f ( x ) x xi 1 x xi
xi 1 xi xi 1 xi 1 i
xi xi 1 xi xi 1 i 1
xi 1 xi 1 xi 1 xi
2 x xi xi 1 2 x xi 1 xi 1 2 x xi 1 xi
f ( x) f ( xi 1 ) f ( xi ) f ( xi 1 )
xi1 xi xi 1 xi 1 xi xi 1 xi xi 1 xi 1 xi 1 xi1 xi
f (0.8) 0.715
36
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.