Numerical Differentiation

Download Report

Transcript Numerical Differentiation

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

:

x i

-1 ,

x i

, and

x i

+1 with

x i

-1 slopes of various secant lines with the corresponding

y

<

x i

<

x i

+1 we can form the values

y i

-1 =

f(x i

-1

)

,

y i

=

f(x i )

and

y i

+1 =

f(x i

+1

)

to estimate the derivative.

Forward Differences

f f

' '  

i

1   

i

y x i i

 

y y i

 1

x i

 1  

y x i i i

 1

x i

 1 Backward Differences

f f

' '  

i

1   

i

y x y i

 1

x i

 1

i i

y i

 1 

x i

 1 

y i

x i y i

+1

y i y i

-1

f(x) x i

-1

x i x i

+1

Central Difference

f

'  

i

y i

 1

x i

 1  

y i

 1

x i

 1

y i

+1

y i y i

-1

f(x) x i

-1

x i x i

+1 If we assume the data are evenly spaced so that

x i

-

x i

-1 below become: =

h

=

x i

+1 -

x i

the formulas Forward Difference

f

'  

i

y i

 1 

y i h

Backward Difference

f

'  

i

y i

 1 

y i h f

Central Difference '  

i

y i

 1  2

h y i

 1 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

x i

-1 three data points?

but make use of all

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

f

'  

i

1  

y i

 1 

x i

 1 4 

y i

x i

 1 3

y i

 1 Three-Point Backward Difference

f

'  

i

1  3

y i

 1 

x i

 1 4 

y i

x i

 1

y i

 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

) 

y i

 1 (

x i

(

x

  1 

x i

)(

x

x i

)(

x i

 1

x

i

 1

x i

)  1 ) 

y i

( (

x x i

 

x i

 1

x i

 1 )( )(

x x i

 

x i x

 1

i

)  1 ) 

y i

 1 (

x

(

x i

 1  

x i

 1 )(

x

x i

 1 )(

x i

 1

x i

 )

x i

)

p

' (

x

) 

y i

 1 (

x i

 1 2

x

x

i x i

)(

x i

  1

x i

  1

x i

 1 ) 

y i

(

x i

2

x

 

x i x i

 1  1 )(

x i

x i

  1

x i

 1 ) 

y i

 1 (

x i

 1 2

x

 

x i x i

 1  1 )( 

x i

 1

x i

x i

)

p

' (

x

) 

y i

 1 (

x i

 1 2

x

 

x i x i

)(

x i

  1

x i

  1

x i

 1 ) 

y i

(

x i

2

x

 

x i x i

 1  1 )(

x i

x i

  1

x i

 1 ) 

y i

 1 (

x i

 1 2

x

x

i x

 1

i

 1 )( 

x i

 1

x i

x i

)

p

' (

x i

 1 ) 

y i

 1 2 (

x i

 1

x

i

 1

x i

 )(

x i x i

  1

x i

  1

x i

 1 ) 

y i

(

x

2

i x

i

 1

x i

  1

x

)(

i

 1

x i

 

x i

 1

x i

 1 ) 

y i

 1 (

x i

2  1

x

i

 1

x i

  1

x i

)(  1

x i

  1

x i

x i

) Consider the data being equally spaced by

h

:

p

' (

x i

 1 ) 

y i

 1

x i

 1 (

x i

 1  

x i

x i

)(

x x i

 1

i

 1  

x i

 1

x i

 1 ) 

y i

(

x i

x i

 1 

x i

 1 )(

x i x i

 1 

x i

 1 ) 

y i

 1 (

x i

 1 

x i

 1

x i

 1  )(

x i x i

 1 

x i

)

p

' (

x i

 1 ) 

y i

 1 (

x i

 1  

h

x i

)(

x

 2

h i

 1 

x i

 1 ) 

y i

(

x i

 2

h

x i

 1 )(

x i

x i

 1 ) 

y i

 1 (

x i

 1  

h x i

 1 )(

x i

 1 

x i

)

p

' (

x i

 1 ) 

y i

 1  3

h

 2

h

2

y i

 2

h

h

2  

h y i

 1 2

h

2   3

y i

 1 2

h

 2

y i h

 

y i

 1 2

h

  3

y i

 1  4

y i

y i

 1 2

h f

'  

i

1  

y i

 1 

x i

 1 4 

y i

x i

 1 3

y i

 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

) 

y i

 1 (

x i

(

x

  1 

x x i i

)(

x

 )(

x i

 1

x

i

 1

x i

)  1 ) 

y i

( (

x

x i

x i

 1 )(

x i

 1 )(

x x i

 

x i x i

 1  1 ) ) 

y i

 1 (

x i

(

x

  1 

x i

 1 )(

x

x i

 1 )(

x i

 1

x i

 )

x i

)

p

(

x

) 

y i

 1

x

( 2 

x i

 1

x i

x

x i x

)(

i

 1

x i x

 1  

x i x i x i

 1 )  1 

y i x

2  (

x i x i

 1 

x

x i

 1

x i

 1

x

)(

x i

 

x i x i

 1  1

x i

 1 ) 

y i

 1

x

( 2 

x i

 1

x i

 1 

x x i

  1

x

)(

i x i x

 1  

x i

 1

x i

)

x i f

' (

x

) 

p

' (

x

) 

y i

 1 (

x i

 1 2

x

x

i x i

)(

x i

  1

x i

  1

x i

 1 ) 

y i

(

x i

2

x

 

x i

 1

x i

 1 )(

x i

x i

  1

x i

 1 ) 

y i

 1 (

x i

 1 2

x

 

x i

 1

x i

 1 )(

x i

  1

x i

x i

) 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 a constant and

h f(x).

We write out the Taylor Series for as the variable and expanding at the point 0.

f(x+h)

treating

x

as

f

(

x

h

) 

f

(

x

) 

f

' (

x

)

h

f

'' (

x

)

h

2 2 !

f

' '' (

x

)

h

3 3 !

f

( 4 ) (

x

)

h

4 4 !

 

f

(

x

h

) 

f

(

x

) 

f

' (

x

)

h

f

'' (

x

)

h

2 2 !

f

' '' (

x

)

h

3 3 !

f

( 4 ) (

x

)

h

4 4 !

 

add !

f

(

x

h

) 

f

(

x

h

) 

f

(

x

h

)  2

f

(

x

)  2 2

f

(

x

) 

f

(

x

h

) 

f f

'' ' ' (

x

)

h

2 2 !

(

x

)

h

2   2 2

f f

( 4 ) (

x

)

h

4 4 !

( 4 ) (

x

)

h

4 4 !

    1

h

2 

f

(

x

h

)  2

f

(

x

) 

f

(

x

h

)  

f

'' (

x

)  2

f

( 4 ) (

x

)

h

2 4 !

 

Example:

i

Find estimates for the derivative with the data set given to the right. We notice the

x

values are evenly spaced.

Two-Point Estimates:

f

' ( 3 ) 

f

' ( 5 )  4  1 5 3   3 4 7  5   3 2  1 2

f

' ( 5 ) 

f

' ( 7 )  4  1 5 3   3 4 7  5  3  2  1 2 1 2 3

f

' ( 5 )  3  1 7  3  2 4  1 2 Forward Backward Central

x i

3 5 7

y i

1 4 3 Three Point Estimates:

f

' ( 3 )   3  4 ( 4 )  3 ( 1 ) 7  3  10 4  5 2 Forward

f

' ( 7 )  3 ( 3 )  4 ( 4 )  1 ( 1 ) 7  3   6  4  3 2 Backward

f

' ' ( 5 )  1 2 2  3  2 ( 4 )  1    4   1 4 Second Derivative (

h

=2)