Quick viewing(Text Mode)

Lecture 8 Numerical Differentiation Formulae By

Lecture 8 Numerical Differentiation Formulae By

CE 30125 - Lecture 8

LECTURE 8

NUMERICAL DIFFERENTIATION FORMULAE BY INTERPOLATING POLY- NOMIALS

Relationship Between and Finite Difference Approximations • We noted that Nth degree accurate Finite Difference (FD) expressions for first have an associated error N + 1 N d f Eh ------dxN + 1 •If f(x) is an Nth degree then,

dN + 1f ------= 0 N + 1 dx and the FD approximation to the first derivative is exact!

• Thus if we know that a FD approximation to a polynomial is exact, we can derive the form of that polynomial by integrating the previous equation.

N N – 1 fx a1x +++a2x  aN + 1

p. 8.1 CE 30125 - Lecture 8

• This implies that a distinct relationship exists between polynomials and FD expressions for derivatives (different relationships for higher order derivatives).

• We can in fact develop FD approximations from interpolating polynomials

Developing Finite Difference Formulae by Differentiating Interpolating Polynomials

Concept th • The approximation for the p derivative of some function fx can be found by th taking the p derivative of a polynomial approximation, gx , of the function fx.

Procedure

• Establish a polynomial approximation gx of degree N such that Np

•gx is forced to be exactly equal to the functional value at N + 1 data points or nodes

th th • The p derivative of the polynomial gx is an approximation to the p derivative of fx

p. 8.2 CE 30125 - Lecture 8

Approximations to First and Second Derivatives Using Quadratic

• We will illustrate the use of interpolation to derive FD approximations to first and second derivatives using a 3 node quadratic interpolation function

• For first derivatives p=1 and we must establish at least an interpolating polynomial of degree N=1 with N+1=2 nodes

• For second derivatives p=2 and we must establish at least an interpolating polyno- mial of degree N=2 with N+1=3 nodes • Thus a quadratic interpolating function will allow us to establish both first and second derivative approximations

• Apply a shifted coordinate system to simplify the derivation without affecting the gener- ality of the derivation

f0 f1 f2 x x0 h x1 h x2 0 h h shifted x axis

p. 8.3 CE 30125 - Lecture 8

Develop a quadratic interpolating polynomial • We apply the Power Series method to derive the appropriate interpolating polynomial • Alternatively we could use either Lagrange basis functions or Newton forward or backward interpolation approaches in order to establish the interpolating polyno- mial

• The 3 node quadratic interpolating polynomial has the form

2 gx= aox ++a1xa2

• The approximating Lagrange polynomial must match the functional values at all N + 1

data points or nodes (xo = 0 , x1 = h , x2 = 2h )

2 gxo = fo  ao0 ++a10 a2 = fo

2 gx1 = f1 aoh ++a1ha2 = f1 

2 gx2 = f2  ao2h ++a12h a2 = f2

p. 8.4 CE 30125 - Lecture 8

• Setting up the constraints as a system of simultaneous equations

0 0 1 ao fo 2 h h 1 a1 = f1 2 4h 2h 1 a2 f2

• Solve for ao , a1 , a2

f – 2f + f 4f –3f – f a = ------2 1 o- , a = ------1 2 o- , a = f o 2 1 2 o 2h 2h

• The interpolating polynomial and its derivative are equal to:

f2 – 2f1 + fo 2 4f1 – f2 – 3fo gx= ------x ++------xfo 2h2 2h

1 f – 2f + f 4f – f – 3f gx = ------2 1 o- x + ------1 2 o-  2 h 2h

p. 8.5 CE 30125 - Lecture 8

(1) Evaluating g ( x o ) to obtain a forward difference approximation to the first derivative

• Evaluating the derivative of the interpolating function at xo = 0

1 1 g xo = g 0 

1 –43fo + f1 – f2 g x = ------o 2h

• Since the function fx is approximated by the interpolating function gx

1 1 f  g xo xo

1 • Substituting in for the expression for g xo

1 –43fo + f1 – f2 f  ------xo 2h

p. 8.6 CE 30125 - Lecture 8

• Generalize the node numbering for the approximation

x0 x1 x2 i i+1 i+2 generalized nodal numbering

• This results in the generic 3 node forward difference approximation to the first deriva- tive at node i

1 – 3fi + 4fi + 1 – fi + 2 f  ------i 2h

p. 8.7 CE 30125 - Lecture 8

(1) Evaluating g ( x 1 ) to obtain a central difference approximation to the first derivative

• Evaluating the derivative of the interpolating function at x1 = h

1 1 g x1 = g h 

1 f2 – 2f1 + fo 4f1 – f2 – 3fo g x = ------h + ------ 1 2 h 2h

1 f2 – fo g x = ------1 2h

• Again since the function fx is approximated by the interpolating function gx

1 1 f  g x1 x1

1 • Substituting in for the expression for g x1

1 f2 – fo f  ------x1 2h

p. 8.8 CE 30125 - Lecture 8

• Generalize the node numbering

x0 x1 x2 i-1 i i+1

• This results in the generic expression for the three node central difference approxima- tion to the first derivative

1 fi + 1 – fi – 1 f  ------i 2h

p. 8.9 CE 30125 - Lecture 8

(1) Evaluating g ( x 2 ) to obtain a backward difference approximation to the first derivative

• Evaluating the derivative of the interpolating function at x2 = 2h

1 1 g x2 = g 2h 

1 f – 2f + f 4f – f – 3f  gx = ------2 1 o-2h + ------1 2 o- 2 2 h 2h

1 3f2 – 4f1 + fo g x = ------2 2h

• Again since the function fx is approximated by the interpolating function gx

1 1 f  g x2 x2

1 • Substituting in for the expression for g x2

1 3f2 – 4f1 + fo f  ------x2 2h

p. 8.10 CE 30125 - Lecture 8

• Generalizing the node numbering

x0 x1 x2 i-2 i-1 i

• This results in the generic expression for a three node backward difference approxima- tion to the first derivative

1 3fi – 4fi – 1 + fi – 2 f  ------i 2h

p. 8.11 CE 30125 - Lecture 8

(2) Evaluating g ( x o ) to obtain a forward difference approximation to the second derivative

2 • We note that in general g x can be computed as:

f – 2f + f g2 x = ------2 1 o-  2 h

• Evaluating the second derivative of the interpolating function at xo = 0 :

2 2 g xo = g 0 

2 f2 – 2f1 + fo g xo = ------h2

• Again since the function fx is approximated by the interpolating function gx , the

second derivative at node xo is approximated as:

2 2 f  g xo xo

p. 8.12 CE 30125 - Lecture 8

2 • Substituting in for the expression for g xo

f – 2f + f f2 ------2 1 o- x  2 o h

• Generalizing the node numbering

i i+1 i+2

x0 x1 x2

• This results in the generic expression for a three node forward difference approximation to the second derivative

f – 2f + f f2 ------i + 2 i + 1 -i i  2 h

p. 8.13 CE 30125 - Lecture 8

(2) Evaluating g ( x 1 ) to obtain a central difference approximation to the second derivative

• Evaluating the second derivative of the interpolating function at x1 = h :

2 2 g x1 = g h 

2 f2 – 2f1 + fo g x1 = ------h2

• Again since the function fx is approximated by the interpolating function gx , the

second derivative at node x1 is approximated as:

2 2 f  g x1 x1

2 • Substituting in for the expression for g x1

f – 2f + f f2 ------2 1 o- x  1 h2

p. 8.14 CE 30125 - Lecture 8

• Generalizing node numbering

i-1 i i+1

x0 x1 x2

• This results in the generic expression for a three node central difference approximation to the second derivative

2 f – 2f + f f ------i + 1 i i – 1- i  2 h

Notes on developing differentiation formulae by interpolating polynomials • In general we can use any of the interpolation techniques to develop an interpolation function of degree Np . We can then simply differentiate the interpolating function and evaluate it at any of the nodal points used for interpolation in order to derive an approximation for the pth derivative. • Orders of accuracy may vary due to the accuracy of the interpolating function varying. • Exact accuracy can be obtained by substituting in Taylor series expansions or by consid- ering the accuracy of the approximating polynomial g(x).

p. 8.15 CE 30125 - Lecture 8

Approximations and Associated Error Estimates to First and Second Derivatives Us- ing Quadratic Interpolation • We can derive an error estimate when using interpolating polynomials to establish finite difference formulae by simply differentiating the error estimate associated with the interpolating function.

• We will illustrate the use of a 3 node Newton forward interpolation formula to derive: • A central approximation to the first derivative with its associated error estimate • A forward approximation to the second derivative with its associated error estimate

Developing a 3 node interpolating function using Newton forward interpolation • A quadratic interpolating polynomial (N = 2 ) has 3 associated nodes (N +31 = ) or interpolating points. We again assume that the nodes are evenly distributed as:

f0 f1 f2 x x0 x1 x2 hh

• With a quadratic interpolating polynomial, we can derive differentiation formulae for both the first and second derivatives but no higher

p. 8.16 CE 30125 - Lecture 8

• The approximating or interpolating function is defined using Newton forward interpola- tion as:

fx= gx+ ex

2 f 1  f gx = f ++xx– ------o------xx– xx– ------o  o o o 1 2 h 2! h

xx– o xx– 1 xx– 2 3 ex= ------f  x  x 3! o 2

• The error can be approximately expressed in either of the following forms:

xx– o xx– 1 xx– 2 3 ex ------f 3! o

3 xx– xx– xx–  f ex ------o 1 2 ------o  3 3! h

• These latter two forms which do not involve  are more suitable for the necessary differ- entiation w.r.t. x since  is functionally dependent on x, i.e. = x

p. 8.17 CE 30125 - Lecture 8

• The forward difference operators are defined as:

fo  f1 – fo

2  fo  f2 – 2f1 + fo

Deriving a central approximation to the first derivative and the associated error estimate

• Evaluating the first derivative of the function at x1 :

1 1 1 f = g x1 + e x1 xx= 1

x0 x1 x2

central

p. 8.18 CE 30125 - Lecture 8

1 • Evaluating g x in the previous expression

2 2 1 fo 1  fo 1  fo 1 f = ------+ -----xx– o ------++-----xx– 1 ------e x xx= 1 h 2! 2 2! 2 h h xx= 1

2 1 f 1  f 1 f = ------o- ++----- x – x ------o ex xx= 1 o 1 1 h 2! h2

1 f – f 1 h 1 f = ------1 o- ++------f – 2f + f ex xx= 22 1 o 1 1 h 2h

1 f2 – fo 1 f = ------+ e x1 xx= 1 2h

p. 8.19 CE 30125 - Lecture 8

1 • Now evaluate e x using a non  dependent expression for the error term and evalu- ating this expression at x1

1 1 3 e x1  ----- f xo xx– 1 xx– 2 ++xx– o xx– 2 xx– o xx– 1 3! xx= 1

1 1 3 e x  ----- f x x – x x – x 1 3! o 1 o 1 2

2 1 h 3 e x  – ----- f x 1 3! o

1 • Substituting for e x1 results in:

2 1 f2 – fo h 3 f  ------– ----- f xo xx= 1 2h 3!

p. 8.20 CE 30125 - Lecture 8

• Generalizing node numbering as:

x0 x1 x2

i-1 i i+1

• This results in the generic expression for a three node central difference approximation to the first derivative with an appropriate error estimate

f – f f1 = ------i + 1 i – 1 + E i 2h

2 h 3 E  – ----- f x 6 i – 1

p. 8.21 CE 30125 - Lecture 8

•Notes • The same discrete differentiation formulae can be derived using the Taylor series approach. • The results for the error estimates are the same regardless of whether you: • Apply differentiation to ex , which represents the error estimate for gx . • Apply a Taylor series analysis to the differentiation formula you derived.

• The error estimate for the interpolating function gx with  is most precise in a formal sense (i.e. it includes all H.O.T. as well!). However there is a weak depen- dence of  on x and therefore some inaccuracies may be incurred when differenti- ating ex to obtain an error estimate for the corresponding finite difference approximation.

• Practically, for estimating the error of the differentiating formula derived by esti- 1 mating e x , we can apply the procedure used and examine an estimate of the error which does not depend on  . This is equivalent to examining the leading order term in the truncated series.

• Note that the derivative in the error formula on the previous page may also be esti-

mated at xi

p. 8.22 CE 30125 - Lecture 8

Deriving a forward difference approximation to the second derivative and the associated error estimate

• Evaluating the second derivative of the function at xo :

2 2 2 f = g xo + e xo xx= o

x0 x1 x2

forward

2 • Evaluate g x and substitute

2 2 2 1  fo 1  fo 2 f = ------++------e x xx= o 2! 2 2! 2 h h xx= o

2 2  f 2 f = ------o + ex xx= 2 o o h

2 f – 2f + f 2 f = ------2 1 o- + ex xx= 2 o o h

p. 8.23 CE 30125 - Lecture 8

2 • Now evaluate e x using a non  dependent expression for the error term and evalu- ating this expression at xo

2 1 3 e xo  ----- f xo xx– 1 +++++xx– 2 xx– o xx– 2 xx– o xx– 1 3! xx= o

2 1 3 e x  ----- f x x – x +++++x – x x – x x – x x – x x – x o 3! o o 1 o 2 o o o 2 o o o 1

2 1 3 e x  ----- f x –2h –02h ++–0h – h o 3! o

2 3 e xo  –h f xo

2 • Substituting for e xo results in:

f – 2f + f f2 ------2 1 o- – hf3 x xx=  o o h2

p. 8.24 CE 30125 - Lecture 8

• Generalizing the node numbering:

x0 x1 x2 i i+1 i+2

• This results in the generic expression for a three node forward difference approximation to the second derivative with an appropriate error estimate

f – 2f – f f2 = ------i + 2 i + 1 i + E h2

3 Ehf – xi

p. 8.25 CE 30125 - Lecture 8

SUMMARY OF LECTURE 6, 7 AND 8

• Difference formulae can be developed such that linear combinations of functional values at various nodes approximate a derivative at a node.

p • In general, to develop a difference formula for fi you need p + 1 nodes for Oh accu- racy and pN+ nodes for O(h)N accuracy. Central approximations for even order deriva- tives require fewer nodes due to a fortunate cancelation of error terms. • The generic form to evaluate a difference formula

p a f +++a f  a f fi – E = ------hp

N • EOh=  when pN+ nodes are used

• Substitute in Taylor series expansions for f , f etc. about node i, re-arrange equa- tions such that coefficients multiply equal order derivatives at node i and generate p algebraic equations by setting the coefficient of fi equal to 1 and the pN+ – 1 other coefficients equal to zero.

• Solve for a , a , ...

p. 8.26 CE 30125 - Lecture 8

• Forward, central and backward difference operators can be manipulated in ways analo- gous to differentiation to develop higher order differences

• Formulae to approximate differentiation using the difference operators can be estab- lished. However, general formulae for any order accuracy are difficult to establish. Also you still need Taylor series analysis to derive the accuracy of the approximations.

• Numerical differentiation formulae can be established by defining an interpolating poly- nomial for at least p + 1 nodes (to evaluate the pth derivative). Any interpolating tech- nique formula can be used. The numerical differencing formula is simply the differentiated interpolating polynomial evaluated at one of the nodes used for interpola- tion. The node at which the formula is evaluated establishes whether the approximation is forward, backward, central, etc.

p. 8.27