

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Simpson’s Rule takes advantage of the fact that most functions are smooth curves, not straight line segments. Simpson’s rule fits a parabola through the top three corners of each pair of strips and sums up the area under all of the parabolas. In Fig. 6.16 we have shown one pair of strips and the parabola that fits this pair. Our first task will be to find the correct values of a , b and c in order that the parabola y a x^2 b x c goes through the top three corners. Once we have found them then it is straightforward to find the area under the parabola. It is
2 1 3 1 2 2 3 ( ) 3 2 3 2
x x x x a x^ b x^ c dx^ a x^ b x^ c x^ x^ x a^ x^ c^ x
Now let’s turn to the task of finding the values of a , b and c. As shown in Fig. 6.16, the three points that the parabola must go through have coordinates ( x , yL ), (0, yM ) and (+ x , yR ). Substituting these into the equation y a x^2 b x c gives three equations in the three unknowns a , b and c :
2
2
2
R
M
L
y a x b x c
y a b c y a x b x c
The second equation immediately gives c = yM. Substituting this into the first and third equations gives the following pair of equations in the unknowns a and b :
2
2
R M
L M
x a x b y y
x a x b y y
Adding the equations, we get
2
a y^ L^ yR^ yM x
Substituting the values found for a and c into the formula for the area under the parabola given on the previous page, we get the formula shown on the next page for the area under the parabola.
Figure 6.16 Simpson’s rule breaks the integration region into a large number of pairs of strips. It then fits a parabola through the top three corners of each pair. This figure shows one such pair.
y a x^2 b x c
( ) R
M
L
y y = f^ x
y
y
x + x
y
x
area under parabola 2 3 2 3
( 2 ) 2 3 L^ R^ M^ M
a x c x
x y y y y x
x y y y
Notice that the coefficients of yL , yM and yR inside the brackets are 1, 4 and 1. Notice also that the area does not depend on where the pair of strips is located. We located them at the origin only to make the task of finding a , b and c easier. Now suppose that we have three strip pairs. Then the area under three parabolas is
area under 3 parabolas 3 ( 0 4 1 2 ) 3 ( 2 4 3 4 ) 3 ( 4 4 5 6 ) x x x y y y y y y y y y
or rearranging,
x y y y y y y y
Notice the pattern of the coefficients of the y ’s inside the brackets; it starts with 1 4 and ends with 4 1, and in the interior it alternates 4, 2, 4, 2, .... This pattern generalizes to any number of pairs of strips.
3 n^ n
x n y y y y y y (^) y
Notice that in this formula n must be an even number. (This is because the region between x = a and x = b must be divided in such a way that all strips occur in pairs.) As usual the first and last y ’s represent the value of the function at the endpoints x = a and at x = b.
Here is Visual Basic code that implements Simpson’s Rule. To use it see the instructions on page 118.
Public Function Simpson (A, B, N) Dim X As Double, Dx As Double, Sum As Double, I As Integer 'this function integrates a function called Func(x) between x=A and x=B 'using Simpson's rule with N strips.
N = (N \ 2) * 2 'Make sure N is even. The \ operator does integer division. Dx = (B - A) / N 'Dx is the width of a strip Sum = 0
For I = 0 To N 'the main loop X = A + I * Dx If I = 0 Or I = N Then 'I for one of the endpoints Sum = Sum + Func(X) ElseIf I Mod 2 = 1 Then 'I is odd Sum = Sum + 4 * Func(X) Else 'I is even Sum = Sum + 2 * Func(X) End If Next I
Simpson = Sum * Dx / 3 End Function