Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Approximate an Integral Numerically

When no antiderivative is available, the trapezoidal rule and Simpson's rule estimate a definite integral from a handful of function values, far more accurately than rectangles for the same nn.

Recognize the task

The integrand has no elementary antiderivative (e−x2e^{-x^2}, sin⁡(x2)\sin(x^2), 1+x3\sqrt{1 + x^3}), or only a table of values is given, and the question says "trapezoidal rule", "Simpson's rule" or "estimate with n=4n = 4". Test: you need a number and cannot integrate exactly.
The rules refine the Riemann sum construction: straight tops instead of flat ones, then parabolic tops. The site has no separate lesson on them; this page is where they live.

Two ways to do it

Trapezoidal ruleany n
Tn=Δx2[f(x0)+2f(x1)+2f(x2)+⋯+2f(xn−1)+f(xn)]T_n = \frac{\Delta x}{2}\Big[f(x_0) + 2f(x_1) + 2f(x_2) + \cdots + 2f(x_{n-1}) + f(x_n)\Big]
Joins the sample points with straight lines. Error shrinks like 1n2\frac{1}{n^2}. Exact for linear functions.
Simpson's rulen even, more accurate
Sn=Δx3[f(x0)+4f(x1)+2f(x2)+4f(x3)+⋯+4f(xn−1)+f(xn)]S_n = \frac{\Delta x}{3}\Big[f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \cdots + 4f(x_{n-1}) + f(x_n)\Big]
Fits a parabola through each pair of strips, so nn must be even. Error shrinks like 1n4\frac{1}{n^4}. Exact for cubics.

Steps

StepOn ∫01e−x2 dx\int_0^1 e^{-x^2}\,dx with n=4n = 4
1Compute Δx and the n + 1 points. Δx=b−an\Delta x = \frac{b - a}{n}; the points run from aa to bb inclusive, so there is one more point than strips.Δx=0.25\Delta x = 0.25; x=0, 0.25, 0.5, 0.75, 1x = 0,\ 0.25,\ 0.5,\ 0.75,\ 1
2Evaluate f at every point. Keep four decimals; round only at the end.1, 0.9394, 0.7788, 0.5698, 0.36791,\ 0.9394,\ 0.7788,\ 0.5698,\ 0.3679
3Apply the weights. Trapezoid: 1,2,2,…,2,11, 2, 2, \ldots, 2, 1. Simpson: 1,4,2,4,…,4,11, 4, 2, 4, \ldots, 4, 1 (ends 11, then alternating 4,24, 2, finishing with 44 before the last 11).T4=0.252[1+2(0.9394+0.7788+0.5698)+0.3679]T_4 = \frac{0.25}{2}\big[1 + 2(0.9394 + 0.7788 + 0.5698) + 0.3679\big]
4Multiply by the factor and round sensibly. Δx2\frac{\Delta x}{2} for the trapezoidal rule, Δx3\frac{\Delta x}{3} for Simpson.T4≈0.7430T_4 \approx 0.7430;   S4=0.253[1+4(0.9394)+2(0.7788)+4(0.5698)+0.3679]≈0.7469\;S_4 = \frac{0.25}{3}\big[1 + 4(0.9394) + 2(0.7788) + 4(0.5698) + 0.3679\big] \approx 0.7469

Worked examples

Example 1 · the Gaussian bump

both rules
∫01e−x2 dx\int_0^1 e^{-x^2}\,dx, n=4n = 4
no elementary antiderivative
T4≈0.7430T_4 \approx 0.7430
weights 1,2,2,2,11, 2, 2, 2, 1
S4≈0.7469S_4 \approx 0.7469
weights 1,4,2,4,11, 4, 2, 4, 1; true value 0.74680.7468

Example 2 · distance from a speed table

trapezoid on data
v=0, 8, 14, 18, 20v = 0,\ 8,\ 14,\ 18,\ 20 m/s every 1010 s
Δx=10\Delta x = 10, n=4n = 4
T4=102[0+2(8+14+18)+20]T_4 = \frac{10}{2}\big[0 + 2(8 + 14 + 18) + 20\big]
distance =∫v dt= \int v\,dt
=5⋅100=500= 5 \cdot 100 = 500 m

Example 3 · Simpson with only two strips

n = 2
∫0πsin⁡x dx\int_0^\pi \sin x\,dx, n=2n = 2
Δx=π2\Delta x = \frac{\pi}{2}; values 0,1,00, 1, 0
S2=π/23[0+4(1)+0]=2π3≈2.094S_2 = \frac{\pi/2}{3}\big[0 + 4(1) + 0\big] = \frac{2\pi}{3} \approx 2.094
exact value 22; a parabola is already close to the arch

See it happen

The trapezoidal rule joins the sample points with straight lines; Simpson's rule fits a parabola through each pair of strips. A parabola follows a smooth curve far better than a line does, which is why Simpson's error shrinks like 1n4\frac{1}{n^4} instead of 1n2\frac{1}{n^2}.

Common mistakes

Odd n with Simpson

✗ S3S_3
✓ nn must be even; the rule works on pairs of strips

Wrong weight pattern

✗ 1,2,4,2,11, 2, 4, 2, 1
✓ 1,4,2,4,11, 4, 2, 4, 1: ends 11, then 44 first

Dropping the ½ or ⅓

✗ Tn=Δx […]T_n = \Delta x\,[\ldots]
✓ Tn=Δx2[…]T_n = \frac{\Delta x}{2}[\ldots], Sn=Δx3[…]S_n = \frac{\Delta x}{3}[\ldots]

Rounding too early

✗ each value rounded to one decimal
✓ carry four decimals, round at the end