Вы находитесь на странице: 1из 8

Numerical Differentiation

Numerical Differentiation is a method used to approximate the value of a derivative


over a continuous region [a,b].
Let f(x) be a continuous function with step size h. There are forward, backward, and
centered difference methods to approximate the derivatives of f(x) at a point xi.
5.1 Forward Difference Approximation of the First Derivative
We know
f x lim

x 0

f x x f x
x

For a finite ' x' .


f x

f x x f x
x

f (x)

x x

Figure 5.1: Graphical representation of forward


difference approximation of first derivative
So if you want to find the value of f x at x xi , we may choose another point
' x' ahead as x xi 1 .

f xi

f xi 1 f xi
x

f xi 1 f xi
xi 1 xi

Numerical Analysis /Lec. 5


Third Class

This gives

where x xi 1 xi
- 51 -

Example 5.1
The velocity of a rocket is given by

14 104
t 2000 ln
9.8t , 0 t 30
4
14 10 2100t

where '' is given in m/s and 't ' is given in seconds.


Use forward difference approximation of the first derivative of t to calculate the
acceleration at t 16 s . Use a step size of t 2 s .
Solution
ati

ti 1 ti
t

ti 16
t 2

ti 1 ti t 16 2 18
a16

18 16
2

14 10 4
9.818 453.02m/ s
4
14 10 210018

18 2000 ln

14 104
9.816 392.07m/ s
4
14 10 210016

16 2000 ln

Hence
a16

18 16 453.02 392.07
30.475m / s 2

2
2

The exact value of a16 can be calculated by differentiating


at

d
14 104
2000 ln
9.8t
4
dt
14 10 2100t

14 104 2100t d

14 104

9.8
at 2000
4
4

14 10

dt 14 10 2100t

14 104 2100t
14 104

2000

14 104 2100t
14 104

Numerical Analysis /Lec. 5


Third Class

- 52 -

2100 9.8

a16 29.674m / s 2

The absolute relative true error is


t

True Value - Approximate Value


100
True Value

29.674 30.475
100
29.674

2.6993%

5.2 Backward Difference Approximation of the First Derivative


We know
f x lim

x 0

f x x f x
x

For a finite ' x' ,


f x

If

f x x f x
x

' x' is chosen as a negative number,

f x

f x x f x
x

f x

f x f x x
x

This is a backward difference approximation as you are taking a point backward


from x . To find the value of f x at x xi , we may choose another point ' x'
behind as x xi 1 . This gives
f xi

f xi f xi 1
x

f xi f xi 1
xi xi 1

where

Numerical Analysis /Lec. 5


Third Class

x xi xi 1

- 53 -

f (x)

x x

Figure 5.2 Graphical representation of backward


difference approximation of first derivative
Example 5.2
The velocity of a rocket is given by

14 104
t 2000 ln
9.8t ,0 t 30
4
14 10 2100t

Use backward difference approximation of the first derivative of t to calculate the


acceleration at t 16 s . Use a step size of t 2 s .
Solution
at

ti ti 1
t

ti 16
t 2

ti 1 ti t 16 2 14
a16

16 14
2

14 104
9.816 392.07m / s
4
14 10 210016

16 2000 ln

14 104
9.814 334.24m / s
4
14 10 210014

14 2000 ln

a16

16 14
2

Numerical Analysis /Lec. 5


Third Class

392.07 334.24
28.915m / s 2
2
- 54 -

The absolute relative true error is


t

29.674 28.915
x100
29.674

2.557%

5.3 Central Difference Approximation of the First Derivative


As shown above, both forward and backward divided difference approximation of the
first derivative are accurate on the order of 0x . Can we get better approximations?
Yes, another method to approximate the first derivative is called the Central
difference approximation of the first derivative.
From Taylor series

f xi
x 2 f xi x 3
2!
3!

f xi
x 2 f xi x 3
f xi 1 f xi f xi x
2!
3!
f xi 1 f xi f xi x

(1)
(2)

Subtracting equation (2) from equation (1)


f xi 1 f xi 1 f xi 2x

2 f xi
x 3
3!

f xi

f xi 1 f xi 1 f xi
x 2

2x
3!

f xi

f xi 1 f xi 1
0x 2
2x

f xi

f xi 1 f xi 1
2x

Hence showing that we have obtained a more accurate formula as the error is of the
order of 0x 2 .

Numerical Analysis /Lec. 5


Third Class

- 55 -

f (x)

x x

x x

Figure 5.3 Graphical Representation of central


difference approximation of first derivative.
Example 5.3
The velocity of a rocket is given by

14 104
9.8t ,0 t 30 .
4
14 10 2100t

t 2000 ln

Use central divided difference approximation of the first derivative of t to


calculate the acceleration at t 16s . Use a step size of t 2s .
Solution
at i

t i 1 t i 1
2t

ti 16
t i 1 t i t 16 2 18
t i 1 t i t 16 2 14

a16

18 14 18 14

4
22

14 10 4
9.818 453.02m/ s
4
14 10 210018

18 2000 ln

14 104
9.814 334.24m/ s
4
14 10 210014

14 2000 ln

Numerical Analysis /Lec. 5


Third Class

- 56 -

a16

18 14 453.02 334.24
29.695m / s 2

4
4

The absolute relative true error is


t

29.674 29.695
100
29.674

0.070769%
The results from the three difference approximations are given in Table 1.
Table 1 Summary of a16 using different divided difference approximations.
a16

Type of Difference
Approximation

m / s

t %

Forward
Backward
Central

30.475
28.915
29.695

2.6993
2.557
0.070769

Clearly, the central difference scheme is giving more accurate results because the
order of accuracy is proportional to the square of the step size.
5.4 Higher Order Derivatives
Example:
Second order derivative:
Note that for the centered formulation, it is a derivation of a derivative:
f xi 1 f xi f xi f xi 1

f xi 1 2 f xi f xi 1
h
h
f ' ' x

h
h2

Forward

f ' ' x

f xi 2 2 f xi 1 f x
h2

Backward

f ' ' x

f xi 2 f xi 1 f xi 2
h2

Centered

f ' ' x

f xi 1 2 f xi f xi 1
h2

I) Forward Difference Methods


First Derivative
f ' ( xi )

f xi 1 f xi
h

Second Derivative
f ' ' ( xi )

f xi 2 2 f xi 1 f xi
h2

Numerical Analysis /Lec. 5


Third Class

- 57 -

Third Derivative
f 3 ( xi )

f xi 3 3 f xi 2 3 f xi 1 f xi
h3

Fourth Derivative
f 4 ( xi )

f xi 4 4 f xi 3 6 f xi 2 4 f xi 1 f xi
h4

II) Backward Difference Methods


First Derivative
f ' ( xi )

f xi f xi 1
h

Second Derivative
f ' ' ( xi )

f xi 2 f xi 1 f xi 2
h2

Third Derivative
f 3 ( xi )

f xi 3 f xi 1 3 f xi 2 f xi 3
h3

Fourth Derivative
f 4 ( xi )

f xi 4 f xi 1 6 f xi 2 4 f xi 3 f xi 4
h4

III) Centered Difference Methods


First Derivative
f ' ( xi )

f xi 1 f xi 1
2h

Second Derivative
f ' ' ( xi )

f xi 1 2 f xi f xi 1
h2

Third Derivative
f 3 ( xi )

f xi 2 2 f xi 1 2 f xi 1 f xi 2
2h 3

Fourth Derivative
f 4 ( xi )

f xi 2 4 f xi 1 6 f xi 4 f xi 1 f xi 2
h4

Numerical Analysis /Lec. 5


Third Class

- 58 -

Вам также может понравиться