chapter 4 numerical differentiation and integration 1/16 given x 0, approximate f ’(x 0 ). h xfhxf...
TRANSCRIPT
Chapter 4 Numerical Differentiation and Integration
1/16
Given x0, approximate f ’(x0).
h
xfhxfxf
h
)()(lim)(' 00
00
h
xfhxfxf
)()()(' 00
0
x0 x1
h
x1 x0
hh
hxfxfxf
)()()(' 00
0
4.1 Numerical Differentiation
forward
backward
Chapter 4 Numerical Differentiation and Integration -- Numerical Differentiation
Approximate f(x) by its Lagrange polynomial with interpolating points x0 and x0 + h.
f (x) =
)(2
))((
))(())((
00
00
00
00
00
xfhxxxx
xhx
xxhxf
hxx
hxxxf
f ’(x) =
)(2
))((
)(2
)(2)()(
00
000
x
x
fdx
dhxxxx
fhxx
h
xfhxf
f ’(x0) = )(2
)()( 00 fh
h
xfhxf O(h)
2/16
Chapter 4 Numerical Differentiation and Integration -- Numerical Differentiation
Approximate f(x) by its Lagrange polynomial with interpolating points { x0, x1, …, xn }.
)()!1(
))...(()()()( )1(0
0x
nnn
kkk f
n
xxxxxLxfxf
f ’(xj) =
n
jkk
kjj
nn
kjkk xx
n
fxLxf
0
)1(
0
)()!1(
)()()(
Note: Note: In general, more evaluation points produce greater In general, more evaluation points produce greater accuracy. accuracy. On the other hand, the number of functional evaluations On the other hand, the number of functional evaluations grows and the roundoff error increases. Hence the numerical grows and the roundoff error increases. Hence the numerical differentiation is differentiation is unstableunstable!!
3/16
Chapter 4 Numerical Differentiation and Integration -- Numerical Differentiation
Example: Given three points x0, x0 + h, and x0 + 2h, please derive the three-point formulae for each of the points.
)(3
)2(2
1)(2)(
2
31)( 0
)3(2
0000 fh
hxfhxfxfh
xf
)(6
)2(2
1)(
2
11)( 1
)3(2
000 fh
hxfxfh
hxf
)(3
)2(2
3)(2)(
2
11)2( 2
)3(2
0000 fh
hxfhxfxfh
hxf
Symmetric to formula 1, with h < 0.
)(6
)()(2
1)( 1
)3(2
000 fh
hxfhxfh
xf
x–1 x1x0Five-point formulae are given on p.171
4/16
Chapter 4 Numerical Differentiation and Integration -- Numerical Differentiation
Approximate f ”(x0)
Consider Taylor expansions of f(x0 + h) and f(x0 – h) at x0:
41
)4(30
20000 )(
24
1)(
6
1)(
2
1)()()( hfhxfhxfhxfxfhxf
41
)4(30
20000 )(
24
1)(
6
1)(
2
1)()()( hfhxfhxfhxfxfhxf
)(12
)()(2)(1
)( )4(2
00020 fh
hxfxfhxfh
xf
HW: p.176-177 #7, 13
Excuses for not doing homework
I could only get arbitrarily close to my textbook.
I couldn't actually reach it.
5/16
Chapter 4 Numerical Differentiation and Integration -- Elements of Numerical Integration
4.3 Elements of Numerical Integration
Approximate b
adxxfI )( -- Numerical Quadrature
Integrate the Lagrange interpolating polynomial of f (x) instead.
Idea
Select a set of distinct nodes a x0 < x1 <…< xn b from [a, b]. T
he Lagrange polynomial is
n
kkkn xLxfxP
0
)()()(
b
a
b
a k
n
kk dxxLxfdxxf )()()(
0
Ak
b
a kj xx
xx
k dxAjk
j
)(
)(
b
a
n
kk
xn
b
a n
b
a n
b
a
n
kkk
dxxxn
f
dxxRdxxPxf
xfAdxxf
fR
0
)1(
0
)()!1(
)(
)()]()([
)()(
][
Error
interpolatory quadrature
6/16
Chapter 4 Numerical Differentiation and Integration -- Elements of Numerical Integration
Definition: The degree of accuracy, or precision, of a quadrature formula is the largest positive integer n such that the formula is exact for xk for each k = 0, 1, …, n.
Example: Consider the linear interpolation on [a, b], we have
)()()(1 bfab
axaf
ba
bxxP
221
abAA
)]()([
2)( bfaf
abdxxf
b
a
f(x)
a b
f(a)f(b)trapezoidal rule
Please determine the precision of this formula.
Solution: Consider xk for each k = 0, 1, …
x0 = 1: b
aabdx1 ]11[2 ab
=
x : =
x2
:
2
22 abb
adxx ][2 baab
32 33 ab
b
adxx ][ 22
2 baab Degree of Precision = 1
7/16
Chapter 4 Numerical Differentiation and Integration -- Elements of Numerical Integration
For equally spaced nodes: nin
abhhiaxi ,...,1,0,,
dxxx
xxA
nx
xij ji
ji
0 )(
)(
n
ji
inn
ji
dtjtinin
abdth
hjihjt
00)(
)!(!)1)((
)()(
Let htax
Cotes coefficient )(niCNote: Cotes coefficients does not depend on either Note: Cotes coefficients does not depend on either ff((xx) or [) or [aa, , bb], ],
and can be determined by and can be determined by nn and and ii only. Hence we can find these only. Hence we can find these coefficients from a table. The formulae are called coefficients from a table. The formulae are called Newton-Cotes Newton-Cotes formulaeformulae..
21
,21 )1(
1)1(
0 CCn = 1: )]()([2
)( bfafab
dxxfb
a
Trapezoidal Ruledxbxaxf
fRb
a
x ))((!2
)(][
1,],[,)(
121 3 ab
hbafh
Precision = 1
8/16
Chapter 4 Numerical Differentiation and Integration -- Elements of Numerical Integration
n = 2:61
,32
,61 )2(
2)2(
1)2(
0 CCC
)]()(4)([6
)( 2 bffafab
dxxf bab
a
Simpson’s Rule
Precision = 3
2,),(,)(
901
][ )4(5 abhbafhfR
n = 3: Simpson’s 3/8-Rule. Precision = 3, and )(803
][ )5(5 fhfR
n = 4: Cotes Rule. Precision = 5, and )(945
8][ )6(7 fhfR
Theorem: For the (n+1)-point closed Newton-Cotes formula, there exists (a, b) for which
nnnn
kkk
b
adtnttt
n
fhxfAdxxf
0
2)2(3
0
))...(1()!2(
)()()(
if n is even and f Cn+2[a, b], and
nnnn
kkk
b
adtnttt
n
fhxfAdxxf
0
)1(2
0
))...(1()!1(
)()()(
if n is odd and f Cn+1[a, b].
HW: p.195 #7, 9, 11, 13
9/16
Chapter 4 Numerical Differentiation and Integration -- Composite Numerical Integration
4.4 Composite Numerical Integration
Due to the oscillatory nature of high-degree polynomials, piecewise interpolation is applied to approximate f(x) a piecewise approach that uses the low-order Newton-Cotes formulae.
Haven’t we had enough formulae? What’s up
now?
Oh come on, you don’t seriously consider
h=(ba)/2 acceptable, do you?
Why can’t you simply refine the partition if you have to
be so picky?
Don’t you forget the oscillatory nature of high-
degree polynomials!Uh-oh
Composite Trapezoidal Rule: ),...,0(, nkhkaxn
abh k
Apply Trapezoidal Rule on each [xk – 1, xk]:
nkxfxfxx
dxxf kk
x
x
kkk
k
,...,1,)]()([2
)( 11
1
1
1
)()(2)(2
n
kk bfxfaf
h
b
a
n
kkk xfxf
hdxxf
11 )]()([
2)( = Tn
),(),()(12
)()(
12)](
12[][
2
12
1
3
bafabh
n
fab
hf
hfR
n
kkn
kk
/*MVT*/
10/16
Chapter 4 Numerical Differentiation and Integration -- Composite Numerical Integration
Composite Simpson’s Rule: ),...,0(, nkhkaxn
abh k
)]()(4)([6
)( 121
1
kkk
x
xxfxfxf
hdxxf
k
k
kx21kx 1kx 4
44
44
])()(2)(4)([6
)(1
0
2
01
21
n
k
n
kkk
b
abfxfxfaf
hdxxf = Sn
)(2180
][ )4(4
fhab
fR
Note: Note: To simplify the notation, we may let To simplify the notation, we may let nn’ = 2’ = 2nn. Then. Then
andandhkaxh
n
abh k
,2
])()(2)(4)([3
kodd keven
kkn bfxfxfafh
S
11/16
Chapter 4 Numerical Differentiation and Integration -- Composite Numerical Integration
Composite integration techniques are all stable.
Example: Consider the Simpson’s Rule with n subintervals on [a, b]. Assume that f (xi) is approximated by f *(xi) such that f (xi) = f *(xi) + i for each i = 0, 1, …, n. Then the accumulated error e(h) is
]24[3
)( 0 kodd keven
nkk
hhe
If | i | < for all i = 0, 1, …, n, then
)(])12/(2)2/(4[3
)( abnhnnh
he
When we refine the partition to ensure accuracy, the increased computation will NOT increase the roundoff error.
12/16
Chapter 4 Numerical Differentiation and Integration -- Composite Numerical Integration
Example: Use Trapezoidal rule and Simpson’s rule with n = 8 to
approximate dxx
1
0 21
4
)1()(2)0(16
1 7
18 fxffT
kk
8
kxk where
= 3.138988494
)1()(2)(4)0(
24
1
odd even4 fxfxffS kk
8
kxk where
= 3.141592502
Solution:
When programming we usually keep dividing the subintervals into 2 equally spaced smaller subintervals. That is, take n = 2k for k = 0, 1, …
When k = 9, T512 = 3.14159202
48 3
1
3
4TT = 3.141592502 = S4
HW: p.204 #7(a)
(b)
13/16
Chapter 4 Numerical Differentiation and Integration -- Romberg Integration
4.5 Romberg Integration
4
12
n
n
TI
TI
][4
1)()(
12
1
2][
2
2 fRfabh
fR nn
),()(12
][2
fabh
fRn Since the error of Trapezoidal rule is
when we reduce the length of each subinterval into a half,
nnnn TT
TTI
3
1
3
4
14
42
2
Solve for I : = Sn
In general: nnn S
TT
14
4 2n
nn CSS
14
422
2
nnn R
CC
14
432
3
Romberg sequence
Romberg method:
< ?
< ?
< ?
… … … … … …
T1 =)0(
0T
T8 =)3(
0T
T4 =)2(
0T
T2 =)1(
0T S1 =)0(
1T
R1 =)0(
3T
S2 =)1(
1T C1 =)0(
2T
C2 =)1(
2T S4 =)2(
1T
14/16
Lab 08. Shape Roof
Time Limit: 2 seconds; Points: 4
The kind of roof shown in Figure 1 is shaped from plain flat rectangular plastic board in Figure 2.
Figure 1 Figure 2
The transection of the roof is a sine curve with altitude l centimeters. Given the length of the roof, your task is to calculate the length of the flat board needed to shape the roof.
15/16
Chapter 4 Numerical Differentiation and Integration -- Richardson’s Extrapolation
4.2 Richardson’s Extrapolation
Generate high-accuracy results while using low-order formulae
Suppose that for some h 0, we have a formula T0(h) that approximates an unknown I, and that the truncation error has the form:
T0(h) I = 1 h + 2 h2 + 3 h3 + …Replace h by half its value, we have
T0(h/2) I = 1 (h/2) + 2 (h/2)2 + 3 (h/2)3 + …
Q: How to improve the accuracy from O(h) to O(h2) ?
...4
3
2
1
12
)()(2 33
22
020
hhIhTT h
...12
)()(2)( 3
22
1020
1
hhIhTT
hTh
...)( 42
312 hhIhT
12
)()(22
1212
hTT h
...)( 22
11 mm
m hhIhT 12
)()(2 121
mm
hm
m hTT
16/16