Plenty of integrals that show up in real work cannot be solved on paper. The drag on a wing, the energy under an experimental stress-strain curve, the area swept by a measured velocity signal — in each case you do not have a tidy function to integrate, only a set of numbers from a sensor or a simulation. Hand-integration techniques are useless here, because there is no closed-form antiderivative to find.
This is where numerical integration earns its place. It estimates a definite integral directly from sampled values of the function, with no algebra and no antiderivative required. This article explains the two workhorse methods, the trapezoidal rule and Simpson's rule, and shows why one of them can be exact while the other only approximates.
Why this calculation matters
Numerical integration sits quietly inside an enormous amount of engineering and science. Every finite element solver integrates stiffness and mass matrices numerically. Signal processing accumulates power and energy from sampled waveforms. Control systems integrate error over time. Statistics integrates probability densities. Whenever a quantity is the accumulated effect of something that varies, and that something is known only at discrete points, numerical integration is the tool that closes the gap.
It also matters because the methods are not all equal. Some converge slowly and some converge fast, and the difference compounds. A method with a higher order of accuracy reaches a target precision with far fewer sample points, which means less data to collect and less computation to run. Choosing well is not academic — it is the difference between a quick, accurate answer and a slow, noisy one.
The core method
The idea behind every numerical integration rule is the same: replace the unknown true function with a simple shape you can integrate, then add up the pieces.
Divide the interval from a to b into n equal strips of width h:
h = (b - a) / n
Sample the function at the strip boundaries to get values f0, f1, f2, ... fn.
The trapezoidal rule approximates the function over each strip with a straight line, so each strip becomes a trapezoid. Summing the trapezoid areas gives:
integral ~= h * [ (f0 + fn)/2 + f1 + f2 + ... + f(n-1) ]
The end points carry half weight; every interior point carries full weight. Because a straight line cannot follow curvature, the trapezoidal rule has an error of order h^2 — halving the strip width cuts the error by roughly a factor of four.
Simpson's rule does better by fitting a parabola through each pair of strips instead of a straight line. It requires an even number of strips and weights the points in the repeating pattern 1, 4, 2, 4, 2, ..., 4, 1:
integral ~= (h/3) * [ f0 + 4f1 + 2f2 + 4f3 + ... + 4f(n-1) + fn ]
The parabola can follow curvature, so Simpson's rule has an error of order h^4 — halving the strip width cuts the error by about sixteen. The payoff is dramatic: Simpson's rule integrates any cubic or lower-degree polynomial exactly, with no error at all.
A worked example
Estimate the integral of f(x) = x^2 from x = 0 to x = 2. This one has a known answer for comparison: the exact value is 8/3 = 2.667.
Use four strips, so n = 4 and the strip width is h = (2 - 0)/4 = 0.5. Sample the function at the five boundary points:
f(0) = 0
f(0.5) = 0.25
f(1) = 1
f(1.5) = 2.25
f(2) = 4
Trapezoidal rule. Apply the half-weight to the end points and full weight to the interior:
integral ~= h * [ (f0 + f4)/2 + f1 + f2 + f3 ]
integral ~= 0.5 * [ (0 + 4)/2 + 0.25 + 1 + 2.25 ]
integral ~= 0.5 * [ 2 + 3.5 ]
integral ~= 0.5 * 5.5 = 2.75
The trapezoidal estimate is 2.75, against the true 2.667 — about 3 % high. The overshoot makes sense: x^2 is concave up, so straight-line tops sit above the curve and overstate every strip.
Simpson's rule. Use the same five points with the 1, 4, 2, 4, 1 pattern:
integral ~= (h/3) * [ f0 + 4f1 + 2f2 + 4f3 + f4 ]
integral ~= (0.5/3) * [ 0 + 4(0.25) + 2(1) + 4(2.25) + 4 ]
integral ~= 0.1667 * [ 0 + 1 + 2 + 9 + 4 ]
integral ~= 0.1667 * 16 = 2.667
Simpson's rule lands on 2.667 — the exact answer. That is not luck. The integrand x^2 is a quadratic, and Simpson's rule fits parabolas, so it reproduces any quadratic with zero error. Same five sample points, same effort, but a method matched to the curvature of the function gets the answer right while the linear method does not.
Common mistakes
Using an odd number of strips with Simpson's rule. Simpson's rule pairs strips into parabolic spans, so it requires an even count. An odd number leaves a leftover strip and breaks the weighting pattern. Handle the remainder with a separate sub-rule or change n.
Misplacing the weights. The trapezoidal rule halves only the two end points. Simpson's rule alternates 4 and 2 on interior points and uses 1 at the ends. A weight applied to the wrong point quietly corrupts the result without any error message.
Assuming more strips always help. More strips reduce the truncation error, but with noisy or finely sampled data, very small h can amplify measurement noise. There is a practical sweet spot, not an infinite gain.
Trusting Simpson's rule on rough functions. Simpson's rule is exact for smooth polynomials, but a function with kinks, steps, or sharp peaks violates the smooth-parabola assumption. Near a discontinuity, accuracy drops sharply regardless of how small h is.
Forgetting to include both end points. Every closed rule needs f at a and at b. Dropping an end point, or starting the sum at the first interior point, leaves a strip out and biases the integral low.
Try the interactive NovaSolver calculator
Working one rule by hand is instructive once; comparing several at a glance is what builds intuition. The Numerical Integration Methods Comparator on NovaSolver does exactly that — pick an integrand, set the integration bounds and the number of subintervals, and it computes the Trapezoidal, Simpson 1/3, Gauss-Legendre, and Romberg estimates side by side, with each method's relative error and a log-log convergence chart that makes the difference in accuracy order visible at once.
Related calculators
- Gauss Quadrature Calculator — for the method that places sample points optimally and reaches very high accuracy with few evaluations.
- Newton-Raphson Method Calculator — the companion numerical tool for root-finding, with fast quadratic convergence.
- Bisection Method Calculator — a robust, guaranteed-convergence root-finder for when speed matters less than certainty.
You can browse the rest in the numerical methods tools hub.
Closing note
Numerical integration is one of those topics that looks modest and turns out to be everywhere. The core idea is simple: trade an unknown function for a shape you can integrate, then sum. The lesson from the worked example is the part worth carrying away — the trapezoidal rule fits lines and the answer is close; Simpson's rule fits parabolas and, for a quadratic, the answer is exact. Match the method to the smoothness of the function, watch your strip count and your weights, and a column of sample values becomes a number you can trust.
Top comments (0)