lecture 8 numerical differentiation formulae by...
TRANSCRIPT
CE 30125 - Lecture 8
p. 8.1
LECTURE 8
NUMERICAL DIFFERENTIATION FORMULAE BY INTERPOLATING POLY-NOMIALS
Relationship Between Polynomials and Finite Difference Derivative Approximations
• We noted that Nth degree accurate Finite Difference (FD) expressions for first derivativeshave an associated error
• If f(x) is an Nth degree polynomial then,
and the FD approximation to the first derivative is exact!
• Thus if we know that a FD approximation to a polynomial function is exact, we canderive the form of that polynomial by integrating the previous equation.
E hN d
N 1+f
dxN 1+
----------------
dN 1+ f
dxN 1+
---------------- 0=
f x a1xN
a2xN 1– aN 1++ + +
CE 30125 - Lecture 8
p. 8.2
• This implies that a distinct relationship exists between polynomials and FD expressionsfor 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
• The approximation for the derivative of some function can be found by
taking the derivative of a polynomial approximation, , of the function.
Procedure
• Establish a polynomial approximation of degree such that
• is forced to be exactly equal to the functional value at data points or nodes
• The derivative of the polynomial is an approximation to the derivative of
pth
f x
pth g x f x
g x N N p
g x N 1+
pth
g x pth
f x
CE 30125 - Lecture 8
p. 8.3
Approximations to First and Second Derivatives Using Quadratic Interpolation
• We will illustrate the use of interpolation to derive FD approximations to first andsecond derivatives using a 3 node quadratic interpolation function
• For first derivatives p=1 and we must establish at least an interpolating polynomialof 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 andsecond derivative approximations
• Apply a shifted coordinate system to simplify the derivation without affecting the gener-ality of the derivation
hhx0 x1 x2
f0 f1 f2x
shifted x axish h0
CE 30125 - Lecture 8
p. 8.4
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 orbackward interpolation approaches in order to establish the interpolating polyno-mial
• The 3 node quadratic interpolating polynomial has the form
• The approximating Lagrange polynomial must match the functional values at all data points or nodes ( , , )
g x aox2
a1x a2+ +=
N 1+xo 0= x1 h= x2 2h=
g xo fo= ao02
a10 a2+ + fo=
g x1 f1= aoh2
a1h a2+ + f1=
g x2 f2= ao 2h 2 a1 2h a2+ + f2=
CE 30125 - Lecture 8
p. 8.5
• Setting up the constraints as a system of simultaneous equations
• Solve for , ,
, ,
• The interpolating polynomial and its derivative are equal to:
0 0 1
h2 h 1
4h2 2h 1
ao
a1
a2
fo
f1
f2
=
ao a1 a2
ao
f2 2f1– fo+
2h2
----------------------------= a1
4f1 f2– 3fo–
2h-------------------------------= a2 fo=
g x f2 2f1– fo+
2h2----------------------------- x
2 4f1 f2– 3fo–
2h-------------------------------- x fo+ +=
g1
x f2 2f1– fo+
h2
----------------------------- x4f1 f2– 3fo–
2h--------------------------------+=
CE 30125 - Lecture 8
p. 8.6
Evaluating g(1)(xo) to obtain a forward difference approximation to the first derivative
• Evaluating the derivative of the interpolating function at
• Since the function is approximated by the interpolating function
• Substituting in for the expression for
xo 0=
g1
xo g1
0 =
g1
xo 3fo– 4f1 f2–+
2h------------------------------------=
f x g x
f1
xog
1 xo
g1
xo
f1
xo
3fo– 4f1 f2–+
2h------------------------------------
CE 30125 - Lecture 8
p. 8.7
• Generalize the node numbering for the approximation
• This results in the generic 3 node forward difference approximation to the first deriva-tive at node i
i i+1 i+2
generalized nodal numbering
x0 x1 x2
fi1 3fi– 4fi 1+ fi 2+–+
2h------------------------------------------------
CE 30125 - Lecture 8
p. 8.8
Evaluating g(1)(x1) to obtain a central difference approximation to the first derivative
• Evaluating the derivative of the interpolating function at
• Again since the function is approximated by the interpolating function
• Substituting in for the expression for
x1 h=
g1
x1 g1
h =
g1
x1 f2 2f1– fo+
h2
---------------------------------h4f1 f2 3fo––
2h-------------------------------+=
g1
x1 f2 fo–
2h--------------=
f x g x
f1
x1g
1 x1
g1
x1
f1
x1
f2 fo–
2h--------------
CE 30125 - Lecture 8
p. 8.9
• Generalize the node numbering
• This results in the generic expression for the three node central difference approxima-tion to the first derivative
x0
i-1
x1 x2
i i+1
fi1 fi 1+ fi 1––
2h--------------------------
CE 30125 - Lecture 8
p. 8.10
Evaluating g(1)(x2) to obtain a backward difference approximation to the first derivative
• Evaluating the derivative of the interpolating function at
• Again since the function is approximated by the interpolating function
• Substituting in for the expression for
x2 2h=
g1
x2 g1
2h =
g1
x2 f2 2f1– fo+
h2
---------------------------------2h4f1 f2 3fo––
2h-------------------------------+=
g1
x2 3f2 4f1– fo+
2h-------------------------------=
f x g x
f1
x2g
1 x2
g1
x2
f1
x2
3f2 4f1– fo+
2h-------------------------------
CE 30125 - Lecture 8
p. 8.11
• Generalizing the node numbering
• This results in the generic expression for a three node backward difference approxima-tion to the first derivative
x0
i-1
x1 x2
ii-2
fi1 3fi 4fi 1–– fi 2–+
2h-------------------------------------------
CE 30125 - Lecture 8
p. 8.12
Evaluating g(2)(xo) to obtain a forward difference approximation to the second derivative
• We note that in general can be computed as:
• Evaluating the second derivative of the interpolating function at :
• Again since the function is approximated by the interpolating function , thesecond derivative at node xo is approximated as:
g2
x
g 2 x f2 2f1– fo+
h2
-----------------------------=
xo 0=
g2
xo g2
0 =
g2
xo f2 2f1– fo+
h2
----------------------------=
f x g x
f2
xog
2 xo
CE 30125 - Lecture 8
p. 8.13
• Substituting in for the expression for
• Generalizing the node numbering
• This results in the generic expression for a three node forward difference approximationto the second derivative
g2
xo
f2
xo
f2 2f1– fo+
h2
----------------------------
x2
i+2
x1
i+1
x0
i
fi2 fi 2+ 2fi 1+– fi+
h2
----------------------------------------
CE 30125 - Lecture 8
p. 8.14
Evaluating g(2)(x1) to obtain a central difference approximation to the second derivative
• Evaluating the second derivative of the interpolating function at :
• Again since the function is approximated by the interpolating function , thesecond derivative at node x1 is approximated as:
• Substituting in for the expression for
x1 h=
g2
x1 g2
h =
g2
x1 f2 2f1– fo+
h2
----------------------------=
f x g x
f2
x1g
2 x1
g2
x1
f2
x1
f2 2f1– fo+
h2
----------------------------
CE 30125 - Lecture 8
p. 8.15
• Generalizing node numbering
• This results in the generic expression for a three node central difference approximationto the second derivative
Notes on developing differentiation formulae by interpolating polynomials
• In general we can use any of the interpolation techniques to develop an interpolationfunction of degree . We can then simply differentiate the interpolating functionand evaluate it at any of the nodal points used for interpolation in order to derive anapproximation 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).
x0 x1 x2
i i+1i-1
fi2 fi 1+ 2fi– fi 1–+
h2
----------------------------------------
N p
CE 30125 - Lecture 8
p. 8.16
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 establishfinite difference formulae by simply differentiating the error estimate associated withthe 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 ( ) has 3 associated nodes ( ) orinterpolating points. We again assume that the nodes are evenly distributed as:
• With a quadratic interpolating polynomial, we can derive differentiation formulae forboth the first and second derivatives but no higher
N 2= N 1+ 3=
x0 x1 x2
f0 f1 f2
h h
x
CE 30125 - Lecture 8
p. 8.17
• The approximating or interpolating function is defined using Newton forward interpola-tion as:
• The error can be approximately expressed in either of the following forms:
• 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.
f x g x e x +=
g x fo x xo– fo
h--------
12!----- x xo– x x1–
2fo
h2
----------+ +=
e x x xo– x x1– x x2–
3!--------------------------------------------------------f
3 = xo x2
e x x xo– x x1– x x2–
3!--------------------------------------------------------fo
3
e x x xo– x x1– x x2–
3!--------------------------------------------------------
3fo
h3
----------
x =
CE 30125 - Lecture 8
p. 8.18
• The forward difference operators are defined as:
Deriving a central approximation to the first derivative and the associated error estimate
• Evaluating the first derivative of the function at :
fo f1 fo–
2fo f2 2f1– fo+
x1
f1
x x1=g
1 x1 e
1 x1 +=
x0 x1 x2
central
CE 30125 - Lecture 8
p. 8.19
• Evaluating in the previous expression
g1
x
f1
x x1=
fo
h--------
12!----- x xo–
2fo
h2
----------12!----- x x1–
2fo
h2
---------- e1
x + ++x x1=
=
f1
x x1=
fo
h--------
12!----- x1 xo–
2fo
h2
---------- e1
x1 + +=
f1
x x1=
f1 fo–
h--------------
12---
h
h2
----- f2 2f1– fo+ e1
x1 + +=
f1
x x1=
f2 fo–
2h-------------- e
1 x1 +=
CE 30125 - Lecture 8
p. 8.20
• Now evaluate using a non dependent expression for the error term and evalu-ating this expression at
• Substituting for results in:
e1
x x1
e1
x1 13!----- f
3 xo x x1– x x2– x xo– x x2– x xo– x x1– + + x x1=
e1
x1 13!----- f
3 xo x1 xo– x1 x2–
e1
x1 h
2
3!----- f
3 xo –
e1
x1
f1
x x1=
f2 fo–
2h--------------
h2
3!----- f
3 xo –
CE 30125 - Lecture 8
p. 8.21
• Generalizing node numbering as:
• This results in the generic expression for a three node central difference approximationto the first derivative with an appropriate error estimate
x0 x1 x2
i i+1i-1
fi1 fi 1+ fi 1––
2h-------------------------- E+=
E h2
6----- f 3 xi 1– –
CE 30125 - Lecture 8
p. 8.22
• Notes
• The same discrete differentiation formulae can be derived using the Taylor seriesapproach.
• The results for the error estimates are the same regardless of whether you:
• Apply differentiation to , which represents the error estimate for .
• Apply a Taylor series analysis to the differentiation formula you derived.
• The error estimate for the interpolating function with is most precise in aformal sense (i.e. it includes all H.O.T. as well!). However there is a weak depen-dence of on and therefore some inaccuracies may be incurred when differenti-ating to obtain an error estimate for the corresponding finite differenceapproximation.
• Practically, for estimating the error of the differentiating formula derived by esti-
mating , we can apply the procedure used and examine an estimate of theerror which does not depend on . This is equivalent to examining the leading orderterm in the truncated series.
• Note that the derivative in the error formula on the previous page may also be esti-mated at
e x g x
g x
x
e x
e1
x
xi
CE 30125 - Lecture 8
p. 8.23
Deriving a forward difference approximation to the second derivative and the associated error estimate
• Evaluating the second derivative of the function at :
• Evaluate and substitute
xo
f2
x xo=g
2 xo e
2 xo +=
x0 x1 x2
forward
g2
x
f2
x xo=12!-----2
fo
h2
----------12!-----2
fo
h2
---------- e2
x + +x xo=
=
f2
x xo=
2fo
h2
---------- e2
xo +=
f2
x xo=
f2 2f1– fo+
h2
---------------------------- e2
xo +=
CE 30125 - Lecture 8
p. 8.24
• Now evaluate using a non dependent expression for the error term and evalu-ating this expression at
• Substituting for results in:
e2
x xo
e2
xo 13!----- f
3 xo x x1– x x2– x xo– x x2– x xo– x x1– + + + + + x xo=
e2
xo 13!----- f
3 xo xo x1– xo x2– xo xo– xo x2– xo xo– xo x1– + + + + +
e2
xo 13!----- f
3 xo h– 2h– 0 2h– 0 h–+ +
e2
xo h f3
xo –
e2
xo
f2
x xo=
f2 2f1– fo+
h2
---------------------------- hf3
xo –
CE 30125 - Lecture 8
p. 8.25
• Generalizing the node numbering:
• This results in the generic expression for a three node forward difference approximationto the second derivative with an appropriate error estimate
x0 x1 x2
i i+2i+1
f 2 fi 2+ 2fi 1+– fi–
h2--------------------------------------- E+=
E hf3
xi –
CE 30125 - Lecture 8
p. 8.26
SUMMARY OF LECTURE 6, 7 AND 8
• Difference formulae can be developed such that linear combinations of functionalvalues at various nodes approximate a derivative at a node.
• In general, to develop a difference formula for you need nodes for accu-racy and 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
• when nodes are used
• Substitute in Taylor series expansions for , etc. about node , re-arrange equa-tions such that coefficients multiply equal order derivatives at node and generate
algebraic equations by setting the coefficient of equal to 1 and the other coefficients equal to zero.
• Solve for , , ...
fip
p 1+ O h p N+
fip E–
a f a f a f+ + +
hp---------------------------------------------------------------=
E O h N= p N+
f f i
i
fip
p N 1–+
a a
CE 30125 - Lecture 8
p. 8.27
• 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. Alsoyou 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 nodes (to evaluate the derivative). Any interpolating tech-nique formula can be used. The numerical differencing formula is simply thedifferentiated interpolating polynomial evaluated at one of the nodes used for interpola-tion. The node at which the formula is evaluated establishes whether the approximationis forward, backward, central, etc.
p 1+ pth