How to use the numerical integration calculator
- Type the function f(x) and the lower and upper limits. Limits can be numbers or expressions such as pi/2.
- Choose an even number of subintervals for the trapezoid and Simpson rules. More intervals give a closer answer.
- Open More options to choose the number of Romberg levels. Each extra level doubles the number of intervals used.
- Compare the three results and read the error estimates. When they agree to many digits, the answer is reliable.
Formula
trapezoid: T = h x (f(a)/2 + f(a+h) + ... + f(b)/2), error ~ h^2
Simpson: S = h/3 x (f0 + 4 f1 + 2 f2 + ... + 4 f(n-1) + f(n)), error ~ h^4
error left in the n-interval results (estimate): 4/3 x (T(2n) - T(n)) and 16/15 x (S(2n) - S(n))
Romberg: R(k, j) = R(k, j-1) + (R(k, j-1) - R(k-1, j-1)) / (4^j - 1)
h is the width of one subinterval, (b - a) / n. Romberg extrapolation combines trapezoid results with 1, 2, 4, 8 ... intervals to cancel the leading error terms one after another.
The area under one arch of sine
For sin(x) from 0 to pi with 10 intervals, the trapezoid rule gives 1.98352353751 and Simpson's rule gives 2.00010951732. With 20 intervals the trapezoid value becomes 1.99588597271 and the Simpson value 2.00000678444. The error estimates for the 10-interval results, 4/3 x (T20 - T10) = 0.0165 and 16/15 x (S20 - S10) = 0.00011, are close to the true errors, 0.01648 and 0.0001095.
Romberg extrapolation with 6 levels, using 32 intervals, gives 2.000000000001, within 5.3e-12 of its previous level. The exact integral is 2.
Which rule to trust
The trapezoid rule replaces the curve by straight lines and is exact only for straight-line functions. Simpson's rule uses parabolas and is exact for polynomials up to degree three, so it is much more accurate for the same number of points. Romberg extrapolation uses only trapezoid values, yet it reaches Simpson-like accuracy and beyond for smooth functions.
For smooth functions the error shrinks quickly with more intervals. For functions with a sharp corner, a spike or very fast wiggles, many more intervals are needed and the error estimates are only reliable once the results are already close.
Limits and singular points
The function must be finite at every point the rules use, including both ends. A function such as 1/x on an interval that includes 0 is rejected with the first bad point named. Reversed limits give the negative of the integral. For an exact antiderivative, use algebra instead; this tool is for cases without one. To see the function before integrating, use the Graphing Calculator, and to find where it crosses zero, the Root Finder.
More math tools
For other numerical methods, try the Error Propagation Calculator, Minimum Spanning Tree Calculator and Polynomial Root Finder.
Assumptions and limits
- The function is smooth enough that the rules converge as the number of intervals grows.
- Trigonometric functions use radians.
- The number of intervals is even, between 2 and 100,000, and Romberg levels are between 2 and 14.
- Error estimates compare a rule with itself at twice the intervals and are estimates, not guarantees.
Frequently asked questions
Why must the number of intervals be even?
Simpson's rule pairs the intervals, using three points per pair, so it needs an even count. The trapezoid rule works with any count, but the same number is used for both for easy comparison.
What does the Romberg change at the last level mean?
It is the difference between the last two diagonal entries of the Romberg table. A tiny value means the extrapolation has settled, which is a good sign but not a proof.
Can I integrate to infinity?
No. Both limits must be finite numbers. For an improper integral, pick a large finite limit and check that the result stops changing as you raise it.
Why is the result for a spike so wrong?
If a narrow feature falls between the sample points, the rules never see it. Increase the number of intervals until the answer stops changing.