Copyright 2001
Department of Mathematics
University of Georgia
Athens, Georgia
Numerical Integration
Maple has a tool to generate a variety of numerical approximations of a definite integral including, but not limited to, the standard types of Riemann sums. This tool is the ApproximateInt tool which is in the Student[Calculus1] package.
| > | with(Student[Calculus1]): |
| > | ApproximateInt(sin(x),x=0..Pi/2,method=left,partition=20,output=plot); |
| > |
There are many options that can be included in this command. The three most important ones are method, partition and output. Method specifies the method used to calculate the approximation. For Riemann sums the methods include, left, right, midpoint, upper, lower or random . The partition option specifies the number of subintervals used. The default is 10. The output option can be plot, value, sum or animation.
In the above plot of the left Riemann sum, the area under the graph of f ( x ) is approximated by the area under the rectangles. The error is the area between the graph and the rectangles. If the rectangles are replaced by trapezoids over each subinterval, the approximation is much better
| > | ApproximateInt(sin(x),x=0..Pi/2,method=trapezoid,partition=20,output=plot); |
In the above plot the tops of the trapezoids and the graph of the function are almost indistinguishable to the naked eye. When trapezoids are used in place of rectangles, the method is called the Trapezoidal Rule. To see how Maple calculates the Trapezoidal approximation we can change the output to sum:
| > | ApproximateInt(sin(x),x=0..Pi/2,method=trapezoid,partition=20,output=sum); |
Another method of approximating the integral is
Simpson's Rule
. With Simpson's Rule a quadratic function is constructed over each subinterval in the partition. A quadratic function is determined by three points on its graph. For Simpson's Rule the points on the graph of the function
f
(
x
) at the endpoints and midpoint of each subinterval are used to construct the quadratic function. The quadratic function is then integrated over the subinterval and the values of these integrals are then summed to get an approximation of the
.
| > | ApproximateInt(sin(x),x=0..Pi/2,method=simpson,partition=20,output=plot); |
To see how Maple calculates the approximation for Simpson's Rule, we change the output to sum:
| > | ApproximateInt(sin(x),x=0..Pi/2,method=simpson,partition=20,output=sum); |
Note that for the same number of subintervals, the Trapezoidal Rule gave a better approximation than the left Riemann sum and Simpson's Rule gave a much better approximation than the Trapezoidal Rule
Project - Part 1
Let
k
denote the number of letters in your last name and let
f
(
x
) =
.
| > | restart:Digits:=25; |
| > | with(Student[Calculus1]): |
1. Calculate the numerical approximations of
using the right Riemann sum, the midpoint Riemann sum, the Trapezoidal Rule and Simpson's Rule with 5,10,15 and 20 subintervals. Organize your output so that comparisons can be made between the various methods and the number of subintervals. Possible suggestions for organizing your output include spreadsheets, using a do-loop or using the seq command.
2. Define each of the approximation methods above as a function of n . For example, you might define
| > | RightApprox:=n->evalf(ApproximateInt(f(x),x=0..2,method = right, partition=n,output=value)); |
Have Maple calculate the exact value of the integral and then define error functions for each of your approximation methods as functions of n. For example, if A is the exact value of the integral, you might define
| > | RightError:=n->abs(RightApprox(n)-A); |
Now calculate the errors for each of your methods and the number of subintervals. Organize your output so that it is easy to read.
3. For each of your methods determine the number of subintervals required for the corresponding error to be less than or equal to 0.001.
Project - Part 2
1. Define the function g(x) =
on the interval [0,4]. Make an animation of the Trapezoidal Rule for approximating
starting with 4 subintervals. Notice that the approximations are always strictly greater than the value of the integral.
2. Can you think of a property that a function might have that would guarantee that the Trapezoidal Rule always gives over-estimates of the integral?
3. Determine the number of subintervals required for the error between the Trapezoidal approximation and the true value of the integral to be less than 0.001.
4. Use the ApproximateInt command to generate the sum for the Trapezoidal Rule with 10 subintervals. Carefully explain how the sum computes the areas of the associated trapezoids.
Project - Part 3
Again let
k
denote the number of letters in your last name. This time define
g
(
x
) as
on the interval [0,
].
1. Set the digits equal to 25. Then generate the Trapezoidal Approximations for
with 4,6,8 and 10 subintervals. How do the approximations compare with the exact value of the integral?
2. Create an animation of the Trapezoidal approximation beginning with 4 subintervals.
3. Generate the corresponding errors for the approximations in part 1.
4. Generate the approximations for
with 4,6,8 and 10 subintervals using Simpson's Rule.
5. Generate the corresponding errors for the approximations in part 4 and compare these errors with those in part 3.
| > |
Project - Part 4
The arclength of the graph of a function f(x) over an interval [a,b] is given by
. Arclength integrals are often difficult or impossible to evaluate in terms of elementary functions. Numerical techniques are often useful to approximate the length of a curve.
1. Use the Trapezoidal Rule with 10 subintervals to approximate the arclength of the graph of the function f(x) = sin(x) on the interval [0,
].
2. Use Simpson's Rule with 10 subintervals to approximate the arclength of the graph of the function f(x) =
on the interval [0,1].
3. Use Simpson's Rule with 10 subintervals to approximate the arclength of the graph of the function f(x) =
on the interval [1,3].
4. Use Maple to compute the exact value of the arclength of the parabola y =
on the interval [0,2]. Then approximate the same arclength with both Simpson's Rule and the Trapezoidal Rule with 10 intervals. Discuss the errors.
Project - Part 5 (Advanced)
In this part of the project we will derive the formula for Simpson's Rule. Suppose we have a function on an interval [a,a+h] with f(a) = p,
and
. Let q(x) =
be an arbitrary quadratic function. Set up the equations that force q(x) to have the same values as f(x) at the points a, a +
and a+
h
. If these equations are labeled as eq1, eq2 and eq3, use the
solve
command of Maple to solve the system of equations for
b, c
and
d.
Plug these coefficients into q(x) and then integrate q(x) over the interval [a,a+h]. Show that your result is
with the aid of the
simplify
command. Now generate the formula for Simpson's approximation for
with the following command:
| > | restart:with(Student[Calculus1]): ApproximateInt(f(x),x=a..b,method=simpson,partition=n,output=sum); |
Explain how your result leads to the sum produced.
Project - Part 6 (Advanced)
1. If f(x) is a linear or quadratic function, then Simpson's approximation for
is exact. Explain why this is the case.
2. A surprising result is that Simpson's approximation is also exact for cubic polynomials. To see this it is enough to prove that if a quadratic function q(x) agrees with
at the points
a
,
and
b,
then
=
where
a
and
b
are arbitrary real numbers.
To accomplish this use the ApproximateInt command to get the Simpson approximattion for
on [a,b] with partition = 1 and output = value. Use the
expand
command to multiply the result out and then show that this equals
.
3. Define the cubic polynomial
where
k
is the number of letters in your last name. Calculate the Simpson approximation for
with 4,6 and 10 subintervals. Verify that these numbers agree with
.
Project - Part 7 (Advanced)
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
using Simpson's Rule with
n
subintervals satisfies the following estimate:
where
M
is the maximum of the absolute value of the fourth derivative of
over the interval [a,b]. In other words
where the maximum is taken over all values of x in [a,b].
1. Let f(x) =
on the interval [0,2] where
k
is the number of letters in your last name. Plot the fourth derivative of f(x) on the interval [0,2] and determine M. Remember that M is the maximum of the
absolute value
of the fourth derivative of f(x).
2. Use the value of M to estimate the SimpsonError in terms of
n
. Suppose you want the SimpsonError to be less than or equal to 0.001. This will be satisfied if
= 0.001. Using your value of M, determine how large
n
must be to guarantee this inequality.
3. Let
n
be the integer you determined in 2. Use the ApproximateInt command to calculate the Simpson approximation with
n
subintervals for
.Then determine the corresponding error. Compare the actual error with 0.001.
The Most Common Maple Commands
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:
| > |