{
  "id": "trapezoidal-rule",
  "title": "Trapezoidal Rule",
  "lang": "en",
  "source_lang": "en",
  "summary": "The trapezoidal rule approximates a definite integral by integrating straight-line segments between sampled function values, producing a weighted sum of trapezoidal areas.",
  "category": "mathematics",
  "subcategory": "applied",
  "type": "concept",
  "aliases": [
    "Trapezium rule",
    "Trapezoid rule",
    "Trapezoidal quadrature"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/trapezoidal-rule/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/trapezoidal-rule/",
      "json": "https://aiwiki.page/zh/trapezoidal-rule.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The trapezoidal rule is a method in numerical analysis for approximating a definite integral using values of a function at selected points. It replaces the function between consecutive points by a straight line and integrates the resulting piecewise-linear approximation. For sufficiently smooth functions on a fixed interval, the composite rule has an error proportional to the square of the spacing between equally spaced points. Its simplicity, compatibility with irregularly spaced data, and unusually rapid convergence for smooth periodic functions make it a widely used integration method."
    },
    {
      "heading": "Basic formula and geometric interpretation",
      "text": "For a function \\(f\\) on an interval \\([a,b]\\), the single-panel trapezoidal rule is\n\n\\[\\int_a^b f(x)\\,dx \\approx T=\\frac{b-a}{2}\\bigl[f(a)+f(b)\\bigr].\\]\n\nThe expression on the right is the integral of the straight line joining \\((a,f(a))\\) and \\((b,f(b))\\). When both endpoint values are nonnegative, it is the area of a trapezoid with parallel vertical sides of lengths \\(f(a)\\) and \\(f(b)\\). When values are negative or the line crosses the horizontal axis, the formula still gives the corresponding signed integral.\n\nEquivalently, the rule multiplies the interval width by the arithmetic mean of the two endpoint values. It is exact for every polynomial of degree at most one, but not for all quadratic polynomials; its degree of exactness is therefore one.\n\nThe rule can also be viewed as integrating a linear interpolant. In the classification of Newton–Cotes formulas, it is the simplest closed rule that uses both endpoints of the integration interval."
    },
    {
      "heading": "Composite trapezoidal rule",
      "text": "A single straight segment may approximate a curved function poorly. The composite rule divides the interval into smaller panels and applies the basic formula to each one.\n\nFor a partition\n\n\\[a=x_0<x_1<\\cdots<x_n=b, \\qquad h_i=x_{i+1}-x_i,\\]\n\nthe approximation is\n\n\\[T_n= \\sum_{i=0}^{n-1} \\frac{h_i}{2} \\bigl[f(x_i)+f(x_{i+1})\\bigr].\\]\n\nThis formula works with unequally spaced points. It is particularly useful when measurements have already been collected at fixed, irregular locations.\n\nFor equally spaced points, let\n\n\\[h=\\frac{b-a}{n}, \\qquad x_i=a+ih.\\]\n\nThen\n\n\\[T_n= h\\left[ \\frac{f(a)}{2} +\\sum_{i=1}^{n-1}f(x_i) +\\frac{f(b)}{2} \\right].\\]\n\nEach interior function value contributes to two neighboring panels and receives total weight \\(h\\); each endpoint receives weight \\(h/2\\).\n\nFor a continuous function, these approximations converge to the integral as the largest panel width tends to zero. More generally, the same convergence holds for bounded Riemann-integrable functions. This follows because the trapezoidal approximation is the average of the left- and right-endpoint Riemann sums on the same partition."
    },
    {
      "heading": "Error and convergence",
      "text": "Single-panel error\n\nSuppose \\(f\\) has a continuous second derivative on \\([a,b]\\). There is a point \\(\\xi\\in(a,b)\\) such that\n\n\\[\\int_a^b f(x)\\,dx-T = -\\frac{(b-a)^3}{12}f''(\\xi).\\]\n\nAn exact integral representation of the error is\n\n\\[T-\\int_a^b f(x)\\,dx = \\frac12 \\int_a^b (x-a)(b-x)f''(x)\\,dx.\\]\n\nThis representation explains the sign of the error. For a convex function, the straight chord lies above the graph, so the trapezoidal rule overestimates the integral. For a concave function, it underestimates it.\n\nComposite error\n\nFor \\(n\\) equal panels and a continuous second derivative,\n\n\\[\\int_a^b f(x)\\,dx-T_n = -\\frac{b-a}{12}h^2 f''(\\xi)\\]\n\nfor some \\(\\xi\\in(a,b)\\). Consequently, if\n\n\\[M_2=\\max_{x\\in[a,b]}|f''(x)|,\\]\n\nthen\n\n\\[\\left|\\int_a^b f(x)\\,dx-T_n\\right| \\le \\frac{b-a}{12}h^2M_2 = \\frac{(b-a)^3}{12n^2}M_2.\\]\n\nThe composite rule is thus second-order accurate, commonly written as an error of \\(O(h^2)\\) using big-O notation. Once this asymptotic behavior applies, halving the spacing typically reduces the error by approximately a factor of four.\n\nFor unequal panel widths, a corresponding bound is\n\n\\[\\left|\\int_a^b f(x)\\,dx-T_n\\right| \\le \\frac{M_2}{12} \\sum_{i=0}^{n-1}h_i^3.\\]\n\nThese second-derivative bounds do not apply directly to functions with singularities, discontinuities, or insufficient smoothness. Such functions may still be integrable, but their convergence rates require separate analysis.\n\nExample\n\nFor \\(f(x)=x^2\\) on \\([0,1]\\), the exact integral is \\(1/3\\). With four equal panels,\n\n\\[T_4= \\frac14 \\left[ \\frac{0}{2} +\\frac1{16} +\\frac14 +\\frac9{16} +\\frac12 \\right] = \\frac{11}{32}.\\]\n\nThe error is\n\n\\[T_4-\\frac13=\\frac1{96}.\\]\n\nBecause \\(f''(x)=2\\) is constant, the composite error formula gives this error exactly."
    },
    {
      "heading": "Error expansions and extrapolation",
      "text": "For sufficiently smooth functions, the Euler–Maclaurin formula gives a more detailed description of the error:\n\n\\[T_n-\\int_a^b f(x)\\,dx = \\frac{h^2}{12}\\bigl[f'(b)-f'(a)\\bigr] -\\frac{h^4}{720}\\bigl[f'''(b)-f'''(a)\\bigr] +\\cdots.\\]\n\nThis is an asymptotic expansion under appropriate smoothness assumptions; it need not be a convergent infinite series. It shows that endpoint derivative differences determine the leading error terms. In particular, if \\(f'(a)=f'(b)\\), the usual \\(h^2\\) contribution vanishes.\n\nThe expansion also motivates Richardson extrapolation. If \\(T_n\\) and \\(T_{2n}\\) use spacings \\(h\\) and \\(h/2\\), respectively, then\n\n\\[R=\\frac{4T_{2n}-T_n}{3}\\]\n\ncancels the leading \\(h^2\\) error. Under sufficient smoothness, \\(R\\) has error \\(O(h^4)\\). This combination is equivalent to the composite Simpson’s rule on the finer grid.\n\nRepeated extrapolation of successively refined trapezoidal approximations produces Romberg integration."
    },
    {
      "heading": "Rapid convergence for periodic functions",
      "text": "The trapezoidal rule can converge much faster than second order when integrating a smooth periodic function over a complete period.\n\nIf \\(f\\) has period \\(L\\), then its endpoint values agree, and the composite formula becomes\n\n\\[T_n=\\frac{L}{n} \\sum_{j=0}^{n-1} f\\left(a+\\frac{jL}{n}\\right).\\]\n\nThere is no need to evaluate the repeated endpoint separately. If all derivatives also match at the endpoints, all corresponding endpoint terms in the Euler–Maclaurin expansion vanish.\n\nFor an infinitely differentiable periodic function, the error decreases faster than every fixed inverse power of \\(n\\). If the function extends analytically to a complex strip around the real axis, the convergence is exponential, with its rate governed by the width of an available strip of analyticity.\n\nA Fourier-series interpretation explains this behavior. Equally spaced sampling integrates most Fourier modes exactly, while modes whose frequencies are nonzero multiples of \\(n\\) contribute through aliasing. For a smooth periodic function, these high-frequency coefficients are small; for a suitably analytic function, they decay exponentially.\n\nPeriodicity alone does not guarantee rapid convergence. Discontinuities or mismatched derivatives at the boundaries can restore slower algebraic convergence."
    },
    {
      "heading": "Implementation and adaptive refinement",
      "text": "The composite rule requires only a weighted sum, making its implementation straightforward. It also permits efficient refinement: when the number of equal panels is doubled, only the new midpoint values need to be evaluated. Specifically,\n\n\\[T_{2n} = \\frac12T_n + \\frac h2 \\sum_{i=0}^{n-1} f\\left(a+\\left(i+\\frac12\\right)h\\right),\\]\n\nwhere \\(h=(b-a)/n\\) is the old spacing.\n\nWhen a leading \\(h^2\\) error model is valid,\n\n\\[\\left|\\int_a^b f(x)\\,dx-T_{2n}\\right| \\approx \\frac{|T_{2n}-T_n|}{3}.\\]\n\nThis estimate can guide adaptive quadrature, in which intervals are refined selectively rather than uniformly. It is an asymptotic estimate, not a guaranteed bound: two grids can both miss a narrow peak or sample an oscillatory function misleadingly.\n\nIn floating-point arithmetic, reducing the spacing indefinitely does not necessarily improve the answer. Rounding, cancellation, inaccurate function evaluations, and uncertainty in sampled data can eventually dominate the discretization error. Pairwise or compensated summation can reduce accumulation error in long weighted sums."
    },
    {
      "heading": "Applications and limitations",
      "text": "The trapezoidal rule is especially useful for:\n\n- Tabulated and experimental data: it works directly with observed values, including irregularly spaced observations.\n- Cumulative integration: successive panel contributions provide approximations to \\(\\int_a^{x_k}f(x)\\,dx\\) at every data point.\n- Smooth periodic problems: it can achieve very high accuracy with a simple uniform grid.\n- Repeated refinement: nested grids allow existing evaluations to be reused.\n- Multidimensional integration: tensor-product versions apply the rule along each coordinate, although their cost grows rapidly with dimension.\n\nFor noisy data, the method integrates the piecewise-linear representation of the observations; it does not remove measurement error or reconstruct unresolved behavior between samples.\n\nFor nonperiodic smooth functions whose values can be evaluated freely, higher-order quadrature may reach a given accuracy with fewer evaluations. Endpoint singularities, discontinuities, and strong oscillations can require interval splitting, variable transformations, or specialized integration methods. In high dimensions, tensor-product trapezoidal rules encounter the curse of dimensionality."
    },
    {
      "heading": "Relation to the trapezoidal method for differential equations",
      "text": "A related use of the same quadrature formula produces the trapezoidal method for solving an ordinary differential equation\n\n\\[y'(t)=F(t,y(t)).\\]\n\nIntegrating over one time step and applying the trapezoidal rule gives\n\n\\[y_{k+1} = y_k+ \\frac h2 \\left[ F(t_k,y_k)+F(t_{k+1},y_{k+1}) \\right].\\]\n\nUnlike quadrature of a known function, this formula generally requires solving an equation for the unknown \\(y_{k+1}\\). It is therefore an implicit method.\n\nFor the test equation \\(y'=\\lambda y\\), its amplification factor is\n\n\\[R(z)=\\frac{1+z/2}{1-z/2}, \\qquad z=h\\lambda.\\]\n\nIt satisfies \\(|R(z)|\\le1\\) whenever \\(\\operatorname{Re}z\\le0\\), making it A-stable in the terminology of numerical stability. However, \\(R(z)\\) approaches \\(-1\\), rather than zero, as \\(z\\) tends to negative infinity. It therefore does not strongly damp very stiff decaying modes and is not L-stable."
    }
  ],
  "links": [
    "numerical-analysis",
    "integral",
    "mathematical-function",
    "polynomial",
    "interpolation",
    "continuous-function",
    "riemann-integral",
    "riemann-sum",
    "derivative",
    "convex-function",
    "big-o-notation",
    "asymptotic-expansion",
    "fourier-series",
    "analytic-function",
    "floating-point-arithmetic",
    "curse-of-dimensionality",
    "ordinary-differential-equation",
    "numerical-stability"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}