In numerical analysis, Romberg's method is used to estimate the definite integral by applying Richardson extrapolation repeatedly on the trapezium rule or the rectangle rule (midpoint rule). The estimates generate a triangular array. Romberg's method is a Newton–Cotes formula – it evaluates the integrand at equally spaced points.The integrand must have continuous derivatives, though fairly good resultsmay be obtained if only a few derivatives exist.If it is possible to evaluate the integrand at unequally spaced points, then other methods such as Gaussian quadrature and Clenshaw–Curtis quadrature are generally more accurate.
The method is named after Werner Romberg, who published the method in 1955.
Using , the method can be inductively defined bywhere
n\gem
m\ge1
2m+2 | |
O\left(h | |
n |
\right).
The zeroeth extrapolation,, is equivalent to the trapezoidal rule with points; the first extrapolation,, is equivalent to Simpson's rule with points. The second extrapolation,, is equivalent to Boole's rule with points. The further extrapolations differ from Newton-Cotes formulas. In particular further Romberg extrapolations expand on Boole's rule in very slight ways, modifying weights into ratios similar as in Boole's rule. In contrast, further Newton-Cotes methods produce increasingly differing weights, eventually leading to large positive and negative weights. This is indicative of how large degree interpolating polynomial Newton-Cotes methods fail to converge for many integrals, while Romberg integration is more stable.
By labelling our approximations as instead of , we can perform Richardson extrapolation with the error formula defined below:Once we have obtained our approximations , we can label them as .
When function evaluations are expensive, it may be preferable to replace the polynomial interpolation of Richardson with the rational interpolation proposed by .
To estimate the area under a curve the trapezoid rule is applied first to one-piece, then two, then four, and so on.After trapezoid rule estimates are obtained, Richardson extrapolation is applied.
- ! Number of pieces | Trapezoid estimates | First iteration | Second iteration | Third iteration | - | - | 1 | 0 | - | 2 | 16 | - | 4 | 30 | - | 8 | 39 | - | - |
As an example, the Gaussian function is integrated from 0 to 1, i.e. the error function erf(1) ≈ 0.842700792949715. The triangular array is calculated row by row and calculation is terminated if the two last entries in the last row differ less than 10-8.
0.77174333 0.82526296 0.84310283 0.83836778 0.84273605 0.84271160 0.84161922 0.84270304 0.84270083 0.84270066 0.84243051 0.84270093 0.84270079 0.84270079 0.84270079
The result in the lower right corner of the triangular array is accurate to the digits shown.It is remarkable that this result is derived from the less accurate approximationsobtained by the trapezium rule in the first column of the triangular array.
Here is an example of a computer implementation of the Romberg method (in the C programming language):
void print_row(size_t i, double *R)
/*INPUT:(*f) : pointer to the function to be integrateda : lower limitb : upper limitmax_steps: maximum steps of the procedureacc : desired accuracy
OUTPUT:Rp[max_steps-1]: approximate value of the integral of the function f for x in [a,b] with accuracy 'acc' and steps 'max_steps'.
double romberg(double (*f)(double), double a, double b, size_t max_steps, double acc)
Here is an implementation of the Romberg method (in the Python programming language):
def romberg(f, a, b, max_steps, acc): """ Calculates the integral of a function using Romberg integration.
Args: f: The function to integrate. a: Lower limit of integration. b: Upper limit of integration. max_steps: Maximum number of steps. acc: Desired accuracy.
Returns: The approximate value of the integral. """ R1, R2 = [0] * max_steps, [0] * max_steps # Buffers for storing rows Rp, Rc = R1, R2 # Pointers to previous and current rows
h = b - a # Step size Rp[0] = 0.5 * h * (f(a) + f(b)) # First trapezoidal step
print_row(0, Rp)
for i in range(1, max_steps): h /= 2. c = 0 ep = 1 << (i - 1) # 2^(i-1) for j in range(1, ep + 1): c += f(a + (2 * j - 1) * h) Rc[0] = h * c + 0.5 * Rp[0] # R(i,0)
for j in range(1, i + 1): n_k = 4**j Rc[j] = (n_k * Rc[j - 1] - Rp[j - 1]) / (n_k - 1) # Compute R(i,j)
# Print ith row of R, R[i,i] is the best estimate so far print_row(i, Rc)
if i > 1 and abs(Rp[i - 1] - Rc[i]) < acc: return Rc[i]
# Swap Rn and Rc for next iteration Rp, Rc = Rc, Rp
return Rp[max_steps - 1] # Return our best guess
2n+1