Skip to main content

Exploring Calculus with Maple Introductory Calculus

Section 14.1 Approximating the Area Under a Function Using ApproximateInt

To use the ApproximateInt() command, we must load the Student[Calculus1] package. Packages are loaded using the with() command and it is typically a good idea to load any necessary packages at the top of your worksheet. Loading a package only needs to be done once per Maple worksheet, but needs to be run each time you open a new or previously closed document.
The function and interval must be specified. Other optional parameters may be included to change how the result is displayed and how the approximation is computed.
Table 14.1. A list of optional parameters for the ApproximateInt() command
Parameter Description
method = method
Select the method for approximation (left, right, lower, upper, midpoint, trapezoid, simpson).
output = output
Change how the output is displayed (plot, value, sum).
partition = n
Change the number of subintervals to use for approximation.
Most of these methods of approximation are discussed in class: left-hand, right-hand, midpoint, trapezoid, and Simpson’s rules.
When using method=upper or method=lower, Maple approximates area using rectangles based off of the maximum or minimum value of the function in each subinterval, respectively. This can be useful to give upper and lower bounds on the true area bounded by the function and the horizontal axis.

Example 14.2. Approximating Area using Left-hand and Right-hand Rules.

In this example, we will approximate the signed area between \(f(x) = 10 { e}^{-x}\) and the \(x\)-axis using left-hand and right-hand rectanges. First, we will see how Maple can give the approximate area using a specific number of subintervals (which Maple calls a partition). These are two common methods that we learn when first calculating Riemann sums.
To start, we will assign function, \(f(x)\text{.}\) and calculate some approximations.
> f(x) := 10*exp(-x);
\begin{equation*} \displaystyle f\, := \,x\mapsto 10\,{{ e}^{-x}} \end{equation*}
We will start with using eight subintervals and approximate the area using left-hand and right-hand rectangles. The method needs to be specified as well as the number of partitions. Maple will give the exact value of this Riemann sum, which can be converted to decimal using the evalf() command.
> with(Student[Calculus1]):
> ApproximateInt(f(x), x = 0..4, method=left, output=value, partition=8); 
    evalf(%);
\begin{equation*} \displaystyle 5+5\,{{ e}^{-1/2}}+5\,{{ e}^{-1}}+5\,{{ e}^{-3/2}}+5\,{{ e}^{-2}}+5\,{{ e}^{-5/2}}+5\,{{ e}^{-3}} +5\,{{ e}^{-7/2}} \end{equation*}
\begin{equation*} \displaystyle 12.47472497 \end{equation*}
> ApproximateInt(f(x), x = 0..4, method=right, output=value, partition=8);
    evalf(%);
\begin{equation*} \displaystyle 5\,{{ e}^{-1/2}}+5\,{{ e}^{-1}}+5\,{{ e}^{-3/2}}+5\,{{ e}^{-2}}+5\,{{ e}^{-5/2}}+5\,{{ e}^{-3}}+5\,{{ e}^{-7/2}}+5\,{{ e}^{-4}} \end{equation*}
\begin{equation*} \displaystyle 7.566303166 \end{equation*}
If we wish to get the actual area under the curve, then we can use an arbitrary \(n\) rectangles and take the limit as \(n\to\infty\text{.}\)

Aside

> ApproximateInt(f(x), x = 0..4, method=left, output=sum, partition=n);
    limit(%, n = infinity); evalf(%);
\begin{equation*} \displaystyle 4\,{\frac {1}{n}\sum _{i=0}^{n-1}10\,{{ e}^{-4\,{\frac {i}{n}}}}} \end{equation*}
\begin{equation*} \displaystyle 10-10\,{{ e}^{-4}} \end{equation*}
\begin{equation*} \displaystyle 9.816843611 \end{equation*}

Example 14.3. Approximating the Area under.

In this example, we will approximate the signed area between \(f(x) = x \sin(x)\) and the \(x\)-axis using rectangle approximation. Unlike in the previous example, we will be using altenative methods for determining the height of the rectangle in each subinterval (or partition), such as upper, lower, and midpoint.
We will start by assigning the function.
> f(x) := x*sin(x);
\begin{equation*} \displaystyle f\, := \,x\mapsto x\sin \left( x \right) \end{equation*}
The method=upper option always uses the maximum value of \(f(x)\) in each subinterval for the height of each rectangle. Below is a plot of the rectangles as well as the approximation of area given by the method when using ten subintervals. As you can see, this method gives a very deliberate overestimate of the actual area bouded by this function and the \(x\)-axis.
> with(Student[Calculus1]):
> ApproximateInt(f(x), x=-3..3, method=upper, output=plot, partition=10);
> ApproximateInt(f(x), x=-3..3, method=upper, output=value, partition=10);
\begin{equation*} \displaystyle 7.981170598 \end{equation*}
The method=lower option always uses the minimum value of \(f(x)\) in each subinterval for the height of each rectangle.
> ApproximateInt(f(x), x=-3..3, method=lower, output=value, partition=10);
\begin{equation*} \displaystyle 4.202044853 \end{equation*}
Finally, the midpoint rule uses the height of each rectangle as the value of the function at the midpoint in each subinterval. Below is a plot of twenty rectangles using the midpoint rule.
> ApproximateInt(f(x), x=-3..3, method=midpoint,
    output=plot, partition=20);