Differentiation of Discrete Function

Numerical Computing
1
Discrete Points x0 , y0 , x1, y1 ,......, xn1, yn1 , xn , yn 
 Find f  xi  where 0<= i <= n
 Solution
 Given



Step1: Get general formula f n (x) for the discrete
points
Step2: Differentiate f n (x) to get f n x
Step3: Substitute With xi in f n x


2
n
n
f n ( x )   Li ( x ) f ( xi )  [
xx
j
j 0
( n  1)!
i 0
] f
n 1
( ( x ))
n
x
xj
j 0
Where Error = [
( n  1)!
] f
n 1
( ( x ))
th
and ‘ n ’ in f n (x) stands for the n order polynomial that approximates
the function f (x) given at (n  1) data points as x0 , y0 , x1 , y1 ,......, xn1 , yn1 , xn , yn 
, and Li ( x) 
n
x  xj
x x
j 0
j i
i
j
Li (x) a weighting function that includes a product of (n  1)
terms with terms of
ji
omitted.
3


Then to find the first derivative, one can differentiate f n x 
once, and so on for other derivatives.
For example, the second order Lagrange polynomial passing
through x0 , y0 , x1, y1 , x2 , y2  is
f 2 x  
x  x1 x  x2  f x   x  x0 x  x2  f x   x  x0 x  x1  f x 
x0  x1 x0  x2  0 x1  x0 x1  x2  1 x2  x0 x2  x1  2
n
[
xx
j 0
(n  1)!
j
]  f n 1 ( ( x))
Differentiating equation (2) gives Three Point Formula
4
f 2x   L0 ( x)  f x0   L1( x)  f x1   L2 ( x)  f x2 
n
 Dx[
xx
j 0
(n  1)!
 This
[
f
n
j
] f
n 1
( ( x))  [
term equals
n
( ( x))
]   xi  x j
(n  1)!
j 0
n 1
xx
j 0
(n  1)!
j
]  Dx[ f
n 1
 This
( ( x))]
term equals
zero WHY??
i j
WHY??
5

x  x1 x  x2  x 2  x1 x  x2 x  x1 x2 
L0 ( x) 

x0  x1 x0  x2  x0  x1 x0  x2 

2 x  x1  x2 
L0 ( x) 
x0  x1 x0  x2 

2 x  x0  x2 
L1( x) 
x1  x0 x1  x2 

2 x  x0  x1 
L2 ( x) 
x2  x0 x2  x1 
6


2x  x  x 
2x  x  x 
f x  
 f x  
 f x 
x  x x  x 
x  x x  x 

2x  x  x 
1

 f x    f ( )   x  x
x  x x  x 
3!
j
2
1
2
j
j
0
2
0
0
1
0
1
2
1
0
1
2
2
j
0
1
3
2
2
0
2
 Three
1
j
j
i 0
j i
Point Formula For unequally
discrete points
7
i
 Eq1
 To


become specially for equally spaced points
X1 = X0 + h
X2 = X0 + 2h


Where h is the step size
Xj may be X0 or X1 or X2
8

Assume Xj=X0 , X1= X0+h, X2= X0+2h then
Substitute in general rule  Eq 1

2 x0  x0  h  x0  2h 
f 2 x0  
 f x0 
x0  x0  h x0  x0  2h 

2 x0  x0  x0  2h 

 f x1 
x0  h  x0 x0  h  x0  2h 

2 x0  x0  x0  h 

 f  x2 
x0  2h  x0 x0  2h  x0  h 
1
3
  f ( 0 )  ( x0  x0  h)( x0  x0  2h)
3!
9


 3h 
 2h 
f 2 x0  
 f  x0  
 f  x1 
2
2
2h 

 h   f  x   1 
2
2
2h 
3!
 h 
f 3 ( 0 )  ( 2h 2 )
1 3
f 2 x0   [
 f  x0   2  f  x0  h 
h 2
1
h2
3
  f  x0  2h ] 
 f ( 0 )
 Eq 2
2
3
 Three
Point Formula For equally discrete
points Xj=X0
10

Assume Xj=X1=X0+h , X1= X0+h, X2= X0+2h then
Substitute in general rule  Eq 1

2 x0  2h  x0  h  x0  2h 
f 2x1  
 f x0 
x0  x0  h x0  x0  2h 

2 x0  2h  x0  x0  2h 

 f x1 
x0  h  x0 x0  h  x0  2h 

2 x0  2h  x0  x0  h 

 f  x2 
x0  2h  x0 x0  2h  x0  h 
1
3
  f ( 1 )  ( x0  h  x0 )( x0  h  x0  2h)
3!
11


 h
h
f 2x1  
 f x0   0  2
2
2h 
1 3
 f x2    f ( 1 )  (h 2 )
2h
6
 
1 1
1
h
f 2x0  h   [  f x0    f x0  2h ]   f 3 ( 1 )
h 2
2
6
2
1 1
1
h2
f 2x0   [  f x0  h    f x0  h ]   f 3 ( 1 )
h 2
2
6
 Eq3
 Three
Point Formula For equally discrete
points Xj=X1
12

Assume Xj=X2=X0+2h , X1= X0+h, X2= X0+2h then
Substitute in general rule  Eq 1

2 x0  4h  x0  h  x0  2h 
f 2x2  
 f x0 
x0  x0  h x0  x0  2h 

2 x0  4h  x0  x0  2h 

 f  x1 
x0  h  x0 x0  h  x0  2h 

2 x0  4h  x0  x0  h 

 f  x2 
x0  2h  x0 x0  2h  x0  h 
1
3
  f ( 2 )  ( x0  2h  x0 )( x0  2h  x0  h)
3!
13
h
2h
f 2 x2  
 f  x0  
 f  x1 
2
2
2h
h
3h
1
3
2




f
x


f
(

)

(
2
h
)
2
2
2
2h
3!
1 1
f 2 x0  2h   [  f  x0   2  f  x0  h 
h 2
2
3
h
3
  f  x0  2h ] 
 f ( 2 )
2
3
14
f 2 x0  
1 1
[  f  x0  2h   2  f  x0  h 
h 2
3
h2
  f  x0 ] 
 f 3 ( 2 )
2
3
f 2 x0  
1 3
[  f  x0   2  f  x0  h 
h 2
1
h2
 Eq 4
  f  x0  2h ] 
 f 3 ( 2 )
2
3
 Three
Point Formula For equally discrete
points Xj=X2
15
1 3
1
h2
f 2 x0   [
 f  x0   2  f  x0  h    f  x0  2h ] 
 f 3 ( 0 )
h 2
2
3
 Eq 2
1 1
1
h2
f 2 x0   [  f  x0  h    f  x0  h ] 
 f 3 ( 1 )
h 2
2
6
 Eq3
1 3
1
h2
f 2 x0   [  f  x0   2  f  x0  h    f  x0  2h ] 
 f 3 ( 2 )
h 2
2
3

 Eq 4
Notes

Eq 2 = Eq 4 by replacing h with –h

Using +h in Eq2  forward differences formula
Using –h in Eq2 backward differences formula

16
f 4 x0  
1
[ 25 f  x0   48 f  x0  h   36 f  x0  2h 
12h
h4
 16 f  x0  3h   3 f  x0  4h ] 
 f 5 ( )
 Eq5
5
f 4 x0  
1
[ f  x0  2h   8 f  x0  h   8 f  x0  h 
12h
h4
 Eq 6
 f  x0  2h ] 
 f 5 ( )
30

Notes
Use Eq 5 with +h if xdesired is the first point forward diff.
 Use Eq 5 with -h if xdesired is the last point  backward diff.
 Using Eq 6 if xdesired is the mid point

17
this data below approximate f 2.0 using
all possible three point formulas and five point
formulas
x
f
(
x
)

xe
 Given
find the error of each
formula
 Given
X
F(x)
1.8
10.889365
1.9
12.703199
2.0
14.778112
2.1
17.148957
2.2
19.855030
18
1
f 2 x0   2 [ f  x0  h   2 f  x0   f  x0  h ]
h
h2
4

 f ( )
 Eq 7
24
19