Numerical Integration
Numerical Integration
Formulas
Mathematically, definite integration is represented by
b
I = f (x) dx
a
which stands for the integral of the function f (x) with respect to the
independent variable x, evaluated between the limits x = a to x = b.
𝑏 −𝑥 2 𝑏
𝑒 𝑎dx, 𝑎 1 + 𝑥 3 dx
NEWTON-COTES FORMULAS
The Newton-Cotes formulas are the most common numerical integration schemes. They are based on the
strategy of replacing a complicated function or tabulated data with a polynomial that is easy to integrate:
b b
I = f (x) dx fn (x) dx (1)
a a
fn(x) = a0 +ax
1 + a2x2
+... + an xn
In general, we assume that a function f(x) is given on interval [a,b] with values
𝑦𝑘 = 𝑓 𝑥𝑘 , 𝑘 = 0,1, … , 𝑛 , 𝑎 = 𝑥0 , b= 𝑥𝑛
Let 𝑃𝑛 (x) denote to the interpolation polynomial for f(x) on the given set of
points.
𝑏 𝑏 𝑏
Then F(x)= 𝑃𝑛 (x) + 𝑅𝑛 (x) → 𝑓 𝑎 𝑥 𝑑𝑥 = ( 𝑛𝑃 𝑎x)𝑑𝑥 + ( 𝑛𝑅 𝑎x)𝑑𝑥
𝑏 𝑏
→ 𝑓 𝑎 𝑥 𝑑𝑥 ≅ ( 𝑛𝑃 𝑎x)𝑑𝑥
𝑏 𝑏 𝑓(𝑧)𝑛+1
With error E= ( 𝑛𝑅 𝑎x)𝑑𝑥 = 𝑛 𝑎+1 𝐺𝑛 (x) dx
Closed and open forms of the Newton-Cotes formulas are available. The closed forms are those where the data
points at the beginning and end of the limits of integration are known(Fig. 19.6a). The open forms have integration
limits that extend beyond the range of the data (Fig. 19.6b). This chapter emphasizes the closed forms
THE TRAPEZOIDAL RULE
The trapezoidal rule is the first of the Newton-Cotes closed integration formulas. It corresponds to the case where
the following polynomial is first order
b−a 2
which is called the trapezoidal rule.
The result of the integration is
I= (b − a) [ f (a) + f (b)]
2
I = (b − a) × average height
1
E =− f ''()(b−a)3
12
where ξ lies somewhere in the interval from a to b.
2
Example 1: Use the Trapezoid rule to numerically integration e −x2
dx
0
Then
I= (2− 0) (1+0.0183) =1.0183
2
The Composite Trapezoidal Rule
One way to improve the accuracy of the trapezoidal rule is to divide the
integration interval from a to b into a number of segments and apply the
method to each segment. The areas of individual segments can then be added
to yield the integral for the entire interval. The resulting equations are called
composite, or multiple-segment, integration formulas.
Figure 19.9 shows the general format and nomenclature we will use to
characterize composite integrals. There are n + 1 equally spaced base points
(𝑥0 , 𝑥1 , 𝑥2 , . . . , 𝑥𝑛 ). Consequently, there are n segments of equal width:
h= b − a
n
If a and b are designated as 𝑥0 and 𝑥𝑛 , respectively, the total integral can be represented as
b x1 x2 xn
I = f (x)dx = f (x)dx + f (x)dx +....+ f (x)dx
a x0 x1 xn−1
That is
h h h
I = [ f (x0) + f (x1)]+ [ f (x1) + f (x2)]+...+ [ f (xn−1) + f (xn)]
2 2 2
n−1
I = [ f (x0) +2f (xi ) + f (xn)]
h
Or
2 i=1
An error for the composite trapezoidal rule can be obtained by summing the individual errors for each segment to give
−
(i )
3 n
E =− (b a ) f ''
12n3 i=1
2
Example 2: Using the Composite Trapezoid rule to estimate the following integral
with n=8,
e
0
−x2
dx
Since
h= b − a = 2− 0 = 0.25
n 8
−𝑥 2
Use calculator mod & 7& f(x)=𝑒 &=& start=0&=end=2&=&step=.25&=
x 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2
2
𝑒 −𝑥 1 0.9394 0.7788 0.5698 0.3679 0.2096 0.1054 0.0468 0.0183
n−1
Since I = [ f (x0) +2f (xi ) + f (xn)]
h
2 i=1
then
I = 0.25[1+2(0.9394+0.7788+0.5698+0.3679+0.2096+0.1054+0.0468) +0.0183]
2
=0.8817
Simpson’s rule:
Simpson’s rule corresponds to the case where the Lagrange polynomial in second order is:
where a and b are designated as 𝑥0 and 𝑥2 , respectively. The result of the integration is
x2
I = f (x)dx = [ f (x0) +4 f (x1) + f (x2)],
h (2)
x0 3
h = b−a
where 2
Example 3: Use the Simpson’s rule to numerically integration
Since 2
I = e dx = [ f (0) +4 f (1) + f (2)], h =
1
−x2 2− 0 , x1 = x0 +h =1
0 3 2
then I = 1[1+4(0.3679) +0.0183] = 0.83
3
It can be shown that a single-segment application of Simpson’s rule has a
truncation error of
E =− 1 h5 f (4) ()
90
where ξ lies somewhere in the interval from a to b.
The Composite Simpson’s Rule
Just as with the trapezoidal rule, Simpson’s rule can be improved by dividing the integration interval into a
number of segments of equal width. The total integral can be represented as
xn x2 x4 xn
I = f (x)dx = f (x)dx + f (x)dx +....+ f (x)dx
x0 x0 x2 xn−2
where h = b − a
n
Example 4: Using composite Simpson's rule to compute the integral in example 2
since h= b − a = 2− 0 = 0.25
n 8
And
2
0 −x2
e dx = I = h[ f (x ) +4( f (x ) + f (x ) + f (x ) + f (x )) +2( f (x ) + f (x ) + f (x )) + f (x )]
3 0 1 3 5 7 2 4 6 8
2
Then 0 e dx = 3 [1+4(0.9394+0.5698+0.2096+0.0468) +2(0.7788+0.3679+0.1054)+0.0183]
−x2 0.25
=0.8821
Exercises: Using the Trapezoidal and Simpson’s rules to find an approximation for
the given integral for the indicated values of n
6 2
1] dx ; n =10 2] dx ; n =6
1 x 0 3x +1
2
3] dx ; n =6 4] sin xdx ; n =6
x +1 0 x +
3
1
2 1
5] cos x2 dx ; n = 6 6] sin x dx ; n =8
0 0 x
3 x
7] dx 8] e sin xdx
2
; n =4 ; n =6
2+sin x 1+ x2
4 0
1
9] cos xdx ; n =4
0 x +1