Skip to content
MoneyDeck

Trapezoidal & Simpson's Rule Calculator

Approximate a definite integral three ways and compare the errors

Updated · Free, no signup

Use x as the variable. Supports ^, sqrt, exp, ln, log10, sin, cos, tan, abs, pi, e.

Simpson's rule needs n even.

Simpson's rule

0.74682495

Trapezoidal rule

0.7462108

Midpoint rule

0.74713088

Reference value (high precision)

0.7468241328

Simpson's absolute error

0.0000008154

Trapezoid absolute error

0.0006133367

Midpoint absolute error

0.0003067449

Step size h = (b − a)/n

0.1

  • With n = 10, Simpson's rule is closest to the reference value (error ≈ 8.15e-7).
  • The midpoint error is about 0.5 × the trapezoid error — for smooth curves it is typically about half, with the opposite sign.

f(x) over the interval

Sample points and weights

ixᵢf(xᵢ)Trapezoid weightSimpson weight
00111
10.10.990049833724
20.20.960789439222
30.30.913931185324
40.40.85214378922
50.50.778800783124
60.60.697676326122
70.70.612626394224
80.80.52729242422
90.90.444858066224
1010.367879441211

About the Trapezoidal & Simpson's Rule Calculator

This numerical integration calculator approximates a definite integral ∫ f(x) dx from a to b with three classic rules at once: the trapezoidal rule, the midpoint rule and Simpson's 1/3 rule. Type the function, the limits and the number of sub-intervals n, and you get each approximation, the step size h and a table of every sample point with the weight each rule gives it.

It is aimed at calculus and numerical-methods students who need to show the working for a trapezoid or Simpson question, and at engineers and scientists who need the area under a curve that has no tidy antiderivative, such as e^(−x²). Each estimate is compared against a high-precision reference value (Simpson with 4,096 sub-intervals), so you can see how the error shrinks as n grows and why Simpson usually wins.

Simpson's rule needs an even number of sub-intervals; if you enter an odd n, the Simpson column uses n + 1 and says so. Angles inside trig functions are in radians, and limits can be typed as expressions like pi/2.

With the default inputs, the simpson's rule is 0.74682495. Change any value above to recalculate instantly.

How to use the trapezoidal & simpson's rule calculator

  1. 1Type the integrand f(x), for example exp(-x^2).
  2. 2Enter the lower and upper limits; expressions like pi/2 are fine.
  3. 3Choose the number of sub-intervals n (use an even number for Simpson's rule).
  4. 4Compare the trapezoid, midpoint and Simpson approximations with the reference value.
  5. 5Use the table of sample points and weights to write out the working.

Formula and method

Trapezoid: T = (h/2)[f₀ + 2f₁ + … + 2fₙ₋₁ + fₙ]
Midpoint: M = h[f(x½) + f(x₃⁄₂) + … ]
Simpson: S = (h/3)[f₀ + 4f₁ + 2f₂ + 4f₃ + … + 4fₙ₋₁ + fₙ]

All three rules split [a, b] into n equal sub-intervals of width h = (b − a)/n and sample the function at xᵢ = a + i·h. The trapezoidal rule joins neighbouring points with straight lines and adds the trapezoid areas; the midpoint rule uses one rectangle per sub-interval with height taken at its centre; Simpson's 1/3 rule fits a parabola through each pair of sub-intervals, which is why it needs n even and uses the 1-4-2-4-…-4-1 weight pattern.

For a smooth function the trapezoid and midpoint errors shrink like h² (halve h, quarter the error), while Simpson's error shrinks like h⁴, so doubling n cuts it by about 16. Simpson's rule is exact for any polynomial up to degree 3. The reference value is Simpson's rule with 4,096 sub-intervals, accurate to roughly 10 or more digits for well-behaved functions.

h
Step size (b − a)/n
fᵢ
f(xᵢ), the function value at xᵢ = a + i·h
n
Number of sub-intervals (even for Simpson)
x½
Midpoint of a sub-interval

Worked examples

∫₀¹ e^(−x²) dx with n = 10

With h = 0.1 the trapezoidal rule gives 0.746211 and the midpoint rule 0.747131, bracketing the true value 0.746824 (√π/2 · erf 1). Simpson's rule gives 0.746825, already correct to six decimal places with only 11 function evaluations.

∫₀² x² dx with n = 4

Samples at 0, 0.5, 1, 1.5, 2 are 0, 0.25, 1, 2.25, 4. Trapezoid: 0.25 × (0 + 0.5 + 2 + 4.5 + 4) = 2.75. Simpson: (0.5/3) × (0 + 1 + 2 + 9 + 4) = 8/3 ≈ 2.6667, which is exact because Simpson's rule integrates cubics exactly.

∫₀^π sin x dx with n = 6

The exact answer is 2. With six sub-intervals the trapezoid rule underestimates (1.9541) because sine is concave here, the midpoint rule overestimates (2.0230), and Simpson's rule is off by less than 0.001.

Frequently asked questions

Which is more accurate, the trapezoidal rule or Simpson's rule?+

For smooth functions Simpson's rule is far more accurate: its error falls with h⁴ instead of h², so with the same number of points it is usually several digits better. The trapezoidal rule can win only for periodic functions integrated over a full period or for functions with kinks.

Why does Simpson's rule need an even number of intervals?+

Simpson's 1/3 rule fits one parabola through every three consecutive points, which covers two sub-intervals at a time. The sub-intervals must therefore pair up, so n has to be even. This calculator uses n + 1 for Simpson if you enter an odd n.

Does the trapezoidal rule overestimate or underestimate?+

If the function is concave up (f″ > 0) on the interval, the trapezoids lie above the curve and the rule overestimates; if it is concave down it underestimates. The midpoint rule does the opposite, which is why the two often bracket the true value.

What is the error bound for the trapezoidal and Simpson rules?+

For the trapezoid rule |E| ≤ (b − a)³·max|f″| / (12n²); for the midpoint rule it is half that; for Simpson |E| ≤ (b − a)⁵·max|f⁽⁴⁾| / (180n⁴). This tool shows the actual error against a high-precision reference instead.

When should I use numerical integration instead of an antiderivative?+

Use it when the antiderivative has no elementary form (e^(−x²), sin(x)/x, √(1 + x³)), when you only have sampled data rather than a formula, or when you need a quick numeric check of a symbolic answer.

Related tools