You are on page 1of 8

Numerical Differentiation

Forward, Backward, Central


Differences
Lagrange Estimation

Numerical Derivatives
In this section we will see how to estimate the value of a derivative based on
knowing only certain function values. This is typical for many applications not to
know the exact function you are dealing with but rather a set of values for it.
The methods that are used tend to separate themselves into methods for values of
the independent variables that are equally spaced and those that are not.
Equally Spaced Data Points
If we consider three values for x: xi-1, xi, and xi+1 with xi-1 < xi < xi+1 we can form the
slopes of various secant lines with the corresponding y values yi-1=f(xi-1), yi=f(xi) and
yi+1=f(xi+1) to estimate the derivative.
Forward Differences

yi yi 1
f ' xi 1
xi xi 1
yi 1 yi

f ' xi
xi 1 xi

Backward Differences

f ' xi 1

yi yi 1
xi xi 1

yi 1 yi
f ' xi
xi 1 xi

f(x)

yi+1
yi
yi-1
xi-1 xi

xi+1

Central Difference

f(x)

yi+1

yi 1 yi 1
f ' xi
xi 1 xi 1

yi
yi-1
xi-1 xi

xi+1

If we assume the data are evenly spaced so that xi-xi-1 = h = xi+1-xi the formulas
below become:
Forward Difference

Backward Difference

Central Difference

y y
f ' xi i 1 i
h

yi 1 yi
f ' xi
h

yi 1 yi 1
f ' xi
2h

If you look in each of these formulas we are only using two pieces of
information. This means we are probably not as accurate as we can be. What if
we would like to estimate the value of the derivative at xi-1 but make use of all
three data points?

Three-Point Difference Formulas for Derivatives (Evenly spaced points)


The two formulas below estimate the value of the derivatives at the endpoints
making use of all three points most often giving a more accurate value for the
derivative.
Three-Point Forward Difference

yi 1 4 yi 3 yi 1
f ' xi 1
xi 1 xi 1

Three-Point Backward Difference

f ' xi 1

3 yi 1 4 yi yi 1
xi 1 xi 1

Both of these formulas come from writing out the Lagrange Interpolating
polynomial for these three points, taking the derivative then plugging in the value
you want.

p ( x) yi 1

( x xi )( x xi 1 )
( x xi 1 )( x xi 1 )
( x xi 1 )( x xi )
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

p ' ( x) yi 1

2 x xi xi 1
2 x xi 1 xi 1
2 x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

p ' ( x) yi 1

2 x xi xi 1
2 x xi 1 xi 1
2 x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

p ' ( xi 1 ) yi 1

2 xi 1 xi xi 1
2 xi 1 xi 1 xi 1
2 xi 1 xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

Consider the data being equally spaced by h:

p ' ( xi 1 ) yi 1

xi 1 xi xi 1 xi 1
xi 1 xi 1
xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

p ' ( xi 1 ) yi 1

h 2 h
2h
h
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

p ' ( xi 1 ) yi 1

3h
2h
h 3 yi 1 2 yi yi 1 3 yi 1 4 yi yi 1

i
i 1
2
2
2
2h
h
2h
2h
h
2h
2h

yi 1 4 yi 3 yi 1
f ' xi 1
xi 1 xi 1

Unequally-Spaced Data Points


In many situations the data points are not equally spaced. To estimate the value of
the derivative we use the Lagrange Polynomial just like before. In this situation
notice that the derivative can be estimated at any point.

p( x) yi 1

p ( x) yi 1

( x xi )( x xi 1 )
( x xi 1 )( x xi 1 )
( x xi 1 )( x xi )
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

x 2 xi x xi 1 x xi xi 1
x 2 xi 1 x xi 1 x xi 1 xi 1
x 2 xi 1 x xi x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

f ' ( x) p' ( x) yi 1

2 x xi xi 1
2 x xi 1 xi 1
2 x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )

Higher Order Derivatives


All the previous formulas we have derived are to estimate the first derivative. What
if we want to estimate the second derivative?

Second derivative estimates rely on writing out the Taylor Series for a modified
version of the function f(x). We write out the Taylor Series for f(x+h) treating x as
a constant and h as the variable and expanding at the point 0.

f ' ' ( x) 2 f ' ' ' ( x) 3 f ( 4) ( x) 4


f ( x h) f ( x ) f ' ( x ) h
h
h
h
2!
3!
4!
f ' ' ( x) 2 f ' ' ' ( x) 3 f ( 4) ( x) 4
f ( x h) f ( x ) f ' ( x ) h
h
h
h
2!
3!
4!
add !
( 4)

f ' ' ( x) 2
f ( x) 4
f ( x h) f ( x h) 2 f ( x ) 2
h 2
h
2!
4!
( 4)
f
( x) 4
2
f ( x h) 2 f ( x ) f ( x h) f ' ' ( x ) h 2
h
4!

1
f ( 4 ) ( x) 2
f ( x h) 2 f ( x ) f ( x h) f ' ' ( x ) 2
h
2
h
4!

Example:

xi

yi

Find estimates for the derivative with the data set


given to the right. We notice the x values are evenly
spaced.

Two-Point Estimates:

4 1 3

53 2
3 4 1
f ' (5)

75 2
f ' (3)

Forward

4 1 3

53 2
3 4 1
f ' (7)

75 2
f ' (5)

f ' (5)

3 1 2 1

73 4 2

Central

Backward

Three Point Estimates:


3 4(4) 3(1) 10 5
f ' (3)

73
4 2

Forward

3(3) 4(4) 1(1) 6 3


f ' ( 7)

73
4
2

Backward

f ' ' (5)

1
4

2
(
4
)

1
22
4

Second Derivative
(h=2)

You might also like