Numerical Integration
The definition of the
definite integral is:
$$
\int_a^b f(x)\, dx = \lim_{n \to \infty} \sum_{i=1}^n f(c_i)\, \Delta x_i,
$$
where we may select \(c_i \in [x_{i-1},x_i]\) in any way that we wish.
Left-endpoint Approximation
We pick \(c_i = x_{i-1}\).
We also set \(\Delta x_i = \frac{b-a}{b}\), that is, cut \([a,b]\) into $n$ equal pieces.
If \(S_n\) is the $n$th Riemann sum, then \(\displaystyle \int_a^b f(x)\, dx \approx S_n\). The formula is:
$$
S_n = \sum_{i=1}^n f(c_i) \Delta x_i
$$
Next, we have Sage do all the hard work:
Right-endpoint Approximation
We pick \(c_i = x_{i}\) which is the right end point of each subinterval \([x_{i-1},x_i]\).
Midpoint Approximation
We pick \(c_i = \frac{x_{i-1}+x_{i}}{2}\) which is the right end point of each subinterval \([x_{i-1},x_i]\).
Trapezoid Rule Approximation
This time the formula is different. We want the trapezoid above the subinteral \([x_{i-1},x_i]\) with heights \(f(x_{i-1})\) and \(f(x_i)\).
Each trapezoid has area
$$
\Delta x \cdot \left(\frac{f(x_{i-1})+f(x_i)}{2}\right),
$$
which we must sum.
Simpson's Rule Approximation
This one is very interesting since it uses parabolas instead of lines to approximate.
Fact: Given three points \(P_0\), \(P_1\), and \(P_2\), there's only one and only one parabola that passes through \(P_0\), \(P_1\), and \(P_2\).
Simpson's Rule is based on this fact and uses an EVEN number of subintervals. It uses pairs of consecutive subintervals \([x_{i-1},x_i]\) and \([x_i,x_{i+1}]\) with the three points \((x_{i-1},f(x_{i-1}))\), \((x_{i},f(x_{i}))\), and \((x_{i+1},f(x_{i+1}))\) to generate parabolas that best fit the curve over these two subintervals.
See the textbook for the details of the derivation.
Try it!
A few more examples.
Exploration
For the following inquiries, look for non-constant, non-linear functions with the desired qualities.
Inquiry 1
Find a function where the LEA is better than the REA--that is, has smaller error. Then find a function where the REA is better than the LEA.
Inquiry 2
Find a function where the MPA is better than either the LEA or the REA.
Inquiry 3
Find a function where Simpson's Rule is better than the MPA.
Inquiry 4
By taking \([a,b]\) larger and larger, see if you can anticipate what \(\int_{-\infty}^{\infty} e^{-x^2}\, dx\) is.
Note: for an exact answer you need Multivarialbe calculus ;-)
Extra-Credit
Write working Sage code that will generate the graphics for the parabolas for Simpson's Rule.
Your Turn