Calculus, Linear Algebra & Discrete Math Integrals & Applications of Integration Composite Simpson's 1/3 and 3/8 rules with the classical fourth-derivative error bound

Simpson's Rule Calculator (1/3 and 3/8)

Simpson's rule fits a parabola through every consecutive triple of points and integrates the parabolas instead of the function. This calculator applies either the 1/3 rule or the 3/8 rule to your integrand, prints the full node table with the coefficient on each ordinate, and compares the result against a high-accuracy reference value so you can see the actual error rather than only the bound. It also reports the classical bound built from the maximum fourth derivative over the interval, and adjusts n when the rule you picked requires it.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Integrand f(x)Use ^ for powers, * for multiplication (2*x, 2x and a plain space all work, so x sin(x) is read as a product), and the function names sin, cos, tan, sec, csc, cot, asin, acos, atan, sinh, cosh, tanh, exp, ln, log (base 10), sqrt, cbrt and abs. The constants pi and e are recognised.sin(x)
Lower limit aWhere the interval starts.0
Upper limit bWhere it ends. The default is pi, so the exact answer is 2.3.141592653589793
Subintervals nThe 1/3 rule needs n even and the 3/8 rule needs n a multiple of three; the calculator raises n if it has to.4
Rule variantBoth are fourth-order accurate; the 1/3 rule is the usual choice and the 3/8 rule handles panel counts divisible by three.Simpson's 1/3 rule

It returns

  • Simpson estimate — The weighted sum of the ordinates times the rule's leading factor.
  • Subintervals actually used
  • Reference value — Computed by adaptive quadrature at a tolerance of 1e-12, for comparison.
  • Actual error
  • Classical error bound — Built from the largest absolute fourth derivative found on the interval.
  • Step size Δx

The formula

abfΔx3[f0+4f1+2f2++4fn1+fn]
abf3Δx8[f0+3f1+3f2+2f3++fn]
|E|(ba)5max|f(4)|180n4

In plain text: ∫ ≈ (Δx/3)[f₀ + 4f₁ + 2f₂ + 4f₃ + … + 4f₍ₙ₋₁₎ + fₙ]

  • ΔxStep size, equal to (b − a)/n (units of x)
  • nNumber of subintervals; even for the 1/3 rule, a multiple of three for the 3/8 rule (count)
  • fᵢThe integrand evaluated at node xᵢ = a + i·Δx (units of f)

The alternating 4-2-4 pattern comes from integrating a parabola through each consecutive triple of nodes. Interior nodes shared by two parabolas pick up a coefficient of 2; the ends belong to one parabola each.

Updated Category Integrals & Applications of Integration Verified against published test cases Reading time 9 min

Fit parabolas, not rectangles

Every numerical integration rule replaces the integrand with something easy to integrate exactly. Riemann sums use flat rectangles. The trapezoidal rule uses straight lines. Simpson's rule uses parabolas, and that one step up in polynomial degree buys far more accuracy than it costs.

Take three equally spaced points on the curve. Exactly one parabola passes through them, and its integral over that pair of subintervals works out to (Δx/3)(f₀ + 4f₁ + f₂). Chain those pairs across the interval, and the shared interior nodes belong to two parabolas each, which is where the alternating 4-2-4-2 pattern comes from: interior odd-numbered nodes sit at the middle of a panel and get weight 4, interior even-numbered nodes are shared between panels and get weight 2, and the two ends get weight 1.

The remarkable part is that Simpson's rule is exact for cubics as well as quadratics, even though it only fits a parabola. The cubic part of the error is odd about the midpoint of each panel and integrates to zero. That accidental extra order is why the error scales with the fourth derivative rather than the third, and why halving the step divides the error by roughly sixteen instead of eight.

The 3/8 variant fits a cubic through four points instead of a parabola through three. Its accuracy is the same order, and its practical use is finishing an interval whose panel count is not even — you take one 3/8 panel and run 1/3 panels for the rest.

Applying the rule step by step

Step 1: choose n and compute Δx. Δx = (b − a)/n. For the 1/3 rule n must be even, because the nodes are consumed two at a time. For the 3/8 rule it must be a multiple of three. If you enter a value that does not satisfy the requirement, this calculator raises n to the next legal value and says so, rather than producing a silently wrong weighting.

Step 2: tabulate the nodes. xᵢ = a + i·Δx for i = 0…n. That is n + 1 ordinates, one more than the number of subintervals.

Step 3: apply the coefficients. For the 1/3 rule: 1, 4, 2, 4, 2, …, 4, 1. For the 3/8 rule: 1, 3, 3, 2, 3, 3, 2, …, 3, 3, 1. A quick check on your own work: the coefficients of the 1/3 rule sum to 3n, and those of the 3/8 rule sum to 8n/3. If your column does not add to that, a coefficient is in the wrong place.

Step 4: multiply by the leading factor. Δx/3 for the 1/3 rule, 3Δx/8 for the 3/8 rule.

The node table on this page carries out all four steps in the open, one row per node, with the coefficient and the weighted contribution in their own columns. That is the layout an examiner expects to see, and it is where a hand calculation most often goes wrong.

Worked example: ∫ from 0 to π of sin x dx with n = 4

The exact answer is [−cos x] from 0 to π, which is 1 + 1 = 2. Now approximate it.

  1. Step size. Δx = (π − 0)/4 = 0.7853982.
  2. Nodes. x₀ = 0, x₁ = 0.7853982, x₂ = 1.5707963, x₃ = 2.3561945, x₄ = 3.1415927.
  3. Ordinates. f₀ = 0, f₁ = 0.7071068, f₂ = 1, f₃ = 0.7071068, f₄ = 0.
  4. Weighted sum. 0 + 4(0.7071068) + 2(1) + 4(0.7071068) + 0 = 2.8284271 + 2 + 2.8284271 = 7.6568542.
  5. Multiply by Δx/3. 0.7853982/3 = 0.2617994, and 0.2617994 × 7.6568542 = 2.0045598.

The estimate is 2.0045598 against an exact 2, an error of 0.0045598 — about two parts in a thousand from only five evaluations of the sine.

Double the panels. With n = 8 the same procedure gives 2.0002692, an error of 0.0002692. Divide the first error by the second: 0.0045598 / 0.0002692 = 16.94. Fourth-order accuracy predicts a factor of 16, and the excess is the higher-order remainder that the leading term ignores.

Compare the bound. For sin x the fourth derivative is sin x again, so max|f⁗| = 1 on this interval. The bound is π⁵ × 1 / (180 × 4⁴) = 306.0197/46080 = 0.006641. The true error of 0.0045598 sits below it, as it must, and the ratio of about 1.5 is typical: the bound is a guarantee, not a prediction.

How to read the two error figures

The actual error compares Simpson against a reference. The reference is adaptive quadrature run to a tolerance of 1e−12, which is far tighter than any hand calculation, so the difference is a fair measurement of Simpson's own error on a smooth integrand.

The classical bound is a guarantee, and it is usually loose. It takes the largest absolute fourth derivative anywhere on the interval and assumes the worst case at every panel. Real integrands rarely achieve that, so the measured error typically lands a factor of two to five below the bound. A bound that is comfortably above the measured error is exactly what you should expect.

The bound is estimated, not exact, and here is how. This calculator differentiates your function symbolically four times and samples the result at 201 points across the interval to find its largest absolute value. If the fourth derivative has a spike between those samples, the estimate is low and the bound loses its guarantee. Where the fourth derivative does not exist at all — a corner, or a square-root singularity at an endpoint — the bound is meaningless and the calculator says so when the measured error exceeds it.

Doubling n divides the error by about sixteen. That is the practical content of fourth-order accuracy, and it is the fastest way to check whether the rule is behaving. If the ratio comes out much lower, your integrand is not smooth enough for Simpson's error analysis to apply.

Simpson's rule against the exact value, at four panel counts

Every row is Simpson's 1/3 rule applied to sin x from 0 to π, whose exact integral is 2. Values are produced by this calculator.
nΔxSimpson estimateErrorError ratio to previous
21.57079632.09439510.0943951
40.78539822.00455980.004559820.70
80.39269912.00026920.000269216.94
160.19634952.00001660.000016616.22
320.09817482.00000100.000001016.06

The ratio column converges toward 16 from above, which is the signature of a fourth-order method: the leading error term dominates more completely as the step shrinks.

Where Simpson's rule goes wrong

  • Using an odd n with the 1/3 rule. The panels are consumed in pairs, so an odd count leaves one subinterval with no partner. This calculator raises n rather than mis-weighting the last node.
  • Getting the coefficient pattern out of phase. The interior pattern is 4, 2, 4, 2 with 4 on odd-numbered nodes. Starting with 2 gives an answer that looks plausible and is wrong. Check that the coefficients sum to 3n.
  • Forgetting that the ends carry weight 1. There are n + 1 ordinates, not n, and the first and last are not multiplied by anything.
  • Applying it across a discontinuity or a corner. The error analysis assumes four continuous derivatives. Split the interval at the bad point and apply the rule to each piece.
  • Trusting the bound when the fourth derivative is unbounded. For an integrand such as sqrt(x) near zero the fourth derivative blows up, the bound is infinite in principle, and the observed convergence is far slower than fourth order.
  • Working in degrees. As with every calculus result involving trigonometric functions, the nodes and ordinates here assume radians.

Choosing between Simpson, the trapezoidal rule and adaptive quadrature

Simpson beats the trapezoidal rule decisively on smooth integrands. The trapezoidal rule is second order, so halving the step divides its error by four rather than sixteen. On the sine example with n = 4, the trapezoidal rule gives 1.8961189 with an error of 0.104, roughly twenty-three times worse than Simpson's for the same five function evaluations. The trapezoidal rule calculator shows that calculation in the same node-table format.

The trapezoidal rule wins on data rather than formulas. Fitting parabolas to noisy measurements amplifies the noise, and trapezoids do not. It is also the natural choice for unequally spaced points, where Simpson's fixed pattern does not apply at all.

The 1/3 and 3/8 rules have the same order. Both are fourth order; the 3/8 rule is marginally less accurate per function evaluation, and its role is to mop up a panel count that is not even. If you have full control over n, use the 1/3 rule.

Adaptive quadrature beats both when you only want the answer. Rather than spacing nodes evenly, it subdivides where the integrand is hard and leaves smooth stretches alone, which is what the definite integral calculator does. Fixed-step Simpson remains the right tool when the point is to show the method — in a numerical-methods course, a hand calculation, or a spreadsheet somebody else has to audit.

For the crudest picture of what all these methods are approximating, Riemann sums show the definition itself: rectangles, no cleverness, first-order accuracy.

Frequently asked questions

Why does n have to be even for Simpson's 1/3 rule?

Because each parabola spans two subintervals, so the panels are consumed in pairs. With an odd n one subinterval is left without a partner and the coefficient pattern breaks. Either raise n by one, as this calculator does, or finish the interval with a single 3/8 panel covering three subintervals.

Why is Simpson's rule exact for cubics when it only fits parabolas?

Because the cubic part of the error is antisymmetric about the midpoint of each panel and integrates to exactly zero. The first term that survives involves the fourth derivative, which is why the rule is fourth-order accurate and why integrates exactly with only two subintervals — one of the test vectors on this page.

What is the difference between the 1/3 and 3/8 rules?

The 1/3 rule fits a parabola through three points and needs an even number of subintervals; the 3/8 rule fits a cubic through four points and needs a multiple of three. Both are fourth order. In practice the 3/8 rule exists to finish an interval whose panel count is not even, and the 1/3 rule does the rest.

How do I choose n?

Start small, double it, and watch the answer. If the change between successive estimates falls by a factor of roughly sixteen each time, the rule is converging as it should and you can stop when the change drops below your tolerance. The convergence table in the reference section shows exactly that pattern for the sine example.

Why is my actual error smaller than the error bound?

Because the bound assumes the fourth derivative reaches its maximum on every panel, which almost never happens. A measured error a few times below the bound is the normal outcome. The bound is a guarantee about the worst case, not a forecast of the typical one.

Can I use Simpson's rule on a table of measured data?

Only if the points are equally spaced and the count matches the rule's requirement. Even then, fitting parabolas through noisy readings amplifies the noise, so the trapezoidal rule is usually the safer choice for laboratory data. Simpson shines on smooth analytic functions, where its extra accuracy is real rather than an artefact of over-fitting.

What happens if my function is undefined at one of the nodes?

No estimate can be formed, and the calculator says so rather than silently dropping the node. Every node from a to b must lie inside the domain of f. If the trouble is at an endpoint, integrate from just inside it and treat the result as an improper-integral approximation, or use adaptive quadrature instead.

How is the maximum fourth derivative estimated?

The calculator differentiates your expression symbolically four times and evaluates the result at 201 evenly spaced points across the interval, taking the largest absolute value it finds. That is an estimate rather than a proof: a narrow spike between sample points would be missed, and the bound would then be understated.

References

  • Numerical Analysis, 10th edition (Newton-Cotes formulas and their error terms) — Burden & Faires, Cengage Learning
  • Numerical Recipes: The Art of Scientific Computing, 3rd edition (classical formulas for equally spaced abscissas) — Press, Teukolsky, Vetterling & Flannery, Cambridge University Press
  • Handbook of Mathematical Functions, Chapter 25: Numerical Interpolation, Differentiation and Integration — Abramowitz & Stegun, National Bureau of Standards