Newton Cotes and Romberg Integration
Numerical integration, or quadrature, replaces an integral by a weighted sum of function values. Newton-Cotes formulas choose equally spaced nodes and integrate an interpolating polynomial through those nodes. The trapezoidal rule, midpoint rule, and Simpson's rule are the most common members of this family.
Romberg integration accelerates the composite trapezoidal rule by applying Richardson extrapolation to its even-power error expansion. It is a good example of a general numerical pattern: start with a simple approximation at several mesh sizes, then combine the approximations to cancel leading error terms.
Definitions
A quadrature rule has the form
where the are nodes and the are weights. A closed Newton-Cotes rule includes the endpoints. The trapezoidal rule is
Simpson's rule uses the midpoint :
A composite rule divides into subintervals and applies a simple rule repeatedly. If , the composite trapezoidal rule is
Romberg integration builds a triangular table from and
Key results
The local trapezoidal error is proportional to , so the composite trapezoidal rule is second-order accurate for smooth functions. Simpson's rule is exact for polynomials of degree at most three and has fourth-order global accuracy when applied as a composite rule on an even number of subintervals.
The Euler-Maclaurin expansion explains why Romberg works. For sufficiently smooth , the composite trapezoidal approximation has an error expansion of the form
Because only even powers appear under appropriate smoothness assumptions, replacing by and combining estimates can cancel , then , and so on. The first extrapolation is exactly
Newton-Cotes rules are easy to implement, but high-order closed Newton-Cotes formulas can have negative weights and poor stability. In practice, low-order composite rules, adaptive Simpson methods, and Gaussian quadrature are used more often than very high-degree Newton-Cotes rules.
A reliable way to use these results is to keep the analysis tied to the actual numerical question rather than to the formula alone. For Newton-Cotes and Romberg integration, the input record should include the integrand, interval, smoothness, panel count, and endpoint behavior. Without that record, two computations that look similar on paper may have different numerical meanings. The same formula can be a safe production tool in one scaling and a fragile experiment in another. This is why the examples on this page show the intermediate arithmetic: the goal is not only to reach a number, but to expose what assumptions made that number meaningful.
The next record is the verification record. Useful diagnostics for this topic include successive mesh differences, Romberg table stability, and comparison with known polynomial exactness. A diagnostic should be chosen before the computation is trusted, not after a pleasing answer appears. When an exact answer is unavailable, compare two independent approximations, refine the mesh or tolerance, check a residual, or test the method on a neighboring problem with known behavior. If several diagnostics disagree, treat the disagreement as information about conditioning, stability, or implementation rather than as a nuisance to be averaged away.
The cost record matters as well. In this topic the dominant costs are usually function evaluations and reuse of old trapezoid values. Numerical analysis is full of methods that are mathematically attractive but computationally mismatched to the problem size. A dense factorization may be acceptable for a classroom matrix and impossible for a PDE grid. A high-order rule may use fewer steps but more expensive stages. A guaranteed method may take many iterations but provide a bound that a faster method cannot. The right comparison is therefore cost to reach a verified tolerance, not order or elegance in isolation.
Finally, every method here has a recognizable failure mode: endpoint singularities, odd Simpson panel counts, and extrapolation outside the asymptotic regime. These failures are not edge cases to memorize; they are signals that the hypotheses behind the result have been violated or that a different numerical model is needed. A good implementation makes such failures visible through exceptions, warnings, residual reports, or conservative stopping rules. A good hand solution does the same thing in prose by naming the assumption being used and checking it at the point where it matters.
For study purposes, the most useful habit is to separate four layers: the continuous mathematical problem, the discrete approximation, the algebraic or iterative algorithm used to compute it, and the diagnostic used to judge the result. Many mistakes come from mixing these layers. A small algebraic residual may not mean a small modeling error. A small step-to-step change may not mean the discrete equations are solved. A high-order truncation formula may not help when the data are noisy or the arithmetic is unstable. Keeping the layers separate makes the results on this page portable to larger examples.
Visual
| Rule | Nodes on one panel | Degree of precision | Composite order | Best use |
|---|---|---|---|---|
| Trapezoidal | endpoints | 1 | 2 | smooth periodic or cheap evaluations |
| Midpoint | center | 1 | 2 | simple open-panel estimate |
| Simpson | endpoints and midpoint | 3 | 4 | smooth functions, even subinterval count |
| Romberg | nested trapezoids | increases by column | high for smooth functions | smooth non-singular integrands |
Worked example 1: trapezoidal and Simpson rules for
Problem. Approximate
using the single-panel trapezoidal rule and Simpson's rule.
Method. The exact integral is
- Trapezoidal rule:
- Simpson's rule with midpoint :
- Substitute values:
Checked answer. The trapezoidal estimate is , while Simpson's rule gives exactly because has degree less than or equal to three.
Worked example 2: first Romberg extrapolation for
Problem. Approximate
using , , and one Romberg extrapolation.
Method. Use and then .
- One-panel trapezoidal rule:
- Two-panel trapezoidal rule uses :
- Extrapolate:
Checked answer. One extrapolation moves the estimate from to , closer to .
Code
import math
def composite_trapezoid(f, a, b, n):
h = (b - a) / n
total = 0.5 * (f(a) + f(b))
for i in range(1, n):
total += f(a + i * h)
return h * total
def composite_simpson(f, a, b, n):
if n % 2:
raise ValueError("Simpson's rule requires an even number of subintervals")
h = (b - a) / n
total = f(a) + f(b)
for i in range(1, n):
total += (4 if i % 2 else 2) * f(a + i * h)
return h * total / 3.0
def romberg(f, a, b, levels):
table = []
for k in range(levels):
row = [composite_trapezoid(f, a, b, 2**k)]
for j in range(1, k + 1):
row.append(row[j - 1] + (row[j - 1] - table[k - 1][j - 1]) / (4**j - 1))
table.append(row)
return table
f = lambda x: 4.0 / (1.0 + x * x)
for row in romberg(f, 0.0, 1.0, 5):
print(row)
print("pi", math.pi)
Common pitfalls
- Applying Simpson's composite rule with an odd number of subintervals.
- Expecting high-order convergence when the integrand is not smooth enough.
- Using very high-degree Newton-Cotes rules instead of composite low-degree rules.
- Treating Romberg table entries as monotone. Extrapolation can overshoot.
- Ignoring endpoint singularities. Trapezoidal and Simpson error formulas assume bounded derivatives.