Numerical Integration
Trapezoidal Rule
Simpson’s Rule
Numerical Integration
Many definite integrals of interest can’t be evaluated analytically.
Probably the best-known example is the integral that gives the area under the standard bell-shaped curve, given by
dz e
x F
x
z 0
2 2
2 1 2
) 1
(
Numerical Integration
The integral is tabulated because it is a fact that there is no way to express the antiderivative of exp(-z2) in terms of elementary functions.
Because of cases like this we need methods to perform approximate integration; for other cases it may be more convenient to use a numerical method than a symbolic one.
Often we’re given values of f(x) at various points but not a formula for f and so have no choice but to use a
numerical method (for example, data from an
Numerical Integration
The Newton-Cotes formula Trapezoidal Rule
Simpson’s Rule Romberg Integration Gaussian Quadrature
Trapezoidal Rule
The trapezoidal rule is equivalent to approximating the area of the trapezoid under the straight line connecting f(a) and f(b).
f(a)
f(b)
Trapezoidal Rule
One way to improve the accuracy of the trapezoid rule is to divide the integration interval from a to b into a
number of segments (N).
The areas of individual segment can then be added to yield the integral for the entire interval.
There are N+1 equally spaced nodes x0, x1, …., xN
Trapezoidal Rule
Let, x0=a and xN=b
Assume
are equally spaced nodes
N a h b
N k
kh x
x
k 0, 0 , 1 , 2 ,...,
Trapezoidal Rule
Therefore
with
N
N
x x x
x
x x b
a
f x dx f x dx f x dx f x dx
1 1
0
2
1
) ( ...
) ( )
( )
(
1
1
( )
k( )
k k
k
x
x n
x
x
f x dx p x dx
Trapezoidal Rule
Let
with
k k
n
x f r f
p ( )
rh x
x
k( dx hdr )
Trapezoidal Rule
1
1
( )
k( )
k k
k
x
x n
x
x
f x dx p x dx
h x
x k k
k
k
dx f
r f
1
0
f r f dr
h
k kTrapezoidal Rule
1
0 2
2
kk
r f
rf
h h f
kf
k2 1
k k
k
f f
f
h
12 1
2 f
kf
k 1h
Trapezoidal Rule
N N
b
a h f f
f h f
f h f
dx x
f 0 1 1 2 1
... 2 2
) 2 (
N
N
f
f f
f h f
1 2
1
0
2 2 ... 2
2
1
1
0
2
) 2 (
N
i
i N
b
a
h f f f
dx x
f
Example
Approximate the following integral using the Trapezoidal rule with h=0.5 and h=0.25.
x dx x
4
1
4
Example
For h=0.5,
a
=1 and b=4N b a
h
4 1
0 5 6
.
Example
2780 .
1 5
. 3 5
1339 .
1 0
. 3 4
9806 .
0 5
. 2 3
8165 .
0 0
. 2 2
6396 .
0 5
. 1 1
4472 .
0 0
. 1 0
) 4
( x
x x f x
i
i i i
i
Example
dx x
f x dx
x
41 4
1
( )
4
h f f f f f f f
2
0 62
1 2 3 4 58486 .
4 2 8614
. 2 1
5 . 0
8896 .
2
Example
For h=0.25,
a
=1 and b=4N b a
h
4 1
0 25 12
.
Example
2 0 7 0 .
1 2 5
. 3 9
1 3 3 9 .
1 0 0
. 3 8
0 5 8 5 .
1 7 5
. 2 7
9 8 0 6 .
0 5 0
. 2 6
9 0 0 0 .
0 2 5
. 2 5
8 1 6 5 .
0 0 0
. 2 4
7 2 9 8 .
0 7 5
. 1 3
6 3 9 6 .
0 5 0
. 1 2
5 4 5 5 .
0 2 5
. 1 1
4 4 7 2 .
0 0 0
. 1 0
) 4
( x
x x f x
i
i i i
i
Example
dx x
f x dx
x
41 4
1
( )
4
h f f f
i2
0 122
i 1 116364 .
10 2 8614
. 2 1
25 . 0
8918 .
2
Example
For h=0.5, N=6, the error is 0.0029 For h=0.25, N=12, the error is 0.0007
The error decreases as the number of segments (N) increases.
When h is reduced by a factor of ½ the successive errors are diminished by approximately ¼.
Exercise
Approximate the following integrals using the Trapezoidal rule with N=10.
(a) (b)
2
0
e
xdx
2x dx
1
3
1
Simpson’s Rule
The trapezoidal rule usually requires a large number of function evaluations to achieve an accurate answer.
Another way to obtain a more accurate estimate of an
integral is to use higher-order polynomials to connect the points.
Simpson’s Rule
Let
p x
2f
kr f
k1 r r
2f
k2 1
( ) ( )
Simpson’s Rule
dx f
r r f
r f
dx x
f
x hx k k k
x x
k
k k
k
2 2
) 1 2 (
) 1
2
(
dr f
r r f
r f
h
2 k k k0
)
21 2 (
1
h rf r
f r r
k k
f
k2 3 2
2
0 2
2
1
2 3 2
Simpson’s Rule
h 2 f
k2 f
k1 f
k3
2
h 2 f
k2 f
kf
k1 f
kf
kf
k3 2
1 2 1
h f
kf
kf
k3 4
1 2Simpson’s Rule
Subdivide the interval [
a
,b] into N subintervals (N is even).N
N
x x
x x x
x b
a
dx x
f
dx x
f dx
x f dx
x f
2
4
2 2
0
) ( ...
) ( )
( )
(
h f 4 f 2 f 4 f 2 f ... 4 f f
Simpson’s Rule
This equation is known as Simpson’s 1/3 rule.
Where N is even.
1 2 /
1 2 2
/
1
1 2
0
4 2
) 3 (
N
i
i N
i
i N
b
a
h f f f f
dx x
f
Simpson’s 3/8 Rule
Let,
k k
k
k
r f r r f r r r f
f x
p
3 2( 1 )( 2 )
36 ) 1
1 2 (
) 1 (
3
3
( )
k 3( )
k k
k
x x x
x
f x dx p x dx
Simpson’s 3/8 Rule
where N= 3, 6, 9, 12, ..…
This equation is called Simpson’s 3/8 rule because h is
1 3 /
1 3 3
/
1
1 3 2
3
0
3 2
8 ) 3
(
N
i
i N
i
i i
N b
a
h f f f f f
dx x
f
Example
Approximate the following integrals using the Simpson’s 1/3 rule with h=0.5 and h=0.25.
4
1
4 dx
x
x
Example
For h=0.5,
a
=1 and b=45 6 . 0
1 4
h a
N b
(N is even)Example
2780 .
1 5
. 3 5
1339 .
1 0
. 3 4
9806 .
0 5
. 2 3
8165 .
0 0
. 2 2
6396 .
0 5
. 1 1
4472 .
0 0
. 1 0
) 4
( x
x x f f
x i
i i i
i i
Example
2
1 2 3
1
1 2 6
0 4
1
4 2
4 3
ii i
i
f
f f
h f x dx
x
) 9504 .
1 ( 2 )
8982 .
2 ( 4 8614
. 3 1
5 . 0
8925 .
2
Example
For h=0.25,
a
=1 and b=4(N is even)
25 12 . 0
1 4
h
a
N b
Example
2780 .
1 50
. 3 10
2070 .
1 25
. 3 9
1339 .
1 00
. 3 8
0585 .
1 75
. 2 7
9806 .
0 50
. 2 6
9000 .
0 25
. 2 5
8165 .
0 00
. 2 4
7298 .
0 75
. 1 3
6396 .
0 50
. 1 2
5455 .
0 25
. 1 1
4472 .
0 00
. 1 0
) 4
( x
x x f f
x i
i i i
i i
Example
5
1 2 6
1
1 2 12
0 4
1
4 2
4 3
ii i
i
f
f f
h f x dx
x
) 8486 .
4 ( 2 )
7878 .
5 ( 4 8614
. 3 1
25 . 0
8925 .
2
Example
Approximate the following integrals using the Simpson’s 3/8 rule with h=0.25.
4
1
4 dx
x
x
Example
For h=0.25,
a
=1 and b=425 12 . 0
1 4
h
a
N b
Example
2780 .
1 50
. 3 10
2070 .
1 25
. 3 9
1339 .
1 00
. 3 8
0586 .
1 75
. 2 7
9806 .
0 50
. 2 6
9000 .
0 25
. 2 5
8165 .
0 00
. 2 4
7298 .
0 75
. 1 3
6396 .
0 50
. 1 2
5455 .
0 25
. 1 1
4472 .
0 00
. 1 0
) 4
( x
x x f f
x i
i i i
i i
Example
4
1
3
1 3 1
3 2
3 12
0 4
1
3 2
8 3
4
i ii i
i
f f
f f
h f x dx
x
) 9174 .
2 ( 2 )
7191 .
7 ( 3 8614
. 8 1
) 25 . 0 ( 3
8925 .
2
Simpson’s Rule
Simpson’s 1/3 rule is usually the method of preference because it attains third-order accuracy with three points rather than the four points required for the 3/8 version.
Exercise
Approximate the following integral
using
a) The Simpson’s 1/3 rule b) The Simpson’s 3/8 rule with N=12.
dx x
3
0 3