d b
f (x) dx = AREA
g(x, y)
c a
dx dy = VOLUME
f (x) dx = nlim
k 1
f (x k )
Key concepts:
1. Integration is a summing process. Thus virtually all numerical approximations
can be represented by
n
b
I = f(x)dx = w if(xi ) E t
i0
a
where: wi = weights
xi = sampling points
Et = truncation error
2. Closed & Open forms:
Closed forms include the end points a & b in xi.
Open forms do not.
To evaluate:
x f(x)dx
0
xn
x2
x1
xn
f(x)dx = pm (x)dx + pm (x)dx + + p m (x)dx
x0 1
x0 2
x0 n
x0
the mi's may be the same or different. Integrate each polynomial exactly.
Order m of polynomial pm(x) determines Newton-Cotes formulas:
m
1
2
3
4
5
Polynomial
linear
quadratic
cubic
quartic
quintic
Formula
Trapezoid
Simpson's 1/3
Simpson's 3/8
Boole's Rule
Boole's Rule
Error
O(h2)
O(h4)
O(h4)
O(h6)
O(h6)
p1 (x)dx (x i x i 1 )
x i 1
f (x i ) f (x i1 )
2
x i 1
(x)dx (x i x i 1 )
f (x i ) f (x i 1 ) 1
(x i x i 1 )3 f "()
2
12
I=
f (x)dx =
(x x
i
i 1 )
i 1
x0
f(x i ) f(x i 1 )
E ti
2
xn x0
= h for i=1,...,n
n
n 1
f(x 0 ) 2
f(x i ) f(x n )
i1
I (xn x0)
2n
1
or: I h f(x 0 )
2
n 1
i 1
1
f(x i ) f(x n )
2
f ( )
i
nf
so the error is
i=1
(x x0 )h 2
nh3
Et =
f = n
f
12
12
Note: If n is
doubled, h h/2
and Et Ea/4
nh3
(b a)3
"
"
12
12n 2
Evaluate
xn
f (x)dx p (x)dx
2
x0
x0
(x x i )(x x i1 )
(x x i1 )(x x i1 )
(x x i1 )(x x i )
f (x i1 )
f (x i )
f (x i 1 )
(x i1 x i )(x i1 x i1 )
(x i x i 1 )(x i x i 1 )
(x i 1 x i 1 )(x i 1 x i )
If points are evenly spaced, integrating yields:
p2 (x)
x i 1
x i 1
f (x)dx (x i1 x i 1 )
f (x i1 ) 4f (x i ) f (x i 1 )
f (x i 1 ) 4f (x i ) f (x i 1)
h
6
3
a.
1
1
x 2 dx
2
0 (1) 2 1 (0) 2 (1) 2
3
p2 (x)dx (x i1 x i 1 )
f x i1 4f x i f x i1
x i 1
xi+1
c. Error:
f (x) dx
i-1
xi1
p 2 (x) dx
i-1
1
(x 2 x 0 ) h 4 f (4) ( )
180
x = -h, 0, +h
h
I = f(x)dx = (f o + xf o +
-h
x2
f o+
2!
) dx
2h3
2h5 [4]
f o+
f + . . . (only odd powers of h survive)
6
5! o
h
h
2h2
2h 4 4
S =
f -h + 4f(0) + f(+ h)
6f
o
o
o
3
3
2
4!
= 2hf o +
2hf0
2h3
2h5 [4]
f0
f
6
3(4!)
Composite Simpson 1/3 Rule (C&C 4th ed., Sec. 21.2.2, p. 599)
Sum pairs of segment areas to approximate the given integral:
xn
n 1
f(x ) 4f(xi ) f(xi1 )
I = f(x)dx = (x i1 x i1 ) i 1
E ti
6
i1,3,5
x
0
h
I f (x 0 ) 4
f (x i ) 2
f (x j ) f (x n )
3
i 1,3,5
j2,4,6
f ( ) nf (4)
n
so:
i =1
(x n x 0 )h 4 (4)
(x n x 0 )5 (4)
nh 5 (4)
Et
f
f
f
180
180
180n 4
p (x)dx (x
x
3
x0 )
x3
c. Error:
x3
f(x)dx = x p (x)dx 80
x
3
Et
(x3 x0)h4f(4)()
( x x )5
1
3
( x3 x0 )h 4 f (4) ( ) h5 f (4) ( ) 3 0 f (4) ( )
80
80
6480
Notes: 1. Composite Simpson 1/3 Rule and Simpson 3/8 Rule errors are
(x n x 0 ) 4 (4)
h f
180
vs.
(x n x 0 ) 4 (4)
h f
80
Simpson 1/3 rule is slightly more accurate over the interval [x0,xn] when
the two methods use the same value of h.
But both methods have the same order of accuracy.
2. Simpson 3/8 Rule requires multiples of three segments.
Simpson 1/3 Rule requires even number of segments.
3. Can use a combination of T, S 1/3, and/or S 3/8 when number of
segments is neither even nor divisible by 3 or when data in unevenly
spaced.
Higher order does not always yield higher accuracy.
1.5
Example: I =
c e
x2
dx = 1.00000
0.2
n
1
2
3
4
6
8
9
12
15
16
32
64
Trap.
1.05191
1.00499*
1.00187*
1.00099
1.00042
1.00023
1.00019
1.00011
1.00008
1.00006
1.00001
1.00000
Simp. 1/3
Simp. 3/8
0.98935
0.99561
0.99965
0.99994*
0.99998*
0.99985
1.00000*
0.99998*
1.00000*
1.00000*
1.00000*
Asterisk (*) denotes more accurate answer for each n.
h1
A(h 2 ) A(h1 )
h
A= 2
+ O(h1m)
n
h1
1
h2
m n+1
Richardson Extrapolation Example -- Numerical Differentiation (C&C 4th ed., Sec. 23.2, p. 635):
n
h1
D(h 2 ) D(h1 )
h
D = 2
n
h1
1
h2
Start with O(h2) centered first difference approx. from Table 23.3:
f(x i h) f(x i h)
f f
1 1
2h
2h
Substituting h2 = h and h1 = 2h, Richardson Extrapolation yields the next
highest order centered first-difference formula in Table 23.3:
4
f '(xi) = (1/3) [ 4 D(h) D(2h) ] + O (h ) =
f (x i ) D(h)
1 1
1
4 (f1 f 1) (f 2 f 2 ) + O (h4) =
3 2h
4h
(-f 2 8f1 8f 1 f 2 )
+ O (h4)
12h
1,k
1
4k 1 1
4k 1 1
where:
j = level of subdivision
k = level of integration O(h2k)
1
2
3
4
5
I j1,k 1 I j,k 1
4k 1 1
# Trap.
segs.
n
1
2
4
8
16
1
4k 1 1
k=1
O(h2)
Trap
I1,1
I2,1
k=2
O(h4)
k=3
O(h6)
k=4
O(h8)
k=5
O(h10)
1/63
1/255
I3,1
1/3
1/15
Example 1:
I =
ce x dx = 1.0000000
1.2
Trap
n
1
2
4
8
16
32
64
Trap
O(h2)
1.0519096
1.0049891
1.0009873
1.0002322
1.0000572
1.0000142
1.0000036
Simpson
O(h4)
0.9893489
0.9996533
0.9999806
0.9999988
0.9999999
1.0000000
Boole
O(h6)
1.0003403
1.0000024
1.0000000
1.0000000
1.0000000
O(h8)
0.9999970
1.0000000
1.0000000
1.0000000
Example 2:
I (a+1)x a dx
a=6
Trap
n
Trapezoid
O(h2)
Simp 1/3
O(h4)
Boole 5-pt
O(h6)
O(h8)
3.500000
1.239583
1.002604
1.000000
2
4
8
16
1.804688
1.214233
1.054403
1.013654
1.017415
1.001127
1.000071
1.000041
1.000001
1.000000
O(h10)
1.000000
Example 3:
I (a+1)x a dx
a = 1.5
Trap
Trapezoid
Simp 1/3
Boole 5-pt
O(h2)
O(h4)
O(h6)
O(h8)
1
2
4
8
16
1.250000
1.066942
1.017545
1.004531
1.001159
1.005922
1.001080
1.000193
1.000034
1.000757
1.000134
1.000024
1.000124
1.000022
O(h10)
1.000022
n 1
i 0
f(x)dx f(x ) R
i
i = weighting factors
xi = sampling points selected optimally
where:
1dx = 2 = 01 + 11 + 21
1
1
x 2 dx =
2
= 0x02 + 1x12 + 2x22
3
1
1
1
x 4 dx =
2
= 0 x04 + 1 x14 + 2 x24
5
1
x dx = 0 = 0 x0 + 1 x1 +
5
2 x25
Solving these six equations for the six unknowns results in:
0 = 0.555555556
1= 0.888888889
2= 0.555555556
x0 = 0.774596669
x1 = 0.000000000
x2 = +0.774596669
Rn =
3
(2n 1) (2n)!
f(2n)()
f(x)dx .
and
b = a0 + a1(+1)
and
a1 = (ba)/2
Thus,
ba
ba
+ 2 x
2
-1
f(y)dy =
and
dy =
ba
dx
2
ba
(b a) (b-a)x b a
f
dx
2
2
n 1
i f(y[xi ])
i 0
1.5
Example 1: Evaluate
0.2
1. Change of variables:
y=
1.5
2. With
y2
dy = 0.65
e[0.65x 0.85] dx
0.2
2
2
2
I 0.65{0 e[0.65x0+0.85] + 1 e[0.65x1+0.85] + 2 e[0.65x2+0.85] }
where:
0 = 0.555555556
1 = 0.888888889
x0 = 0.774596669
2 = 0.555555556
x2 = +0.774596669
x1 = 0.000000000
Itrue
Igauss
Note: with 3 points, i.e., 2 segments: Itrap
ISimp.1/3
1
Example 2:
= 0.65882
0.65860, et = 0.03%
= 0.66211, et = 0.50%
= 0.65181, et = 1.06%
c dy
2 cos( y/2)
n
1
2
4
8
pts
2
3
5
9
Romberg
1.08253170
1.00066008
0.99999114
0.99999987
Gauss Quad
0.99955157
1.00000812
1.00000000
1.00000000
n
1
2
4
8
pts
2
3
5
9
Romberg
O(h2)
O(h4)
O(h6)
O(h8)
Gauss Quad
O(h4)
O(h6)
O(h10)
O(h18)
f x dx
e x f x dx
Gauss-Laguerre
Gauss-Hermite
log-weighted
1
f x dx
ln x f x dx
0
Gauss-Chebyshev
1
f x
1 x2
dx
f(x)dx =
x a
t 1/b
1
f ( ) dt
t
t
(22.27)
which is valid for ab > 0. For integration limits that pass through zero, implement the
integration in two (or three) steps:
b
where a >0The first integral may be evaluated using equation (22.27) and the second
may be evaluated using a Newton-Cotes formula or Gauss Quadrature.
For a detailed example (on the cumulative normal distribution), see C&C Example
22.6, page 629-630.
Multiple Integrals (C&C 4th ed., Sec. 21.5, page 608)
bd
I =
f(x,y)dydx
a c
= f(x,y) dy dx
a c
j1
(x) f(x,y ) dx
j
i1
j1
ij f(xi ,y j ) =
i ij
f(xi ,y j )
i1 j1
f (x)
dx problem at the singular point x = 0
x
In addition, if the derivative of the integrand goes to infinity, it is possible that the error goes to
infinity as well. An example of this situation is:
u
x f (x)dx
x f (x)dx
[f(x) - f(0)]
x dx
f (0)
x dx f (0)
1.5
1.5
1.5
1.5
Approach 1b: Even better, include the first derivative when isolating the singularity, i.e.,:
a) Subtract out the singularity at x = 0, and integrate numerically:
u
x dx
f (0) xf (0)
x dx f (0)
1.5
1.5
f (0)
2.5
2.5
1.5
1.5
f (0)
2.5
2.5
f (x) dx
f (x)
x dx f (y ) y(2y)dy 2 f (y 2 ) y 2 dy
x f(x)dx x
a
a 1
f(x) x a 1f '(x)dx