You are on page 1of 3

Module for the Trapezoidal Rule for Numerical Integration

Theorem (Trapezoidal Rule) Consider y = f (x) over [x0 , x1 ], where x1 = x0 + h. The trapezoidal
rule is

h
TR (f, h) = 2
(f (x0 ) + f (x1 )).

This is an numerical approximation to the integral of f (x) over [x0 , x1 ] and we have the expression

1x
∫x0 f (x) ⅆx ≈ TR (f, h).

Theorem (Composite Trapezoidal Rule) Consider y = f (x) over [a, b]. Suppose that the interval
b-a
[a, b] is subdivided into m subintervals {[xk-1 , xk ]}mk=1 of equal width h = m
by using the
equally spaced nodes xk = x0 + k h for k = 1, 2, ..., m. The composite trapezoidal rule for m
subintervals is

h
T (f, h) = 2
(f (a) + f (b)) + h ∑mk=1 f (xk ).

This is an numerical approximation to the integral of f (x) over [a, b] and we write

b
∫a f (x) ⅆx ≈ T (f, h).
2
Example 1. Numerically approximate the integral ∫0 2 + Cos2 x  ⅆx by using the trape-
zoidal rule with m = 1, 2, 4, 8, and 16 subintervals.
Solution 1.

f[x_] = 2 + Cos2 x ;
coseno

We will use simulated hand computations for the solution.

In[1]:= f[x_] = 2 + Cos2 x ;


coseno

In[4]:= NIntegrate[f[x], {x, 0, 2}]


integra numéricamente

Out[4]= 3.46

2-0
1
In[2]:= t1 = f[0] + f[2.]
2

Out[2]= 4.04864

2-0
2
In[3]:= t2 = f[0] + 2 f[1] + f[2.]
2
Out[3]= 3.60817

Printed by Wolfram Mathematica Student Edition


2 Integración Numérica.nb

2-0
4 1 3
In[5]:= t4 = f[0] + 2 f  + 2 f[1] + 2 f  + f[2.]
2 2 2

Out[5]= 3.4971

2-0
8 1 1 3 5 3 7
In[6]:= t8 = f[0] + 2 f  + 2 f  + 2 f  + 2 f[1] + 2 f  + 2 f  + 2 f  + f[2.]
2 4 2 4 4 2 4
Out[6]= 3.46928

2-0
16 1 1 3 1 5 3 7
In[7]:= t16 = f[0] + 2 f  + 2 f  + 2 f  + 2 f  + 2 f  + 2 f  + 2 f  + 2 f[1] +
2 8 4 8 2 8 4 8
9 5 11 3 13 7 15
2 f  + 2 f  + 2 f  + 2 f  + 2 f  + 2 f  + 2 f  + f[2.]
8 4 8 2 8 4 8

Out[7]= 3.46232

Module for Simpson's Rule for Numerical Integration


The numerical integration technique known as "Simpson's Rule" is credited to the mathemati-
cian Thomas Simpson (1710-1761) of Leicestershire, England. His also worked in the areas of
numerical interpolation and probability theory.
Theorem (Simpson's Rule) Consider y = f (x) over [x0 , x2 ], where x1 = x0 + h, and x2 = x0 + 2 h.
Simpson's rule is

h
SR (f, h) = 3
(f (x0 ) + 4 f (x1 ) + f (x2 )).

This is an numerical approximation to the integral of f (x) over [x0 , x2 ] and we have the expression
2x
∫x0 f (x) ⅆx ≈ SR (f, h).

Corollary (Simpson's Rule: Remainder term) Suppose that [a, b] is subdivided into 2 m subintervals
b-a
{[xk-1 , xk ]}2k=1
m of width h =
2m
. The composite Simpson's rule

h 2h 4h
S (f, h) = 3
(f (a) + f (b)) + 3
∑m-1
k=1 f (x2 k ) + 3
∑mk=1 f (x2 k-1 ).

is an numerical approximation to the integral, and

b
∫a f (x) ⅆx = S (f, h) + ES (f, h).

Furthermore, if f (x) ∈ C4 [a, b], then there exists a value c with a < c < b so that the error term
ES (f, h) has the form

(b - a) f4 (c)
ES (f, h) = - 180
h4 .

This is expressed using the "big O" notation ES (f, h) = O (h4 ).


2
Example 1. Numerically approximate the integral ∫0 2 + Cos2 x  ⅆx by using Simpson's
rule with m = 1, 2, 4, and 8.

Printed by Wolfram Mathematica Student Edition


Integración Numérica.nb 3

Solution 1.

f[x_] = 2 + Cos2 x ;
coseno

We will use simulated hand computations for the solution.

f[x_] = 2 + Cos2 x ;
coseno

2-0
2
In[8]:= s1 = f[0] + 4 f[1] + f[2.]
3

Out[8]= 3.46135

2-0
4 1 3
In[9]:= s2 = f[0] + 4 f  + 2 f[1] + 4 f  + f[2.]
3 2 2
Out[9]= 3.46008

2-0
8 1 1 3 5 3 7
In[10]:= s4 = f[0] + 4 f  + 2 f  + 4 f  + 2 f[1] + 4 f  + 2 f  + 4 f  + f[2.]
3 4 2 4 4 2 4

Out[10]= 3.46

2-0
16 1 1 3 1 5 3 7
s8 = f[0] + 4 f  + 2 f  + 4 f  + 2 f  + 4 f  + 2 f  + 4 f  + 2 f[1] +
3 8 4 8 2 8 4 8
9 5 11 3 13 7 15
4 f  + 2 f  + 4 f  + 2 f  + 4 f  + 2 f  + 4 f  + f[2]
8 4 8 2 8 4 8

Printed by Wolfram Mathematica Student Edition

You might also like