Goal: Approximate the definite integral of a function f(x) from a to b numerically: ∫abf(x)dx, where f:R→R.
Quadrature Formula: Approximate the definite integral using a weighted sum of function values at specific points:
∫<em>abf(x)dx≈ω</em>0f(x<em>0)+⋯+ω</em>nf(xn)
x<em>0,…,x</em>n are the quadrature nodes.
ω<em>0,…,ω</em>n are the quadrature weights.
Definition: A quadrature rule is exact for polynomials of degree n if it gives the exact value when f(x) is a polynomial of degree less than or equal to n.
Change of Variables
Transformation: Use the change of variable y=b−ax−a to transform the integral over the interval [a,b] to an integral over [0,1]: ∫<em>abf(x)dx=(b−a)∫</em>01g(y)dy, where g(y)=f(a+(b−a)y).
Interval Transformation: Quadrature formulas on [0,1] can be transformed to any interval [a,b]:
Interval
Weights
Nodes
[0,1]
omega<em>k | nk |
| [a,b] | (b−a)ω</em>k
a+k⋅nb−a
Basic Closed Newton-Cotes Formulas
Idea: Replace f(x) with an interpolating polynomial P<em>n(x) using n+1 equispaced nodes in [a,b]:
P</em>n(x)=∑<em>k=0nf(x</em>k)ℓ<em>k(x), where ℓ</em>k(x)=∏<em>j=kx<em>k−x</em>jx−x</em>j, and xk=a+k⋅nb−a.
Closed Quadrature Newton-Cotes Formulas: Approximate the integral as: ∫<em>abf(x)dx≈∑</em>k=0nf(x<em>k)α</em>k, where α<em>k=∫</em>abℓk(x)dx.
Weights of the NC Quadrature Rules
Lemma: The coefficients alpha<em>k are unique such that ∫</em>abp(x)dx=∑<em>k=0np(x</em>k)αk for any polynomial p(x) of degree less than or equal to n.
Calculating Weights: To find the values of alpha<em>k, take p</em>j(x)=xj for j=0,…,n. Since ∫<em>01xjdx=j+11 for j=0,…,n, we solve the following linear system:
\begin{aligned}
\alpha0 + \alpha1 + \cdots + \alpha{n-1} + \alphan &= \frac{1}{1} \
\frac{1}{n}\alpha1 + \cdots + \frac{n-1}{n} \alpha{n-1} + \alphan &= \frac{1}{2} \
\vdots \
\left(\frac{1}{n}\right)^n \alpha1 + \cdots + \left(\frac{n-1}{n}\right)^n \alpha{n-1} + \alpha_n &= \frac{1}{n+1}
\end{aligned}
Recall: The error in polynomial interpolation: f(x)=P<em>n(x)+(n+1)!∏</em>i=0n(x−xi)f(n+1)(ξ(x)), where a≤ξ(x)≤b.
Integrating: Integrating the error term gives: ∫<em>abf(x)dx=∫</em>ab[P<em>n(x)+(n+1)!∏</em>i=0n(x−x<em>i)f(n+1)(ξ(x))]dx=∫</em>abP<em>n(x)dx+∫</em>ab(n+1)!∏<em>i=0n(x−x</em>i)f(n+1)(ξ(x))dx =∑<em>k=0nf(x</em>k)α<em>k+∫</em>ab(n+1)!∏<em>i=0n(x−x</em>i)f(n+1)(ξ(x))dx.
Error Bound: The error is thus bounded by E<em>n(f):=∫</em>abf(x)dx−∑<em>k=0nf(x</em>k)α<em>k=∫</em>ab(n+1)!∏<em>i=0n(x−x</em>i)f(n+1)(ξ(x))dx ≤∫<em>ab(n+1)!∏</em>i=0n∣x−x<em>i∣∣f(n+1)(ξ(x))∣dx≤(n+1)!(b−a)n+1max</em>a≤x≤b∣f(n+1)(x)∣∫ab1dx.
Error Bound for Simple Closed Newton-Cotes Formula: E<em>n(f)≤(n+1)!(b−a)n+2⋅max</em>a≤x≤b∣f(n+1)(x)∣.
Even n Error: If n is even, then E<em>n+1(f)≤c</em>n⋅(b−a)n+3⋅max<em>a≤x≤b∣f(n+2)(x)∣, where c</em>n=(n+2)!1∫0nt2(t−1)⋯(t−n)dt.
Composite NC Formulas: Basic Setting
Idea: Split the interval [a,b] into subintervals [a,x<em>1]∪[x</em>1,x<em>2]∪⋯∪[x</em>p−1,b], integrate over each subinterval, and apply a Newton-Cotes formula with n+1 nodes to each. ∫<em>abf(x)dx=∫</em>ax<em>1f(x)dx+∫</em>x<em>1x</em>2f(x)dx+⋯+∫<em>x</em>p−1bf(x)dx,
Ingredients:
N=np (total number of intervals).
hN=Nb−a (integration step).
x<em>j=a+j⋅h</em>N for j=0,…,N (integration nodes).
Error Bound: For n odd: E(f)≤(b−a)(Nb−a)n+1⋅(n+1)!nn+1⋅maxa≤x≤b∣f(n+1)(x)∣
Error Bound: For n even: E(f)≤c<em>n⋅(b−a)(Nb−a)n+2⋅nn+2⋅max</em>a≤x≤b∣f(n+2)(x)∣
Note: n is fixed. This method can be too expensive.
Richardson Extrapolation
Concept: Given an approximation A(h) to some quantity A, dependent on a stepsize h: A(h)=A+chn+O(hn+1) (where c may depend on n but not on h).
Example: NC for n odd is an approximation to A=∫abf(x)dx with order n+1 on h=Nb−a.
Richardson Extrapolation Formula: R(h,t):=tn−1tnA(h/t)−A(h)
has convergence order n+1, since R(h,t)=tn−1tn(A+c(th)n+O(hn+1))−(A+chn+O(hn+1))=A+O(hn+1).
Extrapolated Simpson Rule
Apply Richardson extrapolation to the simple Simpson rule, S(h), with t=2 in [a,b], where h=b−a.
Let h=b−a: Q(h)=90h[7f(a)+32f(a+4h)+12f(a+2h)+32f(a+43h)+7f(b)]
This is the simple closed Newton-Cotes formula for 5 nodes and is exact for polynomials with degree less than or equal to 5.
Adaptive Integration
Goal: Obtain a good approximation to ∫abf(x)dx while minimizing the number of function evaluations.
Idea: Break [a,b] into pieces. Approximate the integral in each piece using two different methods (e.g., simple and composite formulas). If the difference is small enough, use Richardson extrapolation. Otherwise, subdivide the interval and repeat.
Steps:
Compute S and S2 (simple and composite Simpson's rule with 2 subintervals).
Evaluate E=∣S−S2∣, which estimates the error.
If E≤tol, then ∫<em>abf(x)dx≈1516S</em>2−S=Q.
If E > tol, repeat steps 1 and 2 in:
Step 3.1: the interval [a,2a+b], and
Step 3.2: the interval [2a+b,b].
Add up the values of Q obtained in all steps at each iteration.
MATLAB Commands
quad: MATLAB's professional method for approximating integrals, using an extrapolated Simpson's rule in an adaptive method.
quadtx: version of quad in the NCM book/folder.
Example
f(x)=e−4xsin(2x) in [0,4]
Exercise
I:=4∫011+x21dx.
What is the value of I?
Approximate I using the trapezoid rule.
Approximate I using Simpson's rule.
Approximate I using composite Simpson's rule with 8 intervals.
How many subintervals are needed to approximate I to within 10−16 using the composite Simpson's formula?