Numerical Integration Calculator (Simpson's, Trapezoidal, Midpoint)
Approximate definite integrals using Simpson's Rule, Trapezoidal Rule, and Midpoint Rule.
Compare accuracy between methods and understand numerical quadrature error bounds.
What Is Numerical Integration? Numerical integration (quadrature) approximates the value of a definite integral ∫[a,b] f(x) dx when an exact analytical solution is difficult or impossible to find. The function is evaluated at a finite number of points, and the area under the curve is estimated geometrically. These methods are essential in science and engineering — most real-world integrals cannot be solved by hand.
Trapezoidal Rule The simplest method: approximate the area under the curve using trapezoids. With n equal subintervals of width h = (b−a)/n: ∫[a,b] f(x) dx ≈ h × [f(x₀)/2 + f(x₁) + f(x₂) + … + f(x_{n−1}) + f(x_n)/2] Error: O(h²) — halving the step size quarters the error. For a straight line, the trapezoidal rule is exact. For curved functions, it underestimates concave-up regions.
Midpoint Rule Uses the function value at the midpoint of each subinterval: ∫[a,b] f(x) dx ≈ h × [f(x₀+h/2) + f(x₁+h/2) + … + f(x_{n−1}+h/2)] The midpoint rule is actually more accurate than the trapezoidal rule for smooth functions — it has the same O(h²) order but a smaller error constant.
Simpson’s Rule Simpson’s Rule fits a parabola through each triple of points (every two subintervals): ∫[a,b] f(x) dx ≈ (h/3) × [f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + … + 4f(x_{n−1}) + f(x_n)] n must be even. Error: O(h⁴) — much more accurate than trapezoidal. Simpson’s 1/3 rule is exact for polynomials up to degree 3. Named after Thomas Simpson, a British mathematician who published it in 1743 in England.
Gaussian Quadrature Gauss-Legendre quadrature uses optimally placed (non-uniform) sample points. It can exactly integrate polynomials of degree 2n−1 using only n function evaluations. Gauss-Legendre is the gold standard for smooth functions: it is exponentially more accurate than equal-spacing methods. Used internally in most scientific computing libraries (NumPy, MATLAB, Mathematica).
Error Bounds Trapezoidal error ≤ (b−a)³ × max|f’’(x)| / (12n²) Simpson’s error ≤ (b−a)⁵ × max|f’’’’(x)| / (180n⁴) This means increasing n from 10 to 100 reduces trapezoidal error by 100× but reduces Simpson’s error by 10,000×. For oscillatory or discontinuous functions, special methods (adaptive quadrature, Romberg integration) are more appropriate.
Applications Physics: computing electric potential from charge distributions, orbital mechanics. Statistics: computing probabilities from continuous distributions (Gaussian, chi-squared). Engineering: signal processing — the Fourier transform is a form of numerical integration. Finance: pricing exotic options via Monte Carlo integration. Medicine: computing AUC (Area Under the Curve) for pharmacokinetics from blood concentration data.