Simp
Simp
Simp
1 Simpson’s Rule
Simpson’s rule differs from the other numerical integration routines in that it requires
that we partition the interval [a, b] into an even number of subintervals.
However, the width of each subinterval remains the same, calculated with
b−a
h= .
n
Consider the case, shown in Figure 1, where x0 = −h, x1 = 0, and x2 = h.
The function f (in green) is evaluated at x0 , x1 , and x2 , producing the corre-
sponding y-values, y0 , y1 , and y2 .
y
(0, y1)
(h, y2)
(−h, y0)
Placing this result in Equation (1), the area under the parabola y = Ax2 + Bx + C
on [−h, h] is given by
h
A= (y0 + 4y1 + y0 ).
3
Note that this area result remains unchanged if we shift the region right or left. In
Figure 2, the area under the curve is partitioned into six subintervals.
Parabolic arches are drawn through P0 , P1 , and P2 , then P2 , P3 , and P4 , and
finally, through P4 , P5 , and P6 . If yk is in the y-value of point Pk , k = 0, 1, . . . , 6,
then the total area under the parabolic arches is
3
y
P5 (x5 , y5 )
P1 (x1 , y1 ) P6 (x6 , y6 )
P2 (x2 , y2 ) P4 (x4 , y4 )
P0 (x0 , y0 ) P3 (x3 , y3 )
x
Figure 2 Simpson’s rule requires an even number of subintervals.
h h h
S= (y0 + 4y1 + y2 ) + (y2 + 4y3 + y4 ) + (y4 + 4y5 + y6 ).
3 3 3
Obviously, if we increase the number of subintervals to n, where n is even, the total
area is now
h h h
S = (y0 + 4y1 + y2 ) + (y2 + 4y3 + y4 ) + · · · + (yn−2 + 4yn−1 + yn ).
3 3 3
If we factor h/3 from each term, this will greatly simplify our programming instruc-
tions.
h
S = [(y0 + 4y1 + y2 ) + (y2 + 4y3 + y4 ) + · · · + (yn−2 + 4yn−1 + yn )] (2)
3
We are now ready to write a program that will execute Simpson’s rule.
We begin by providing the calculator with some initial data. We assume that
the integrand of
Z b
f (x)dx
a
is currently loaded in the Y= Menu. For example if we wish to integrate
Z 2
1
dx,
1 x
then we load y = 1/x in Y1.
The calculator will need to know the limits of integration and the number of subin-
tervals in the partition. We also clear the home screen before prompting the user
for this data.
Clr Home
Prompt A
Prompt B
Prompt N
If int(N/2)\ne N/2
Then
Disp "N MUST BE EVEN"
Stop
End
(B-A)/N->H
Because we begin with the endpoint of the first subinterval, we store the contents
of the variable A in X.
A->X
We will store the sum in the variable S. It is important that we initialize this variable
to zero before we begin.
0->S
We now add the function values in Equation (2). This is accomplished by proceeding
one step at a time, moving from left to right. This calls for the use of a For loop.
For(K,1,N,1)
S+Y1(X)+4*Y1(X+H)+Y1(X+2*H)->S
X+2*H->X
End
This loop construct warrants some further explanation. The command For(K,1,N,1)
initializes K to 1, then executes the loop. It increments the value of K by 1, then
5
checks to see if K is less than or equal to N. If K is less than or equal to N, the loop is
executed again. If K is greater than N, execution of the loop is halted and the pro-
gram continues by executing the line following the End command, which terminates
the loop. In the body of the loop, two things happen. First, the integrand, which
was stored in Y1, is evaluated at X, X+H, and X+2*H, added to the current value of
S, then S is updated to contain this current sum. This is accomplished with the
command S+Y1(X)+4*Y1(X+H)+Y1(X+2*H)->S. Next, X is incremented by 2*H by
executing the command X+2*H->X. This is necessary because Simpson’s rule uses 2
subintervals to approximate the area under the parabolic arch.
Once the loop terminates, S contains the sum (y0 + 4y1 + y2 ) + (y2 + 4y3 + y4 ) +
· · · + (yn−2 + 4yn−1 + yn ). By Equation (3), we must still multiply the function by
h/3.
S*H/3->S
Note that this result agrees with the first row of Table 1. Use the program to verify
the results in the next two rows of Table 1.
2 Appendix
Here is a complete program listing.
Clr Home
Prompt A
Prompt B
Prompt N
If int(N/2)\ne N/2
Then
Disp "N MUST BE EVEN"
Stop
End
(B-A)/N->H
A->X
0->S
For(K,1,N/2,1)
S+Y1(X)+4*Y1(X+H)+Y1(X+2*H)->S
X+2*H->X
End
S*H/3->S
Disp "METHOD: SIMPSON"
Disp "Sum:"
Disp S