Numerical Diff
Numerical Diff
1
f (xi+1) = f (xi ) + f (xi )h+ f (xi )h2 +.... (1)
2!
Now let us truncate the series after the first derivative term we have
f (xi ) f (xi+1) − f (xi ) +O(h) (2)
h
where h is called the step size that is, the length of the interval over which the approximation is
made, 𝑥𝑖+1 − 𝑥𝑖 . It is termed a forward difference because it utilizes data at i and i + 1 to
estimate the derivative. This forward difference is but one of many that can be developed from
the Taylor series to approximate derivatives numerically.
A third way to approximate the first derivative is to subtract Eq. (3) from the forward Taylor
series expansion Eq.(1) to yield
2
f (xi+1) = f (xi−1) +2 f (xi )h+ f (3) (xi )h3 +....
3!
which can be solved for
These values can be used to compute the forward difference [Eq. (2)], F(x) 1.2 0.925 0.2
Besides first derivatives, the Taylor series expansion can be used to derive numerical
estimates of higher derivatives. To do this, we write a forward Taylor series expansion for f
(𝑥𝑖+2 ) in terms of f (𝑥𝑖 ):
1
f (xi+2) = f (xi ) + f (xi )(2h) + f (xi )(2h)2 +.... (6)
2!
Equation (1) can be multiplied by 2 and subtracted from Eq. (6) to give
1] y = cos x at x = ; h=
4 12
2] y = e3x+2 at x = 0.5 ; h = 0.1
3] y =x2 cos x at x = 0.4 ; h = 0.5
4] y = tan( 3x ) at x =3 ; h = 0.5
5] y = sin(0.5 x)/ x at x =1 ; h = 0.2
6] y = xln(x +1) at x =1 ; h = 0.2
7] y = tan(x)/ x at x = h=
;
4 12
8] y = ex sin(x) at x = ; h=
3 6
9] y =x2 e4x+1 at x =1 ; h= 0.2
Newton’s forward and backward for differentiation
Another way to find the derivative, we can use Newton’s forward difference
polynomials
1 1
P(x) = f (x0) + f (x0)s + f (x0) s(s −1) +...+ n f (x0) s(s −1)....(s −(n−1)) (1)
2
2! n!
P(x) = f (xn) +f (xn)(s) + 1 2 f (xn)(s)(s +1)+...+ 1 2 f (xn)(s)(s +1)(s +2)...(s +n−1) (2)
2! n!
Where 𝑥 = 𝑥𝑛 + s h
df = df dx = f h
ds dx ds
f = 1 df 1 1 1 1
= [ f (x0) + f (x0)(2s −1) + f (x0)(3s −6s +2) + 4 f (x0)(4s3 −18s2 +22s −6) ]
2 3 2
h ds h 2! 3! 4!
df = df dx = f h
ds dx ds
1 df 1 1 1
f = = 2 [ f (x0)+ f (x0)(6s −6) + 4 f (x0)(12s2 −36s +22) + ]
2 3
h ds h 3! 4!
similarly we can prove
1 1
f = 3 [ f (x0)+ 4 f (x0)(24s −36) + ]
3
h 4!
Example: Find f’’ (1.5) &f’’’(1.5) and f’’(8)& f’’’(8) using the following
table
x 1 3 5 7 9
F(x) 4 5 8 11 16
Solution: since h=2, x=1.5, 𝑥0 =1 , x= 𝑥0 +s h, then 1.5=1+s(2) , hence s=0.25
5 2
3 -2
8 0 4
3 2
11 2
16
1 1 1
f = 2 [ f (x0)+ f (x0)(6s −6) + 4 f (x0)(12s2 −36s +22) + ]
2 3
h 3! 4!
f (1.5) = 1[2−2(0.25−1) + 1 (4)(12(0.25)2 −36(0.25) +22]
4 4!
f = 13 [3 f (x0)+ 1 4 f (x0)(24s −36) + ]
h 4!
f (1.5) = 1[−2+ 1 (4)(24(0.25) −36)]
8 4!