Numerical Analysis and Computing
Numerical Analysis and Computing
Numerical Analysis and Computing
Romberg Quadrature
Adaptive Quadrature
Gaussian Quadrature
Joe Mahaffy,
[email protected]
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, [email protected] Composite-Romberg-Adaptive-Gaussian (1/43)
Composite Quadrature
Romberg Quadrature
Adaptive Quadrature
Gaussian Quadrature
Outline
1 Composite Quadrature
Divide and Conquer; Example Simpsons Rule
Generalization
Collecting the Error...
2 Romberg Quadrature
Applying Richardsons Extrapolation
Romberg Quadrature Code Outline
3 Adaptive Quadrature
Introduction
Building the Adaptive CSR Scheme
Example...
Putting it Together...
4 Gaussian Quadrature
Ideas...
2-point Gaussian Quadrature
Higher-Order Gaussian Quadrature Legendre Polynomials
Examples: Gaussian Quadrature in Action; HW#7
Z b n/2
h X
f (x)dx = f (x0 ) f (xn ) + 4f (x2j1 ) + 2f (x2j )
a 3
j=1
n/2
h5 X
f (4) (j ).
90
j=1
(b a) 4 (4)
E (f ) = h f ().
180
Hence Composite Simpsons Rule has degree of accuracy 3
(since it is exact for polynomials up to order 3),
and the error is
proportional to h4 Convergence Rate O h4 .
(Part-1)
Implement Composite Simpsons Rule, and use your code to solve
BF-4.4.3-a,b,c,d.
Z b n1
h X (b a) 2
f (x)dx = f (a) + f (b) + 2 f (xj ) h f ()
a 2 12
j=1
1 1 1
0 0 0
0 1 2 3 0 1 2 3 0 1 2 3
k Rk,1
1 0
2 1.5707963267949
3 1.8961188979370
4 1.9742316019455
5 1.9935703437723
6 1.9983933609701
7 1.9995983886400
Rk,1 Rk1,1
Rk,2 = Rk,1 +
22 1
Rk,1 O h2
`
Rk,2
0 0
1.5707963267949 2.09439510239
1.8961188979370 2.00455975498
1.9742316019455 2.00026916994
1.9935703437723 2.00001659104
1.9983933609701 2.00000103336
1.9995983886400 2.00000006453
Extrapolate, again...
It turns out (Taylor expand to check) that the complete error term
for the Trapezoidal rule only has even powers of h:
Z b
X
f (x) = Rk,1 E2i hk2i .
a i=1
Hence the Rk,2 approximations have error terms that are of size
O(h4 ).
To get O(h6 ) approximations, we compute
Rk,2 Rk1,2
Rk,3 = Rk,2 +
42 1
0
1.570796326794897 2.094395102393195
1.896118897937040 2.004559754984421 1.998570731823836
1.974231601945551 2.000269169948388 1.999983130945986 2.000005549979671
1.993570343772340 2.000016591047935 1.999999752454572 2.000000016288042
1.998393360970145 2.000001033369413 1.999999996190845 2.000000000059674
1.999598388640037 2.000000064530001 1.999999999940707 2.000000000000229
0.5
-0.5
-1
-1.5
-10 0 10
Idea Cleverly predict (or measure) the amount of variation and au-
tomatically add more points where needed.
We are going to discuss this in the context of Composite
Simpsons rule, but the approach can be adopted for other
integration schemes.
First we are going to develop a way to measure the error
a numerical estimate of the actual error in the numerical
integration. Note: just knowing the structure of the error
term is not enough! (We will however use the structure of the
error term in our derivation of the numerical error estimate.)
Then we will use the error estimate to decide whether to accept the
value from CSR, or if we need to refine further (recompute
with smaller h).
where
(b a) a+b (b a)
S(f ; a, b) = f (a) + 4f 2 + f (b) , h1 = .
6 2
1 h15 (4) 1 1 h15 (4) 2
E (f ; h2 , 2 ) = f (2 ) + f (2 )
32 90 32 90
where 12 [a, a+b 2 a+b
2 ], 2 [ 2 , b].
If f C 4 [a, b], then we can use our old friend, the intermediate
value theorem:
f (4) (12 ) + f (4) (22 )
2 [12 , 22 ] [a, b] : f (4) (2 ) = .
2
So it follows that
1 h15 (4)
E (f ; h2 , 2 ) = f (2 ) .
16 90
Now we have
1 h15 (4)
S(f ; a, a+b
2 ) + S(f ;
a+b
2 , b) f (2 )
16 90
h15 (4)
= S(f ; a, b) f (1 ).
90
Now use the assumption f (4) (1 ) f (4) (2 ) (and replace 1 and
2 by ):
h51 (4) 16
f () S(f ; a, b)S(f ; a, (a+b)/2)S(f ; (a+b)/2, b) ,
90 15
h15 (4)
notice that 90 f () = E (f ; h1 , ) = 16E (f ; h2 , ). Hence
1
E (f ; h2 , ) S(f ; a, b)S(f ; a, (a+b)/2)S(f ; (a+b)/2, b) ,
15
Joe Mahaffy, [email protected] Composite-Romberg-Adaptive-Gaussian (25/43)
Composite Quadrature Introduction
Romberg Quadrature Building the Adaptive CSR Scheme
Adaptive Quadrature Example...
Gaussian Quadrature Putting it Together...
h15 (4)
Using the estimate of 90 f (), we have
Adaptive Quadrature
Rb
We want to approximate I = a f (x) dx with an error less than
(a specified tolerance).
[1] Compute the two approximations
S1 (f (x); a, b) = S(f (x); a, b), and
S2 (f (x); a, b) = S(f (x); a, a+b
2 ) + S(f (x);
a+b
2 , b).
[2] Estimate the error, if the estimate is less than , we are done.
Otherwise...
[3] Apply steps [1] and [2] recursively to the intervals
[a, a+b a+b
2 ] and [ 2 , b] with tolerance /2.
0.9 18
0.8 16
0.7 14
Refinement Level
0.6 12
f(x)
0.5 10
0.4 8
0.3 6
0.2 4
0.1 2
0 0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x x
q
3 2
Figure: Application of adaptive CSR to the function f (x) = 1 (x 2e
) . Here,
we have required that the estimated error be less than 106 . The left panel shows
the function, and the right panel shows the number of refinement levels needed to
reach the desired accuracy. At completion we have the value of the integral being
0.61692712, with an estimated error of 3.93 107 .
Gaussian Quadrature
Newton-Cotes Gaussian
Open Closed
Quadrature Degree of Degree of Degree of
Points Accuracy Accuracy Accuracy
1 1 1
2 1 1 3
3 3 3# 5
4 3 3 7
5 5 5 9
The mid-point rule.
Trapezoidal rule.
# Simpsons rule.
The mid-point rule is the only optimal scheme we have see so far.
P0 (x) = 1
P1 (x) = x
P2 (x) = x 2 1/3
P3 (x) = x 3 3x/5
P4 (x) = x 4 6x 2 /7 + 3/35
P5 (x) = x 5 10x 3 /9 + 5x/21.
It turns out that the roots of the Legendre polynomials are the
nodes in Gaussian quadrature.
Joe Mahaffy, [email protected] Composite-Romberg-Adaptive-Gaussian (36/43)
Composite Quadrature Ideas...
Romberg Quadrature 2-point Gaussian Quadrature
Adaptive Quadrature Higher-Order Gaussian Quadrature Legendre Polynomials
Gaussian Quadrature Examples: Gaussian Quadrature in Action; HW#7
Theorem
Suppose that {x1 , x2 , . . . , xn } are the roots of the nth Legendre
polynomial Pn (x) and that for each i = 1, 2, . . . , n, the coefficients
ci are defined by
Z 1 Y n
x xj
ci = dx.
1 xi x j
j =1
j 6= i
[3] Now, since deg(R(x)) < n, the first part of the proof implies
Z 1 X n
R(x) dx = ci R(xi ).
1 i=1
Putting [1], [2] and [3] together we arrive at
Z 1 Z 1
P(x) dx = Q(x)Pn (x) + R(x) dx
1 1
Z 1 Xn
= R(x) dx = ci R(xi )
1 i=1
n
X
= ci P(xi ),
i=1
which shows that the formula is exact for all polynomials P(x) of
degree less than 2n.
Joe Mahaffy, [email protected] Composite-Romberg-Adaptive-Gaussian (40/43)
Composite Quadrature Ideas...
Romberg Quadrature 2-point Gaussian Quadrature
Adaptive Quadrature Higher-Order Gaussian Quadrature Legendre Polynomials
Gaussian Quadrature Examples: Gaussian Quadrature in Action; HW#7
2x a b (b a)t + (b + a)
t= x= ,
ba 2
we can apply the Gaussian Quadrature formulas to any interval
Z b Z 1
(b a)t + (b + a) (b a)
f (x) dx = f dt.
a 1 2 2
Examples I/II
Z /4
1
(cos(x))2 dx = + = 0.642699081698724
0 4 8
Examples II/II
Z /4
1
(cos(x))2 dx = + = 0.642699081698724
0 4 8