Simpson's Rule

Copyright 2001

Department of Mathematics

University of Georgia

Athens, Georgia

Carol W. Penney

Robert Rumely

John Gosselin

The Basic Formula

Recall that the trapezoidal approximation of int(f(x),x = a .. b)  involved the weighted sum

h/2 ( y[0]+y[n] +2*( y[1]+y[2] +...+ y[n-1] ))

where the interval [a,b] was divided into n  subintervals of length h  =   (b-a)/n  and x[0] , x[1] ,... x[n]  are the endpoints of the subintervals. In the trapezoidal rule the function f(x)  was approximated by a linear function having the same values at the endpoints of each subinterval. In Simpson's rule we approximate the function f(x)  on subintervals by quadratic functions or parabolas. Since it takes three points to determine a unique parabola, we work with pairs of subintervals, and therefore, it is necessary to assume that the number of subintervals, n, is even . Consider the first two subintervals having endpoints x[0] , x[1]  and x[2] . Let y[0] , y[1]  and y[2]  denote the values of the function f  at the points x[0] , x[1]  and x[2]  respectively. Let p(x)  denote the unique quadratic function whose graph passes through the points ( x[0] , y[0] ), ( x[1], y[1] ) and ( x[2], y[2] ). The idea behind Simpson's Rule is to approximate int(f(x),x = x[0] .. x[2])  by int(p(x),x = x[0] .. x[2]) . It turns out that the last integral can be calculated in terms of h , y[0] , y[1]  and y[2] . The result is

int(p(x),x = x[0] .. x[2])  = h/3 ( y[0] + 4*y[1] + y[2] )

So int(f(x),x = x[0] .. x[2])  is approximated by h/3 ( y[0] + 4*y[1] + y[2] ). The next pair of intervals involves the endpoints x[2] , x[3]  and x[4] . By the result above int(f(x),x = x[2] .. x[4])  is approximated by h/3 ( y[2] + 4*y[3] + y[4] ). Adding these results we approximate int(f(x),x = x[0] .. x[4])  by

h/3 ( y[0]+4*y[1]+2*y[2]+4*y[3]+y[4] )

Adding up the approximations for all pairs of subintervals leads to the following approximation for int(f(x),x = a .. b) :

h/3 ( y[0]+4*y[1]+2*y[2]+4*y[3]+2*y[4]+4*y[5] +...+ 2*y[n-2]+4*y[n-1]+y[n] )

Again we obtain a weighted sum involving the values of the function f  at the points in the partition of the interval [a,b]. This approximation is known as Simpson's approximation with n  subintervals. Remember that n  is assumed to be even .

Example with 10 Subintervals

We will study the integral of the function f(x) = x^2*exp(-x)  on the interval [0,5] with 10 subintervals.

>    restart:f:=x->x^2*exp(-x);

>    a:=0;

>    b:=5;

>    n:=10;

>    h:=(b-a)/n;

>    x:=i->a+i*h;

We now calculate the Simpson approximation for int(f(x),x = 0 .. 5)  with 10 subintervals.

>    SimpApprox:=h/3*(f(x(0))+4*f(x(1))+2*f(x(2))+4*f(x(3))+2*f(x(4))+4*f(x(5))+2*f(x(6))+4*f(x(7))+2*f(x(8))+4*f(x(9))+f(x(10)));

>    evalf(SimpApprox);

Since the integral can be calculated directly with antiderivatives, we compute the actual value of the integral and compute the error.

>    TrueValue:=evalf(int(f(x),x=0..5));

>    SimpError:=evalf(abs(SimpApprox-TrueValue));

We also compute the percentage error.

>    PercentError:=SimpError/TrueValue;

Discuss the result. In an earlier project the same integral was approximated using the trapezoidal rule. Compare the results.

The General Formula

We need a general formula for the Simpson Approximation with n  subintervals. The trick is to group the terms having the same coefficients. If x(i) is defined as a+i*h , the first and last terms have coefficient 1, the odd terms have coefficient 4 and the even terms not including the first and last terms have coeffieient 2. We let y[i] = f(x(i)) . It follows that the Simpson approximation with n  subintervals can be written as

h/3 ( y[0]+y[n] + 2*sum(y[2*i],i = 1 .. n/2-1) + 4*sum(y[2*i-1],i = 1 .. n/2) )

In order to implement this formula in Maple, we note that x(i) must be defined in terms of both i  and n . Also h  is now a function of n.

>    restart:f:=x->x^2*exp(-x);

>    a:=0;

>    b:=5;

>    h:=n->(b-a)/n;

>    x:=(i,n)->a+i*h(n);

>    y:=(i,n)->f(x(i,n));

>    SimpApprox:=n->evalf((h(n)/3)*(y(0,n)+y(n,n)+2*sum(y(2*i,n),i=1..n/2-1)+4*sum(y(2*i-1,n),i=1..n/2)));

>    SimpApprox(10);

>    TrapApprox:=n->evalf((h(n)/2)*(y(0,n)+y(n,n)+2*sum(y(i,n),i=1..n-1)));

>    TrapApprox(10);

Determine the Simpson approximation for the same function on the same interval with 16 subintervals. Also calculate the error and percent error with 16 subintervals.

Project

The Movie

The following animation illustrates Simpson's Rule graphically. Run the animation and write a paragraph explaining what the slides in the animation are illustrating. Explain what the green curves and what the pink regions represent .

[Maple Plot]

Simpson's Rule vs Trapezoidal Rule

Let f(x) = 1.0/(1+m*x^3)  on the interval [1,2] where   m  is the number of letters in your last name. This should be the same function you used in your project on Riemann sums and the Trapezoidal Rule. The functions corresponding to each column in the following spreadsheet are given in the Tools. The number n  in all the approximation rules corresponds to the number subintervals being used. Note that the number of data points is one more than the number of subintervals. For Simpson's Rule we require that n  be an even integer. Once a formula has been established in Maple, you can enter it into the spreadsheet below. For example in the cell B2 you should enter Trapapprox(~A2) to get the trapezoidal approximation with 6 subintervals. You can then fill down the B column. Then move on to fill in the remaining columns.

n TrapApprox SimpsonApprox TrapError SimpsonError
6



8



10



12



14



16



18



20



NULL



Estimate the number of subintervals required by each method so that the error is less than .001. Compare and discuss your results with similar results from the projects on the trapezoidal rule and Riemann sums.

Error Estimate for Simpson's Rule

It can be shown using methods of advanced calculus that for a function on [a,b] with at least four continuous derivatives, the error in approximating int(f(x),x = a .. b)  using Simpson's Rule with n  subintervals satisfies the following estimate:

abs(SimpsonError(n)) <= M*(b-a)^5/(180*n^4)

where M  is the maximum of the absolute value of the fourth derivative of f(x)  over the interval [a,b].  In other words

M = max(abs(diff(f(x),`$`(x,4))))

where the maximum is taken over all values of x  in [a,b]. Plot the fourth derivative of your function on [0,10] and determine M . Remember that it is the maximum of the  absolute value  of the fourth derivative of f(x) that you want to calculate.

Evaluate the right-hand-side of the above inequality as a constant C  over n^4 . Now set up the inequality C/(n^4) <= .1e-2  = .001 and solve for n . This gives an estimate on how large n  needs to be in order that Simpson's Approximation with n  subintervals has a prescribed accuracy. Compare this result with the result obtained in the previous section.

The Most Common Maple Commands

Tools for this Project

>    f:=;

>    a:=;

>    b:=;

>    h:=n->(b-a)/n;

>    x:=(i,n)->a+i*h(n);

>    y:=(i,n)->f(x(i,n));

>    SimpApprox:=n->evalf((h(n)/3)*(y(0,n)+y(n,n)+2*sum(y(2*i,n),i=1..n/2-1)+4*sum(y(2*i-1,n),i=1..n/2)));

>    TrapApprox:=n->evalf((h(n)/2)*(y(0,n)+y(n,n)+2*sum(y(i,n),i=1..n-1)));

>    TrueValue:=int(f(x),x=a..b);

>    SimpError:=n->=abs(SimpApprox(n)-TrueValue);

>    TrapError:=n->abs(TrapApprox(n)-TrueValue);

>    SimpPercentError:=n->SimpError(n)/TrueValue;

>    TrapPercentError:=n->TrapError(n)/TrueValue;

Academic Honesty Statement:

Place the following statement (by copying and pasting) at the end of your report and sign it in ink.  Your instructor will not grade your report unless this signed statement appears at the end of your report.

I understand that I may work with others if I give them credit in this statement.  I also understand that I am required to write my report--that to copy all or part of someone else's report or to allow someone else to copy all or part of my report constitutes plagiarism, which is a serious violation of academic honesty.

I worked with (replace this parenthetical remark with first and last names of those with whom you worked)   on this project.  I wrote my own report.  I did not copy any of this report from anyone else and I did not allow anyone else to copy any of this report.

Signed: