Mathematics 134 -- Intensive Calculus for Science 2

Lab 1: Numerical Integration in Maple

February 14, 2001

Goals

Today, we will use Maple to compute some approximate values for integrals, using the LEFT, RIGHT, MID, and TRAP methods. We will look for patterns in the approximations and the errors for all methods.

The Student Package

The commands we will use today are contained in the "student" package, a collection of routines for basic calculus operations. To begin, you should enter the command:

with(student);

to load the package.

All the commands we will work with today perform various integration operations on functions defined by expressions (formulas).

Detailed Information on Maple Expression Syntax

Here is some more information about the syntax rules that Maple uses to decide if what you have typed in is a well-formed expression for a function.

For a function described by a formula, the formula is entered in something like usual mathematical notation:

  1. The symbols for addition, subtraction, multiplication, and division are +, -, *, / respectively.
  2. The caret (^) is the Maple symbol for raising to a power.
  3. The asterisk symbol for multiplication MUST be included whenever you are performing a product in a formula. Moreover, everything must be entered in one string of characters, so you will need to use parentheses to group terms to get the expressions you want. The rule to keep in mind is: Maple always evaluates expressions by doing powers first, then products and quotients, then sums and products, left to right, unless parentheses are used to override these built-in rules. For example, the Maple expression a + b^2/c + d is the same as the mathematical formula: a + b2/c + d. If you really wanted a + b2 in the numerator and c + d in the denominator of a fraction, you will need to enter the expression (a + b^2)/(c + d). What if you really wanted (a+b)2 in the numerator?
  4. Maple ``knows'' all the functions we studied in Chapter 1 of our text. The names of the most common ones are sin, cos, tan, exp, ln. To use one of these functions in a Maple formula, you put the name, followed by the "argument" (that is the expression you are applying the function to) in parentheses.

Numerical Integration Commands

The formats for the various commands we will use today are:

leftsum(function,x=a..b,n);

rightsum(function,x=a..b,n);

middlesum(function,x=a..b,n);

trapezoid(function,x=a..b,n);

In each case, you fill in the formula for the function whose integral you are approximating, you supply the a,b for the interval, and you supply the value of n, the number of subdivisions. The output of each of these commands is a formula for a summation. To evaluate the sum and get a decimal number, you can enclose the whole command inside an evalf( ). For example, to approximate the integral of sin(x^2) from a = 2 to b = 3 with the trapezoidal rule and n = 20 subdivisions, giving the value as a decimal, you would enter:

evalf(trapezoid(sin(x^2),x=2..3,20));

Maple also contains a suite of more sophisticated numerical methods for definite integrals. To have Maple compute an approximate value of the integral of sin(x^2) from a = 2 to b = 3, for example, you would use:

evalf(Int(sin(x^2),x=2..3));
Note the capital I in the "Int". This is important -- it tells Maple, in effect, to bypass the process of looking for a formula for an indefinite integral and the Fundamental Theorem and to go directly to its numerical methods.

Lab Questions

  1. For each of the following functions and intervals, construct a table giving the values of LEFT(n),RIGHT(n),TRAP(n),MID(n) for n = 4,10,50,100,200. Round Maple's output to 6 decimal places in all cases.
  2. Now, use Maple's sophisticated numerical integration routine to compute a value for each of the integrals in the problem above. Treat that answer as the exact value of the integral. (It's certainly closer than any of the approximations you computed in the first problem!) Make a second table giving the error for each approximation you found in the first problem.
  3. Based on the data you found above and our understanding of the numerical methods, answer the following questions. You may also want to plot the functions above to see various features of their graphs. Recall that you can do that in Maple using the plot command. To plot y = cos(x)/x on [a,b] = [1,2], for instance, you could use:

    plot(cos(x)/x,x=1..2);

Assignment

The lab write-up is due in class Wednesday, February 21.