Last time | Next time |
Today:
This will be your last "homework" to turn in; any other assignments will be part of your final takehome (thinking of 6.2, 6.3).
I've talked to two of you, who seem to have a pretty solid project idea; who still needs one?
While there is no motivation for this, the author shows that it works. Maybe it's just magic.... or a good project?
In fact, Simpson's rule is just a weighted average of the two previous methods (remember Long's rule: whenever you have two approximations, you have a third -- an average).
In particular, the midpoint method is twice as good as the trapezoidal method, and the errors tend to be of opposite sign. This analysis is based off of an approximating parabola
So your code for the Simpson's rule is \[ simp(f,a,b) = \frac{1}{3}\left(2*mid(f,a,b)+trap(f,a,b)\right) \]
The trapezoidal method is the integral of a linear interpolator of two endpoints, and midpoint is the integral of the constant function passing through -- well, the midpoint of the interval!
This illustrates one important different application of these two methods:
These methods are both examples of what are called "Newton-Cotes methods" -- trapezoidal is a "closed" method, and midpoint is "open".
The first idea is to paste these methods together on a "partition" of the interval of integration -- that is, multiple sub-intervals, on each one of which we apply the simple rule. This pasted up version is called a "composite" rule.
We start by assuming a partition of the interval $[a{,}b]$ that is equally spaced. But in the end, we should let the behavior of $f$ help us to determine the the partition of the interval. This is called "adaptive" integration.
These figures illustrate one of the methods in action -- which one?
The maximum subinterval width ($||{P}||$) goes to
zero. The partition gets thinner and thinner, as the number of
subintervals (n) goes to $\infty$. The approximations get better and better, of course, as $n \longrightarrow \infty$.
Notice that the larger subintervals occur where the function isn't
changing as rapidly. |
Let's have a look at the derivation of the composite rule on page 168, and, in particular, note the error term (defined as the exact integral minus the approximation), which can be written as \[ -\frac{b-a}{12}h^2f^{(2)}(\xi), \] with $\xi \in (a,b)$ and with (our author switches focus to \(n\), in part, I fear, because of his infatuation with stencils....:)
(Look at the dance he does in the pseudo-code: what purpose does his \(h\) serve?)
This is a "divide and conquer" algorithm. Very slick!
Here's some Mathematica code that I wrote to illustrate the idea. It includes examples of how we can turn this into a plotting routine....
But the idea is really swell, and I am delighted by this method!
Here's another picture of how we might build one of these.