Professional Documents
Culture Documents
ME 361-Differentiation
ME 361-Differentiation
ME 361-Differentiation
Numerical Differentiation
df d 2f
=? , 2
=? , etc.
dx dx
Answer: Replace f(x), or the tabulated data, with a simple function g(x).
Then, operate on g(x) instead
df dg d 2f d 2g
f (x) g (x) , , 2
, etc.
dx dx dx d x2
x - x0
Newton-Gregory forward polynomial s where h is constant
h
s (s - 1) 2 s (s - 1) (s - 2) 3
f(s) Pn (s) = f0 + s Δf0 + Δ f0 + Δ f0 + ...
2! 3!
dPn (x) 1 1 1
f '(s) = f + (2 s - 1) Δ 2
f + . (....) Δ 3
f + ...
h
0 0 0
dx 2 6
If x = x0, f ‘(x0) = ?
1 f -f
Use one term: f '(x 0 ) f0 = 1 0
h h
1 1 2 1
Use two terms: f '(x) f + (2 s - 1) Δ f = - f2 + 4 f1 - 3 f0
h
0 0
2 2h
1
f1 - f 0
-h
f ' (x 0 ) E '(x 0 ) f ''( ) One-term forward
h 2
- h2 '''
f ' (x 0 )
1
f1 - f -1 E ' (x 0 ) f ( ) One-term central
2h 6
f ' (x 0 )
1
- f 2 4 f1 - 3 f 0 h2 ''' Two-term forward
E ' (x 0 ) f ()
2h 3
- h 4 (5)
f ' (x 0 )
1
- f 2 8 f1 - 8 f - 1 f - 2 E ' (x 0 ) f ( ) Two-term central
12 h 30
f ' (x 0 )
1
2 f 3 9 f 2 18 f1 11 f 0 O(h3) Three-term forward
6h
Note that, using central differences, we get better accuracy with two-terms than
we do with four terms using forward differences.
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS
1
f ''(x 0 ) f 2 - 2 f1 + f0 E''(x0 ) h f '''( ) Two-term forward
h2
1 - h 2 (4)
f ''(x 0 ) 2 f1 - 2f0 + f-1 E''(x 0 ) f ( ) Two-term central
h 12
1
f ''(x 0 ) - f3 4 f 2 - 5 f1 + 2 f 0 O(h 2 ) Three-term forward
h2
1
f ''(x 0 ) - f2 16 f1 - 30 f 0 16 f - 1 - f*2 O(h 4 ) Three-term central
12 h 2
n
f (n+1) ( ) n
f (n+1) ( )
f(x) = Pn (x) + x - x i
n+1 !
E(x) = f(x) - Pn (x) = x - x
i 0
i
n+1 !
i 0
d n f (n+1) ( )
E'(x) = f '(x) - Pn (x) = x - x i
dx i 0 n+1 !
d n f (n+1) ( ) d f (n+1) ( ) n
= x - x i n+1! + dx n+1!
dx i 0
x - x i
i 0
d n f (n+1) ( ) f (n+2) ( ) n
E'(x) = x - xi + x - x
n+1 ! n+2 ! i
dx i 0 i 0
d n f (n+1) ( ) f (n+2) ( ) n
E'(x) = x - xi + x - x
n+1 ! n+2 ! i
dx i 0 i 0
If x = xj, one of the tabulated values, the second term becomes zero,
and the first term is reduced to one product of (xj – xi)’s:
f (n+1) ( )
x - xi
n
E'(x j ) =
i 0
j
n+1 !
i j
dP 1 2 f0 3 f0 4 f0
f (x)
'
= f0 - + - + ...
dx h 2 3 4
True % Error 37 % 17 % 9% 6%
Error estimation
h '' h 2 f0 2 f0
One-term forward: '
E (x 0 ) = - f ( ) - 2 =-
2 2 h 2h
2 f0 0.054
E'est (2) =- =- = - 0.027
2h 2
'
True error: Etrue (2) = f ' (2) - P' (2) = - 0.135 - (- 0.085) = - 0.05
1
f ( n ) ( ) nf0 n f ( n ) ( ) Dn f0 n!
h
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS
i 1 2 3 4 5
xi -2 -1 0 1 2
yi 4 -1 2 1 8
d) Compare answers in (b) and (c) with those of the previous example where a
set of cubic splines is fitted to the same data points;
P4 (x) = 0.16666667 (x+1) (x) (x-1) (x-2) + 0.16666667 (x+2) (x) (x-1) (x-2) +
0.5 (x+2) (x+1) (x-1) (x-2) - 0.16666667 (x+2) (x+1) (x) (x-2) +
This is the fourth-degree polynomial passing through all the given data points.
The plot is given below.
8.0
6.0
4.0
2.0
0.0
-2.0
-2.0 -1.0 0.0 1.0 2.0
8.0
6.0
4.0
2.0
0.0
-2.0
-2.0 -1.0 0.0 1.0 2.0
Note that the same fourth-degree interpolating polynomial can be found using
the divided difference table and the formula
P4 (x) 4 - 5 (x + 2) + 4 (x + 2) (x + 1) D2fi - 2 (x + 2) (x + 1) x + (x + 2) (x + 1) x (x - 1)
f (n1) ( )
n
E (x) f (x) - Pn (x) (x - x i )
i 0 (n 1) !
The error estimator for the first derivative at a tabulated data point xj is:
n
f (n1) ( )
E (x j ) f (x j ) -
' '
Pn' (x j ) (x j - xi )
i0 (n 1) !
ij
Lagrange form:
P4(0.5) = 1.812500
P4(0.5) = 1.812500
The same answer is obtained because they are the same polynomial.
4
f (5) ( )
Error Calculation: E (x) f (x) - P4 (x) (x - xi )
i 0 5!
f (5) ( )
= (x - x0 ) (x - x1 ) (x - x2 ) (x - x3 ) (x - x 4 )
5!
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS
f (5) ( )
The fifth derivative is to be replaced by the fifth divided difference: D5 f
5!
E (x) (x - x0 ) (x - x1 ) (x - x 2 ) (x - x 3 ) (x - x 4 ) D5 f
But, the fifth divided difference does not exist. From the trend in the divided
difference table, assume that D5f = 0.5. Then:
The error estimate is almost 40 %. It was about 20% with cubic splines.
(c) One may use either the polynomial in Lagrange form or the polynomial
obtained from the divided difference table. It seems that it is easier to take
the first derivative of the later polynomial. Let’s do that:
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS