Mathematics 136 – Calculus 2 Lab Day 1 – “In search of a better numerical integral method” February 28, 2020

Background

We have now seen the LEF T (n), RIGHT (n), MID(n), and T RAP (n) methods for approximating definite integrals (the left-, right-, and midpoint Riemann sums were not new; the trapezoidal method is new). We have seen the following patterns (some more than once!):

• If f is increasing on [a, b], then LEF T (n) gives an underestimate of ∫_{a}^{b} f(x) dx for all n. If f is decreasing on [a, b], then LEF T (n) gives an overerestimate of ∫_{a}^{b} f(x) dx for all n.

• If f is decreasing on [a, b], then RIGHT (n) gives an undererestimate of ∫_{a}^{b} f(x) dx for all n. If f is increasing on [a, b], then LEF T (n) gives an overerestimate of ∫_{a}^{b} f(x) dx for all n.

• Whether T RAP (n) is an under- or over-estimate of ∫_{a}^{b} f(x) dx depends on the concavity of f. If f is concave up on [a, b], then T RAP (n) will give an overestimate of the integral. If f is concave down on [a, b], then T RAP (n) will give an underestimate of the integral.

• Whether MID(n) is an under- or over-estimate of ∫_{a}^{b} f(x) dx also depends on the concavity of f, and we want to understand this as well.

In this lab, we will gather some data on these methods by looking at several examples, and introduce an even better method obtained by combining two of these methods in an appropriate way.

Maple Commands and Examples

The commands for finding the left, right, and midpoint sums are contained in the student package. Start by entering

                          with(student);

to load this.

The commands we will use in the lab are:

• leftbox, middlebox, rightbox which draw graphical representations of the left-, midpoint, and right-hand Riemann sums for a given function, and

• leftsum, middlesum, rightsum which compute the left-, midpoint, and right-hand Riemann sums of a given function (as formulas). For instance, try entering the following commands to see the pictures for the left- and right-hand sums for f(x) = t^{2}−3t+4 on [a, b] = [0, 2] with n = 5 subdivisions:

                 leftbox(t^2 - 3*t + 4, t=0..2,5);

                    rightbox(t^2 - 3*t + 4, t=0..2,5);

To see the numerical values of the left-hand, midpoint, and right-hand sums (that is LEF T (5), MID(5), and RIGHT (5)) you can enter commands like this:

                 evalf(leftsum(t^2 - 3*t + 4, t=0..2, 5));
                evalf(middlesum(t^2 - 3*t + 4, t=0..2, 5));
                evalf(rightsum(t^2 - 3*t + 4, t=0..2, 5));

There is a similar command for the trapezoidal rule. This does T RAP (5) for the same function as above:

                evalf(trapezoid(t^2 - 3*t + 4, t=0..2, 5));

If you leave off the evalf( ) around the leftsum or rightsum, can you see what the output means?

As you can probably guess now, the format for all of these commands is: the command name, open parenthesis, the formula for the function f, comma, t =, then the endpoints, separated by two periods, another comma, then the number n, followed by the close parenthesis, then the semicolon.

We will also need to be able to get exact values (or at least very close approximations) to our integrals. This is done in Maple by commands like this:

                        int(t^2 - 3*t + 4, t=0..2);
                    evalf(Int(t^2 - 3*t + 4, t=0..2));

Try these and look closely at the output. The first applies the FTC and gives the exact value. The second applies Maple’s “super-accurate” numerical methods to give a decimal approximation that is correct to 8 or 9 decimal places at least. (Note the capital I on the Int here – it’s important, but it’s slightly complicated to explain exactly what it means – “don’t ask” unless you really want to get a peek “under the hood” at what Maple actually does with your input commands(!).) There will be some cases where Maple will not be able to find an antiderivative of the f you give it; in that case the output will be the same integral back again. For instance try

                          int(exp(x^3), x=0..1);

This means that Maple was unable to find an elementary antiderivative for the function f(x) = e^{x^{3}}, so it could not carry out the FTC to find the definite integral. (In fact this is an example where no elementary antiderivative exists.)

Lab Problems

A) For each of the following integrals,

1) Compute an accurate numerical approximation using the evalf(Int(function, limits)); command as described above. We will treat this as our exact value – it’s the most accurate estimate we know!

2) Compute LEF T (n), RIGHT (n), MID(n), and T RAP (n) approximations for n = 10, 20, 40, 80, 160, and compute the errors this way:

approximate value − exact value

without taking the absolute value, including the sign. (A negative sign means that the approximate value is smaller than the exact value, and a positive sign means that the approximate value is larger than the exact value.) Arrange your data into two tables (one table for each of the integrals). In each table, give the approximation and the error for the different different n values for each of the four different methods (LEFT, RIGHT, MID, TRAP). Make the tables “by hand” in a Google Doc or Google Spreadsheet.

Integrals:

1) ∫_{0}^{2} e^{−x^{2}/10} dx (enter the function as exp(-x^2/10))

2) ∫_{2}^{5} \frac{sin x}{x} dx

B) Now we want to look for some patterns in our data.

1) For each integral and each method separately, do you notice any consistent pattern when you compare the size of the error with a given n and with n twice as large (e.g. the error for MID(10) vs. the error for MID(20), or the error for T RAP (40) vs. the error for T RAP (80))? Is the pattern the same for all of the methods, or does it vary?

2) Do you notice any consistent pattern when you compare the sizes of the errors for the four different methods on the same integral, with the same n? In particular, what is the approximate relation between the size of the errors for the TRAP and MID methods (for the same integral and the same n), and how are the signs of the two errors related?

3) How is the sign of the error for MID(n) related to the concavity of y = f(x) on the interval [a, b]? You will probably want to plot the functions to see the concavity!

C) One commonly-used better integration method is called Simpson’s Rule (no, it’s not named for Homer Simpson!) One way to write the formula for Simpson’s rule is:

SIMP (n) = \frac{2 · MID(n) + T RAP (n)}{3}

There is another command called simpson in the student package in Maple that uses this method to compute approximate values of integrals.

1) Try it on the examples from question A, and compare the sizes of the errors for Simpson’s Rule and the other methods for each n = 5, 10, 20, 40, 80, 160.

2) Why is Simpson’s Rule apparently more accurate? (Hint: Think about your answer to part 2 of question B).

Assignment

Individual lab write-ups. Share your Google doc or spreadsheet with jlittle@holycross.edu no later than 5pm on Friday, March 13.