Professional Documents
Culture Documents
Richardsons Extrapolation
Numerical Integration (Quadrature)
Joe Mahaffy,
hmahaffy@math.sdsu.edui
Department of Mathematics
Dynamical Systems Group
Computational Sciences Research Center
San Diego State University
San Diego, CA 92182-7720
http://www-rohan.sdsu.edu/jmahaffy
Spring 2010
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (1/49)
x
Numerical Differentiation
Richardsons Extrapolation
Numerical Integration (Quadrature)
Outline
1 Numerical Differentiation
Ideas and Fundamental Tools
Moving Along...
2 Richardsons Extrapolation
A Nice Piece of Algebra Magic
Numerical Differentiation
f (x0 + h) f (x0 )
f (x0 ) .
h
Problems: Cancellation and roundoff errors. For small values
of h, f (x0 +h) f (x0 ) so the difference may have very
few significant digits in finite precision arithmetic.
smaller h not necessarily better numerically.
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (4/49)
x
Numerical Differentiation
Ideas and Fundamental Tools
Richardsons Extrapolation
Moving Along...
Numerical Integration (Quadrature)
Previously we have used the family Ln,0 (x), Ln,1 (x), . . . , Ln,n (x) to
build the Lagrange interpolating polynomial. A good tool for
discussing polynomial behavior, but not necessarily for computing
polynomial values (c.f. Newtons divided differences).
Now, lets combine our tools and look at differentiation.
f (x0 + h) f (x0 ) h i
1 h2
= h f (x0 ) + hf (x0 ) + 2 f ((x)) f (x0 )
h
= f (x0 ) + h2 f ((x))
then we have
f (x0 + h) f (x0 ) M|h|
f (x0 ) , with an error less than .
h 2
Qn
d k=0 (x xk )
=
dx (n + 1)!
1
[(x x1 )(x x2 ) (x xn ) + (x x0 )(x x2 ) (x xn ) + ] =
(n + 1)!
n n
1 X Y
(x xk )
(n + 1)!
j=0 k=0,k6=j
n n
X f (n+1) () Y
f (xj ) = f (xk )Ln,k (xj ) + (xj xk )
(n + 1)!
k=0 k=0
k 6= j
Note: The formula is most useful when the node points are equally
spaced (it can be computed once and stored), i.e.
xk = x0 + kh.
Now, we have to compute the derivatives of the Lagrange
coefficients, i.e. Ln,k (x)... [We can no longer dodge this task!]
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (10/49)
x
Numerical Differentiation
Ideas and Fundamental Tools
Richardsons Extrapolation
Moving Along...
Numerical Integration (Quadrature)
Building blocks:
(x x1 )(x x2 ) 2x x1 x2
L2,0 (x) = , L2,0 (x) =
(x0 x1 )(x0 x2 ) (x0 x1 )(x0 x2 )
(x x0 )(x x2 ) 2x x0 x2
L2,1 (x) = , L2,1 (x) =
(x1 x0 )(x1 x2 ) (x1 x0 )(x1 x2 )
(x x0 )(x x1 ) 2x x0 x1
L2,2 (x) = , L2,2 (x) = .
(x2 x0 )(x2 x1 ) (x2 x0 )(x2 x1 )
Formulas:
2xj x1 x2 2xj x0 x2
f (xj ) = f (x0 ) + f (x1 )
(x0 x1 )(x0 x2 ) (x1 x0 )(x1 x2 )
2
2xj x0 x1 f (3) (j ) Y
+ f (x2 ) + (xj xk ).
(x2 x0 )(x2 x1 ) 6
k=0
k 6= j
1 h2
f (x0 ) = [3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (0 )
2h 3
2
1 h
f (x0 + h) = [f (x0 ) + f (x0 + 2h)] f (3) (1 )
2h 6
1 h2
f (x0 + 2h) =
[f (x0 ) 4f (x0 + h) + 3f (x0 + 2h)] + f (3) (2 )
2h 3
Make the substitution x0 + h x0 in the second equation.
1 h2 (3)
f (x0 ) = [3f (x 0 ) + 4f (x 0 + h) f (x0 + 2h)] + f (0 )
2h 3
1 h2 (3)
f (x0 ) = [f (x0 h) + f (x0 + h)] f (1 )
2h 6
1 h2
f (x0 + 2h) =
[f (x0 ) 4f (x0 + h) + 3f (x0 + 2h)] + f (3) (2 )
2h 3
After the substitution x0 + h x0 in the second equation. Next, make
the substitution x0 + 2h x0+ in the third equation.
1 h2 (3)
f (x0 ) = [3f (x 0 ) + 4f (x 0 + h) f (x0 + 2h)] + f (0 )
2h 3
1 h2 (3)
f (x0 ) = [f (x0 h) + f (x0 + h)] f (1 )
2h 6
1 + h2
f (x0+ ) =
f (x0 2h) 4f (x0+ h) + 3f (x0+ ) + f (3) (2 )
2h 3
After the substitution x0 + h x0 in the second equation, and
x0 + 2h x0+ in the third equation.
1 h2
f (x0 ) = [3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (0 )
2h 3
2
1 h
f (x0 ) = [f(x0 h) + f(x0 + h)] f (3) (1 )
2h 6
2
f (x0+ ) = 1 f (x0+ 2h) 4f (x0+ h) + 3f (x0+ ) + h f (3) (2 )
2h 3
After the substitution x0 + h x0 in the second equation, and
x0 + 2h x0+ in the third equation.
Note#1: The third equation can be obtained from the first one by setting h h.
Note#2: The error is smallest in the second equation.
Note#3: The second equation is a two-sided approximation, the first and third one-
sided approximations.
Note#4: We can drop the superscripts ,+ ...
7
2 1.5 1 0.5 0 0.5 1 1.5 2
1 h2
f (x0 ) = [f (x0 h) + f (x0 + h)] f (3) (1 )
2h 6
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (14/49)
x
Numerical Differentiation
Ideas and Fundamental Tools
Richardsons Extrapolation
Moving Along...
Numerical Integration (Quadrature)
7
2 1.5 1 0.5 0 0.5 1 1.5 2
1 h2
f (x0 ) = [3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (0 )
2h 3
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (15/49)
x
Numerical Differentiation
Ideas and Fundamental Tools
Richardsons Extrapolation
Moving Along...
Numerical Integration (Quadrature)
7
2 1.5 1 0.5 0 0.5 1 1.5 2
1 h2
f (x0 ) = [f (x0 2h) 4f (x0 h) + 3f (x0 )] + f (3) (2 )
2h 3
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (16/49)
x
Numerical Differentiation
Ideas and Fundamental Tools
Richardsons Extrapolation
Moving Along...
Numerical Integration (Quadrature)
5-point Formulas
25f (x0 )+48f (x0 +h)36f (x0 +2h)+16f (x0 +3h)3f (x0 +4h) h4 (5)
f (x0 ) = 12h + 5 f ().
7
2 1.5 1 0.5 0 0.5 1 1.5 2
Richardsons Extrapolation
Richardsons Extrapolation
Richardsons Extrapolation
and
X hk
M N1 (h/2) = Ek .
2k
k=1
and
X hk
M N1 (h/2) = Ek .
2k
k=1
If we let N2 (h) = 2N1 (h/2) N1 (h), then
n
h X (2)
M N2 (h) = 2E1 E1 h + Ek h k ,
| 2{z } k=2
0
where
(2) 1
Ek = Ek 1 .
2k1
Hence, N2 (h) is now a second order approximation to M.
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (22/49)
x
Numerical Differentiation
Richardsons Extrapolation A Nice Piece of Algebra Magic
Numerical Integration (Quadrature)
We can play the game again, and combine N2 (h) with N2 (h/2) to get a
third-order accurate approximation, etc.
We can play the game again, and combine N2 (h) with N2 (h/2) to get a
third-order accurate approximation, etc.
Nj (h/2) Nj (h)
Nj+1 (h) = Nj (h/2) +
2j 1
We let
Nj+1 (h) = j Nj (h) + j Nj (h/2)
We let
Nj+1 (h) = j Nj (h) + j Nj (h/2)
hj
M Nj+1 (h) = j Ej hj + (1 j )Ej j
+ O hj+1
2
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (24/49)
x
Numerical Differentiation
Richardsons Extrapolation A Nice Piece of Algebra Magic
Numerical Integration (Quadrature)
Now,
j 1
M Nj+1 (h) = Ej h j + (1 j ) j + O hj+1
2
Now,
j 1
M Nj+1 (h) = Ej h j + (1 j ) j + O hj+1
2
Now,
j 1
M Nj+1 (h) = Ej h j + (1 j ) j + O hj+1
2
Therefore,
Nj (h/2) Nj (h)
Nj+1 (h) = Nj (h/2) +
2j 1
f (x + h) f (x h) h2
f (x0 ) = f () + O(h4 )
| 2h
{z } |6 {z }
N2 (h) error term
f (x + h) f (x h) h2
f (x0 ) = f () + O(h4 )
| 2h
{z } |6 {z }
N2 (h) error term
N(h/2) N(h)
N3 (h) = N2 (h/2) + .
3
f (x + h) f (x h) h2
f (x0 ) = f () + O(h4 )
| 2h
{z } |6 {z }
N2 (h) error term
N(h/2) N(h)
N3 (h) = N2 (h/2) + .
3
f (x+h/2)f (xh/2) f (x+h)f (xh)
f (x+h/2)f (xh/2) 2h/2
2h
N3 (h) = 2h/2 + 3
8f (x+h/2)8f (xh/2) f (x+h)f (xh)
= 6h 6h
1
= 6h [f (x h) 8f (x h/2) + 8f (x + h/2) f (x + h)] .
f (x + h) f (x h) h2
f (x0 ) = f () + O(h4 )
| 2h
{z } |6 {z }
N2 (h) error term
N(h/2) N(h)
N3 (h) = N2 (h/2) + .
3
f (x+h)f (xh) f (x+2h)f (x2h)
f (x+h)f (xh)
N3 (2h) = 2h + 2h
3
4h
Example, f (x) = x 2 e x .
f (x) = (2x + x 2 )e x ,
f (2) = 8e 2 = 59.112.
x f(x)
1.70 15.8197 f (2.1)f (2.0)
= 64.566. (Fwd Difference, 2pt)
1.80 19.6009 0.1
1.90 24.1361 f (2.1)f (1.9)
= 59.384. (Ctr Difference, 3pt)
0.2
2.00 29.5562
2.10 36.0128 f (2.2)f (1.8)
0.4 = 60.201. (Ctr Difference)
2.20 43.6811
2.30 52.7634 (459.38460.201)/3 = 59.111. (Richardson)
f (1.8)8f (1.9)+8f (2.1)f (2.2)
1.2 = 59.111. (5pt)
Numerical Quadrature
Z b n
X
f (x) dx ai fi ,
a i=0
n n
X f (n+1) ((x)) Y
Pn (x) = fi Ln,i (x), with error En (x) = (xxi )
(n + 1)!
i=0 i=0
to obtain
Z b Z b Z b
f (x) dx = Pn (x) dx + En (x) dx
a
|a {z } | a {z }
The Approximation The Error Estimate
Z b Z b n
X Xn Z b n
X
Pn (x) dx = fi Ln,i (x) dx = fi Ln,i (x) dx = fi ai .
a a i=0 i=0 | a
{z } i=0
ai
Z b Z b n
X Xn Z b n
X
Pn (x) dx = fi Ln,i (x) dx = fi Ln,i (x) dx = fi ai .
a a i=0 i=0 | a {z } i=0
ai
Hence we write Z b n
X
f (x) dx ai fi
a i=0
Z b Z b n
X Xn Z b n
X
Pn (x) dx = fi Ln,i (x) dx = fi Ln,i (x) dx = fi ai .
a a i=0 i=0 | a
{z } i=0
ai
Hence we write Z b n
X
f (x) dx ai fi
a i=0
with error given by
Z b Z n
b
f (n+1) ((x)) Y
E (f ) = En (x) dx = (x xi ) dx.
a a (n + 1)!
i=0
R P
Note: Can we change the order of integration and summation as we did above?
In this case where we are integrating a polynomial over a finite interval it is
OK. For technical details see a class on real analysis (e.g. Math 534B).
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (32/49)
x
Numerical Differentiation The Why? and Introduction
Richardsons Extrapolation Trapezoidal & Simpsons Rules
Numerical Integration (Quadrature) Newton-Cotes Formulas
Then
Z b
Z x1
x x1 x x0
f (x) dx = f0 + f1 dx
a x0 x0 x 1 x1 x 0
Z
1 x1
+ f ((x))(x x0 )(x x1 ) dx.
2 x0
where h = x1 x0 = b a.
Joe Mahaffy, hmahaffy@math.sdsu.edui ; Richardsons Extrapolation; R f (x) dx (34/49)
x
Numerical Differentiation The Why? and Introduction
Richardsons Extrapolation Trapezoidal & Simpsons Rules
Numerical Integration (Quadrature) Newton-Cotes Formulas
Hence,
Z b x1
(x x1 )2 (x x0 )2 h3
f (x) dx = f0 + f1 f ()
a 2(x0 x1 ) 2(x1 x0 ) x0 12
(x1 x0 ) h3
= [f0 + f1 ] f ()
2 12
Z b
f(x0 ) + f(x1 ) h3
f(x) dx = h f (), h = b a.
a 2 12
Let x0 = a, x1 = a+b ba
2 , x2 = b, let h = 2 and use the quadratic
interpolating polynomial
Z b Z x2
(x x1 )(x x2 ) (x x0 )(x x2 )
f (x)dx = f (x0 ) + f (x1 )
a x0 (x 0 x 1 )(x 0 x 2 ) (x 1 x0 )(x1 x2 )
(x x0 )(x x1 )
+ f (x2 ) dx
(x2 x0 )(x2 x1 )
Z x2
(x x0 )(x x1 )(x x2 ) (3)
+ f ((x)) dx ...
x0 6
Z b
f(x0 ) + 4f(x1 ) + f(x2 )
f(x) dx = h + O(h4 f (3) ()).
a 3
After use of the weighted mean value theorem, and the the
h2 (4)
approximation f (x1 ) = h12 [f (x0 ) 2f (x1 ) + f (x2 )] 12 f (),
and a whole lot of algebra (see BF pp 189190) we end up with
After use of the weighted mean value theorem, and the the
h2 (4)
approximation f (x1 ) = h12 [f (x0 ) 2f (x1 ) + f (x2 )] 12 f (),
and a whole lot of algebra (see BF pp 189190) we end up with
Z x2
f(x0 ) + 4f(x1 ) + f(x2 ) h5 (4)
f (x) dx = h f ().
x0 3 90
Z b
f(x0 ) + 4f(x1 ) + f(x2 )
f(x) dx = h + O(h5 f (4) ()).
a 3
f(x)
Integration Examples
Rb
f (x) [a, b] a f (x)dx Trapezoidal Error Simpson Error
x [0, 1] 1/2 0.5 0 0.5 0
x2 [0, 1] 1/3 0.5 0.16667 0.33333 0
x3 [0, 1] 1/4 0.5 0.25000 0.25000 0
x4 [0, 1] 1/5 0.5 0.30000 0.20833 0.0083333
ex [0, 1] e1 1.8591 0.14086 1.7189 0.0005793
The approximation is
Z b n
X
f (x) dx ai f (xi ),
a i=0
where Z xn Z xn n
Y (x xj )
ai = Ln,i (x) dx = dx.
x0 x0 (xi xj )
j =0
j 6= i
Theorem
Pn
Suppose that i=0 ai f (xi ) denotes the (n + 1) point closed
Newton-Cotes formula with x0 = a, xn = b, and h = (b a)/n. Then
there exists (a, b) for which
n
b hn+3 f (n+2) () n
Z Z
t 2 (t 1) (t n)dt,
X
f (x)dx = ai f (xi ) +
a i=0
(n + 2)! 0
n = 2: Simpsons Rule
h h5
f (x0 ) + 4f (x1 ) + f (x2 ) f (4) ()
3 90
n = 3: Simpsons 38 -Rule
3h 3h5 (4)
f (x0 ) + 3f (x1 ) + 3f (x2 ) + f (x3 ) f ()
8 80
n = 4: Booles Rule
2h 8h7 (6)
7f (x0 ) + 32f (x1 ) + 12f (x2 ) + 32f (x3 ) + 7f (x4 ) f ()
45 945
The approximation is
Z b Z xn+1 n
X
f (x) dx = f (x) dx ai f (xi ),
a x1 i=0
where
Z xn+1 Z xn n
Y (x xj )
ai = Ln,i (x) dx = dx.
x1 x0 (xi xj )
j =0
j 6= i
Theorem
Pn
Suppose that i=0 ai f (xi ) denotes the (n + 1) point open Newton-Cotes
formula with x1 = a, xn+1 = b, and h = (b a)/(n + 2). Then there
exists (a, b) for which
n
b hn+3 f (n+2) () n+1
Z Z
t 2 (t 1) (t n)dt,
X
f (x)dx = ai f (xi ) +
a i=0
(n + 2)! 1
h3
n=0: 2hf (x0 ) + f ()
3
3h 3h3
n=1: f (x0 ) + f (x1 ) + f ()
2 4
4h 14h5 (4)
n=2: 2f (x0 ) f (x1 ) + 2f (x2 ) + f ()
3 45
5h 95h5 (4)
n=3: 11f (x0 ) + f (x1 ) + f (x2 ) + 11f (x3 ) + f ()
24 144