Numerical Integration

Pre-requisites:

  1. Ability to sketch a picture of a graph of a function showing the typical rectangles or trapezoids used in the Left, Right, and Trapezoid Rules.
  2. Ability to sketch a picture of a graph of a function showing how the Trapezoid Rule and Midpoint rule give over estimates or under estimates when applied to functions whose graphs are concave up or concave down.

Many functions that need to be integrated do not have antiderivatives that can be written in terms of well known functions (for example, sin(x)/x has no elementary antiderivative). In addition, data collected experimentally may represent a function whose symbolic formula is not known. Such integrations are performed numerically. The "standard" numerical techniques for estimating integrals are: Left, Right, and Midpoint Riemann Sums, the Trapezoid Rule, and Simpson's Rule.

Goals:

  1. To see how Maple can be used to implement these numerical methods.
  2. To compare the efficiency of the methods.
  3. To be amazed at how much better some of the methods are than others and discover which are the "best".

Directions:

  1. Read the explanation of what each block of Maple code below does.
  2. Copy and paste the Maple code, one block at a time, as you read it, into Maple and execute it. You should understand what each line of Maple code accomplishes.
  3. Answer the questions using paper and pencil on a separate sheet of paper. Be sure to explain your answers.

We begin by setting the interval [a,b], the function f(x), and choosing the number n of equal subintervals.

a:=0; b:=1; n:=10;
f:=x->2*x-x^2;

Next we compute the width of each rectangle in the Riemann sum.

DeltaX:=(b-a)/n;

When we calculate the height of the rectangles, we have the choice of using the left hand endpoint, midpoint, or right hand endpoint of each of the i subintervals, where i goes from 1 to n. On the ith subinterval, the right hand endpoint corresponds to a+i*DeltaX (why?), the midpoint corresponds to (the right hand endpoint) - (DeltaX/2).

  1. What expression corresponds to the left hand endpoint of the ith subinterval? Explain your answer. Also, substitute your answer for the blank in the Maple code below before executing the block.
r:=i->a+i*DeltaX;
m:=i->r(i)-DeltaX/2;
l:=i->___;

The Riemann Sums are then just the following:

Right:= Sum( f( r(i) )*DeltaX,i=1..n);
Mid:=Sum( f( m(i) )*DeltaX,i=1..n);
Left:= Sum( f( l(i) )*DeltaX,i=1..n);

We are interested in getting a decimal approximation instead of an exact sum, so insert the Maple line RightValue:=evalf(Right); and similar lines for Left and Mid.

Instead of thin rectangles, it is possible to estimate area using thin trapezoids. Then the height of the trapezoid on the left is f(l(i)), that is, f at the left hand endpoint of the subinterval, and the height of the trapezoid on the right is f(r(i)), that is, f at the right hand endpoint of the subinterval. The area of the trapezoid is then [f(l(i))+f(r(i))]/2 * DeltaX, so:

Trap:= Sum( ( f( l(i) ) + f( r(i) ) ) / 2 *DeltaX,i=1..n);
TrapValue:=evalf(Trap);
Now consider the integral itself. Notice that we can evaluate it exactly, so we can compare our Right, Mid, Left, and Trap answers to the actual integral.
  1. Integrate f(x) over the interval from a to b by hand. Express the value you get both as a fraction and as a decimal.

Two numbers agree to n decimal places if they are equal when each is rounded to n places. For example, if you have followed the above directions, then the Left Riemann Sum is not even accurate to one decimal place, the Right Riemann Sum agrees with the true value to one decimal place.

  1. To how many decimal places do the true value and the Midpoint Riemann Sum agree?
  2. To how many decimal places do the true value and the Trapezoid Rule agree?
  3. Find the Left and Right Riemann sums for n=59, 60, 199, 200. Based on what you find, what is the smallest number of subdivisions necessary to make the Right Riemann Sum agree with the Exact Value to 2 decimal places; the Left Riemann Sum agree with the Exact Value to 2 decimal places? Explain how you know.
  4. Use values of n less than 10 and find the smallest value for which the Trapezoid Rule gives a value that agrees with the True Value to two decimal places.
  5. Use values of n less than 10 and find the smallest value for which the Midpoint Riemann Sum gives a value that agrees with the True Value to two decimal places.
  6. Based on the previous questions:
    1. Rank the four estimation techniques from most accurate to least accurate.
    2. Is Left consistently too high or is it too low? Explain why refering to a graph.
    3. Is Right consistently too high or is it too low? Explain why referring to a graph.
    4. Is Mid consistently too high or is it too low? Explain why referring to a graph.
    5. Is Trap consistently too high or is it too low? Explain why referring to a graph.
  7. Go back to the line defining f, and redefine it to be 1/(1+x).
    1. Repeat question 2 for this new function.
    2. Experiment with different values of n and explain which answers to the preceeding question (8a-8d) will or will not change and why.
  8. (Optional) Simpson's Rule can be defined as the weighted average, Simpson=(2Mid+Trap)/3, of the Midpoint and Trapezoid Rules. Use Maple to compute the approximation given by Simpson's Rule for some of the same functions and values of n you found above. Does Simpson seem more accurate or is it less accurate? Try Simpson's rule on a variety of quadratic functions, even with low values of n. What do you notice?
Last Update: 2007/06/05