| > |
lab10.mws --- Numerical Integration
| > | restart; with( plots ): with( Student[Calculus1] ): |
| > |
Auxiliary Procedures (execute, but do not change)
| > | ApproxIntTable := proc( f, dom, methods, partitions ) local exact, _exact, K, M, hdr, new_row, rows, _hdr, _return, _type; _hdr := table([right=R,left=L,midpoint=M,trapezoid=T,simpson=S]); if nargs>4 and convert(args[5],set) subset {`value`,`error`} then _type := convert(args[5],set) else _type := {`value`} end if; _return := NULL; _exact := Int( f, dom ); hdr := [ n, seq( _hdr[m][n], m=methods ) ]: if member(`value`,_type) then rows := hdr; for K in partitions do new_row := seq( evalf(ApproximateInt( f, dom, method=M, partition=K, output=value )), M=methods ); rows := rows, [ K, new_row ]; end do: _return := _return, Matrix( [rows] ) end if; if member(`error`,_type) then hdr := [ n, seq(E[s], s=hdr[2..-1]) ]; exact:=evalf(_exact); rows := hdr; for K in partitions do new_row := seq( evalf(ApproximateInt( f, dom, method=M, partition=K, output=value ) -exact), M=methods ); rows := rows, [ K, new_row ]; end do: _return := _return, Matrix( [rows] ) end if; return _return end proc: |
| > |
Lab Overview
Earlier in the semester you spent some time learning a variety of integration techniques - integration by parts, partial fractions, trigonometric substitutions, .... While there are many more techniques that you could learn, the fact is that there are many integrals that cannot be evalauted in terms of our standard functions. Recall that an integral as simple as
could not be evaluated in terms of polynomials, rational functions, or trigonometric functions. In this case, in order to have a name for this antiderivative we created the natural logarithm function:
.
Another example was seen in Lab 8. When you worked with the normal distribution, you needed to evaluate integrals such as
.
A new function can be defined to give this a name, but it is not possible to give every integral a name.
The only truly general way to evaluate all definite integrals is numerically. The simplest numerical integration methods involve adding areas of rectangles. In this lab you will see how areas of rectangles can be used to approximate a definite integral. An examination of the errors for a known integral suggest two improved numerical methods, the Trapezoid Rule and Simpson's (or Parabola) Rule.
Maple has a number of convenient utilities for working with numerical integration. The ApproximateIntegration maplet [ Maplet Viewer][ MapleNet] is built around the ApproximateInt command in the Student[Calculus1] package. Also, table of approximations and errors will be produced with the ApproxIntTable command defined at the top of this worksheet.
The lab questions are based directly the examples presented in this worksheet. Notice that there are a total of 12 points in the questions; any score above 7 will be counted as bonus.
Deadline for submitting a lab solution is midnight, Thursday, March 27, 2003.
| > |
--------------------------------------------------------
Be Patient
Some plots and numerical computations take a little time to complete. (Some animations might take a few minutes to prepare.) Clicking a button a second, third, or tenth time does not make the computer work faster. In fact, each time you click a button, that request is added to the queue of requests. Each request will be processed in the order in which it is received. If you think your computer is stalled, contact Jay or Kevin.
--------------------------------------------------------
Example 1: A Graphical Look at
To begin, complete these steps:
After a few seconds you should see a plot (with an unintelligible title) and the Approximated Area pane will show 1.186544012. From the graph, it appears that each rectangle is larger than the actual area under the curve. Thus, we expect
ln(3) < 1.186544012.
| > |
Next,
Now the rectangles are all a little too small, so
ln(3) > 1.019877345.
| > |
Another alternative is to use the midpoint of each subinterval to determine the height of the rectangles. To obtain this approximation:
It is no longer possible to use the graph to determine if this result is too large or too small. But, the approximation, 1.096324725, is clearly better than either the left or right sum. (Note also that this is not the same as the average of the left and right sums.)
| > |
To obtain better approximations, the number of partitions can be increased. To ``see'' the improved approximations that increasing the number of partitions produces, be sure the Animation Options pane has Number of Frames: 6 , the Subdivide Interval is set to halve and Subpartition is set to all . Before creating the animation, turn to your neighbors and check that you are all using different Riemann Sums - either left , midpoint , or right . Then, click Animate . This might take a few minutes. Compare results with your neighbors.
| > |
What is the most accurate estimate for ln(3) that you can make from this information? Which method provides the best estimate? How many subintervals are used? (See Lab Question 0.)
| > |
Example 2 -A Tabular Look at
Once again, consider
| > | f := 1/x: a := 1: b := 3: II := Int( f, x=a..b ): II = value(II); |
The ApproxIntTable command (defined at the top of this worksheet) can be used to prepare a side-by-side comparison of the three Reimann sum, or Rectangle, Rules for several different partitions. The three Rectangle Rules are
| > | Mlist := [ left, right, midpoint ]; |
and consider the partitions
| > | Plist := [ 2, 4, 8, 16, 32, 64, 128, 256, 512 ]: |
The corresponding table of approximations to the integral is
| > | ApproxIntTable( f, x=a..b, Mlist, Plist, `value` ); |
Check that these results agree with the ones found in Example 1.
| > |
The table of errors - the difference between the approximation and the exact value of the integral (ln(3)) - is obtained simply by changing the final argument in the ApproxIntTable command to `error` :
| > | ApproxIntTable( f, x=a..b, Mlist, Plist, `error` ); |
The important observations in this table are:
This final observation is most important. To be more explicit, compare the number of subpartitions required to estimate the integral to two decimal places. For the left or right endpoint approximations,
is required; but, for the midpoint approximation,
suffices.
| > |
| > | ApproxIntTable( f, x=a..b, Mlist, Plist, {`value`,`error`} ); |
| > |
Example 3 - Trapezoidal Rule
Another observation that can be made from the table of errors in Example 2 is that the errors from the left and right endpoint approximations are very close to being negatives of one another. That is,
.
A simple average of these two approximations should produce an approximaiton with a much smaller error. The approximation obtained in this manner is called the Trapezoid Rule.
The reason for this name is that the average of the areas of the left and right endpoint rectangles is the area of the trapezoid formed by connecting the left and right endpoints with a straight line. This fact is illustrated in the following figure for
| > | N := 2: |
subpartitions. (You can change this number, but if it becomes too large you will not be able to distinguish the rectangles and trapezoids.)
| > | Pleft := ApproximateInt( f, x=a..b, method=left, partition=N, output=plot, title="", boxoptions=[color=blue], showarea=false, functionoptions=[color=cyan,style=point] ): Pright := ApproximateInt( f, x=a..b, method=right, partition=N, output=plot, title="", boxoptions=[color=green], showfunction=false, showarea=false ): Ptrap := ApproximateInt( f, x=a..b, method=trapezoid, partition=N, output=plot, title="", boxoptions=[color=red], showfunction=false, showarea=false ): display([Pleft,Pright,Ptrap]); |
| > |
To further analyze the Trapezoid Rule, prepare a new table of errors that inludes the errors for the Trapezoid Rule.
| > | Mlist2 := [op(Mlist),trapezoid]; |
| > | ApproxIntTable( f, x=a..b, Mlist2, Plist, `error` ); |
This shows the increased accuracy of the Trapezoid Rule over either the Left or Right Endpoint Rule. But, the Midpoint Rule is always a better approximation than the Trapezoid Rule.
| > |
Example 4 - Simpson's Rule
Closer inspection of the table of errors in Example 3 reveals the errors for the Midpoint and Trapezoid Rules appears to nearly obey a simple relationship:
.
If this is true, then a weighted average of
and
should give an improved approximation. The appropriate weighted average is
=
+
.
The approximation obtained from this formula is called Simpson's Rule. Because this particular weighting amounts to finding the area under a parabola, another name for this method is the Parabola Rule. The following figure adds this parabola to the rectangles and trapezoid. The improved approximation is quite amazing.
| > | Psimp := ApproximateInt( f, x=a..b, method=simpson, partition=N, output=plot, title="", boxoptions=[color=brown], showfunction=false, showarea=false ): display([Pleft,Pright,Ptrap,Psimp]); |
Wow! The parabola is almost indistinguishable from the graph of the integrand!! Let's see the errors for this method
| > | Mlist3 := [op(Mlist2),simpson]; |
| > | ApproxIntTable( f, x=a..b, Mlist3, Plist, `error` ); |
Notice that Simpson's Rule with
provides an approximation that is accurate to two decimal places. (Compared with
for the Midpoint and Trapezoid Rules and
for the Left and Right Endpoint Rules.)
Looking towards the bottom of the column of errors for Simpson's Rule, these errors are not really zero. Maple reports
0.
because the actual error is smaller than the smallest floating-point number with 10 decimal digits, i.e.,
. To force Maple to work with smaller floating point numbers, change the
Digits
parameter to the number of digits Maple should keep, say 14,, then re-create the table of errors.
| > | Digits := 14: ApproxIntTable( f, x=a..b, Mlist3, Plist, `error` ); Digits := 10: |
To conclude, note that each time the number of subintervals is doubled, Simpson's Rule provides one additional decimal digit in the approximation. (See Lab Question 2.)
| > |
Lab Questions
0. [ 2 points ]
What is the most accurate estimate for ln(3) that you can make from the information collected in Example 1?
Which method provides the best estimate? How many partitions are used?
1. [ 5 points ]
Consider the function
and the integral
.
(a) Graph
on the interval [ 0, 10 ]. Is f periodic? If so, what is the period?
(b) What is the floating-point approximation Maple reports for the definite integral
?
(c) Find the left, right, midpoint, trapezoid, and Simpson's rule approximations with
to this integral?
(d) Find
such that the first 6 decimal digits of
agree with the corresponding digits of
. What is the value of I to 6 decimal digits?
(e) Using
from (d), how many decimal digits of
,
,
, and
are correct?
2. [2 points, Essay Question]
Reconsider the table of errors in Example 4. In general, how many times must the number of subpartitions be doubled to obtain one additional decimal digit of accuracy for the Left, Right, Midpoint, and Trapezoid Rules? (For Simpson's Rule, it was observed that one additional decimal digit is obtained each time the number of subpartitions is doubled.)
3. [3 points]
The exact value of the integral in Lab Question 1 can be expressed in terms of a Fresnel sine function.
What is the definition of the Fresnel sine function?
Use Maple to express the integral in Lab Question 1 in terms of the Fresnel sine function.
Who is Fresnel (give name, dates of birth and death, and one important scientific contribution)?
| > |
| > |