numerical computation lecture 15: approximating derivatives united international college
TRANSCRIPT
Last Time
• During the last class period we covered:– Bezier Curves and Surfaces– Readings:
• Class Slides
– Due Tomorrow: • Bezier Surface Programming Assignment• Questions?
Today
• We will cover:– Numerical Approximations to Derivatives– Readings:
• Pav, Chapter 7• Homework due on Friday !!
Derivatives
•The derivative represents the rate of change of a dependent variable y (= f(x) ) with respect to an independent variable x. (derivative = f '(x) )
•Example: For f(x) = sin(x) , we have
f '(1)= cos(1)
•For computational algorithms, we can seldom find the exact value of f '(x) as this involves symbolic calculations, so we have to estimate the value of f '(x).
Numerical Estimates of f’(x)
• There are three basic ways to estimate derivatives:– Forward finite divided difference– Backward finite divided difference– Center finite divided difference– All based on the Taylor Series
– Another form of this result is the following, where is some point between x and h.
.........
!2
''' 2 h
xfhxfxfhxf
2
!2
''' h
fhxfxfhxf
Numerical Estimates of f’(x)
• Rearranging this last equation gives
• We will estimate the derivative by dropping the last term. If we can bound the second derivative by some constant, then this last term is O(h) and we get
h
f
h
xfhxfxf
2
'''
)(' hO
h
xfhxfxf
Forward Divided Difference Formula for f’(x)
• Thus,
• This formula is called the first forward divided difference formula and the error in this formula is of order O(h).
• The error in this approximation is due to truncation of the last term (the second derivative term).
h
xfhxfxf
'
Forward Divided Difference Formula for f’(x)
• The truncation error can be made small by making h small. However, as h gets smaller, precision will be lost in this equation due to subtractive cancellation.
• The error in calculation for small h is called roundoff error. Generally the roundoff error will increase as h decreases.
h
xfhxfxf
'
Forward differenceForward difference
x -h x x +h
xh
True derivative
Approximation
Forward Divided Difference Formula for f’(x)
Backward differenceBackward difference
xh
True derivative
Approxi
mat
ion
Backward Divided Difference Formula for f’(x)
x -h x x +h
Backward Divided Difference Formula for f’(x)
• Solving for f’(x) gives:
• Or,
• This is called the Backward Divided Difference Formula for f’(x).
2
!2
''' h
fhxfxfhxf
h
f
h
hxfxfxf
2
'''
)(' hO
h
hxfxfxf
Centered Divided Difference Formula for f’(x)
• Consider the Taylor series expansions for the forward and backward approximations, extended to the degree 3 terms:
• If we subtract these two and solve for f’(x) we get:
62
)(''')('''
2
)()()('
221 hff
h
hxfhxfxf
Centered Divided Difference Formula for f’(x)
• If f’’’ is continuous, we can find a bound on f’’’ and we get the centered divided difference formula:
• Note: Since the error is O(h2), this is a better approximation than the forward or backward approximations!
62
)(''')('''
2
)()()('
221 hff
h
hxfhxfxf
)(2
)()()(' 2hO
h
hxfhxfxf
Centered differenceCentered difference
x2h
True derivative
Approximatio
n
Centered Divided Difference Formula for f’(x)
x -h x x +h
f(x)
x
f(x)
x
f(x)
x
f(x)
x
true derivativeforward
finite divideddifference approx.
backwardfinite divided
difference approx.
centeredfinite divided
difference approx.
Divided Difference Formula for f’’(x)
• Consider the Taylor series expansions for the forward and backward approximations, extended to the degree 4 terms:
• If we add these two and solve for f’’(x) we get:
)()()(2)(
)('' 22
hOh
hxfxfhxfxf
Richardson Extrapolation Formula
• Recall: The forward difference formula for f’(x) had error O(h), while the centered difference formula had error O(h2). Can we do better?
• Consider again the Taylor expansions:
• Let Then, h
hxfhxfh
2
)()()(
....)(')( 66
44
22 hahahaxfh
Richardson Extrapolation Formula
• Also,
• We can use and to get:
• Note: This approximation for f’(x) has error of O(h4)!!
....64
1
16
1
4
1)(')
2( 6
64
42
2 hahahaxfh
)2()(h
h
3
)()2/(4)('
hhxf
Ex19.2: Richardson ExtrapolationEx19.2: Richardson Extrapolation
• We will use the extrapolation method above on the central difference approximation to estimate the first derivative of
at x = 0.5 with h = 0.5 and 0.25 (exact sol. = -0.9125)
2.1x25.0x5.0x15.0x1.0)x(f 234
Richardson Extrapolation Example
9125.03
)()2/(4
934.05.0
)25.0()75.0()2/(
0.11
)0()1(
2
)()()(
hh
ffh
ff
h
hxfhxfh
Ex19.2: Richardson ExtrapolationEx19.2: Richardson Extrapolation
• We can use the Richardson method to increase the accuracy of numerical estimates to any series-based quantity.
• Suppose we want to calculate some quantity L and have found, through theory, an approximation to L:
• Let
General Richardson Extrapolation
)2()0,(
n
hnD
Ex19.2: Richardson ExtrapolationEx19.2: Richardson Extrapolation
• Define:
• Theorem: (Richardson Extrapolation). There are constants akm such that
Proof: By induction. (Skipped) • Corollary:
General Richardson Extrapolation
14
)1,1()1,(4),(
m
m mnDmnDmnD
)(),( )1(2 nhOLnnD
)2()0,(
n
hnD
Ex19.2: Richardson ExtrapolationEx19.2: Richardson Extrapolation
• Example: Consider f(x) = arctan(x). Suppose we want to find . Let and start with
h = 0.01• Then, we compute D(n,m) in a pyramid fashion (as we did
for Newton’s divided differences). The first column is just
• Class Exercise: Verify that these values are correct.• Best Approximation is D(2,2) = 0.333333333333313• Actual Answer is ?
General Richardson Extrapolation
)2('f
)2()0,(
n
hnD
Ex19.2: Richardson ExtrapolationEx19.2: Richardson Extrapolation
• Example: Consider f(x) = arctan(x). What if we just used smaller and smaller values of h?
General Richardson Extrapolation