Trapezoidal rule
The trapezoidal rule, also known as the trapezoid rule or trapezium rule, is a fundamental method in numerical analysis for approximating the definite integral of a continuous function over an interval by dividing the region into trapezoidal areas.[1] Geometrically, it estimates the area under the curve by fitting straight lines between consecutive points on the function and summing the areas of the resulting trapezoids, providing an exact result for linear functions (polynomials of degree at most one).[2][3]
For a single subinterval from a to b, the basic formula is \int_a^b f(x) \, dx \approx \frac{b-a}{2} [f(a) + f(b)], which represents the area of the trapezoid formed by the points (a, f(a)), (a, 0), (b, 0), and (b, f(b)).[4] In the composite version, the interval [a, b] is partitioned into n equal subintervals of width h = (b - a)/n, yielding the approximation \int_a^b f(x) \, dx \approx \frac{h}{2} \left[ f(a) + 2 \sum_{i=1}^{n-1} f(a + i h) + f(b) \right].[5]
The method originates from the Newton-Cotes formulas, where the integrand is approximated by a first-degree polynomial, and it serves as an improvement over simple rectangular (Riemann) sums by averaging the left and right endpoint approximations.[1] The error for the composite trapezoidal rule is E_T = -\frac{(b-a) h^2}{12} f''(\xi) for some \xi \in [a, b], assuming f'' is continuous, indicating second-order accuracy that improves with more subintervals.[5] This error term highlights its suitability for smooth functions, though it may underperform for highly oscillatory or concave functions compared to higher-order methods like Simpson's rule.[6]
Fundamentals
Definition and Geometric Basis
The trapezoidal rule is a numerical integration method that approximates the definite integral of a function f(x) over an interval [a, b] by the area of a trapezoid. Specifically, for a single interval, it estimates \int_a^b f(x) \, dx \approx \frac{b-a}{2} \left[ f(a) + f(b) \right].[7] This formula arises from treating the integrand values at the endpoints as the parallel sides (or bases) of a trapezoid, with the interval length b - a serving as the height (or distance between the parallel sides).[8]
Geometrically, the definite integral \int_a^b f(x) \, dx represents the exact area under the curve y = f(x) from x = a to x = b, assuming f(x) \geq 0 for simplicity. The trapezoidal rule approximates this area by inscribing a trapezoid within the region bounded by the x-axis, the vertical lines at x = a and x = b, and the secant line connecting the points (a, f(a)) and (b, f(b)). The two parallel sides of the trapezoid are the vertical lines at the endpoints (of lengths f(a) and f(b)), while the non-parallel sides are the segment on the x-axis of length b - a and the secant line segment of length \sqrt{(b-a)^2 + (f(b) - f(a))^2}; however, the area computation simplifies to the average of the endpoint heights times the base width, yielding the formula above. This approach provides a linear approximation to the curve, which is more accurate than a rectangular approximation for smooth functions.[8]
For broader application, the trapezoidal rule extends to the composite version by dividing the interval [a, b] into multiple subintervals and summing the trapezoidal areas over each, improving accuracy without altering the underlying geometric principle.[8]
Motivation and Prerequisites
Numerical integration methods, such as the trapezoidal rule, become indispensable when determining an exact antiderivative of a function is challenging or outright impossible, thereby requiring reliable approximations to evaluate definite integrals./05%3A_Integration/5.05%3A_Numerical_Integration) This necessity arises frequently in applied mathematics and sciences, where functions may lack elementary antiderivatives, yet precise area computations under curves are essential for modeling physical phenomena or solving engineering problems.
To grasp the trapezoidal rule, one must first be acquainted with the fundamentals of Riemann sums and the definition of a definite integral as the limit of such sums, which partition the interval into subintervals and approximate areas with simple shapes like rectangles.[8] Moreover, the method presupposes that the integrand f(x) is continuous on the closed interval [a, b], ensuring the existence of the integral and the validity of the approximations.[8]
The trapezoidal rule stands out due to its inherent simplicity and ease of implementation, requiring only function evaluations at interval endpoints to form basic geometric approximations.[9] This accessibility makes it especially suitable for smooth functions, where it provides efficient and reasonably accurate estimates without demanding advanced computational tools.[10] Unlike exact integration via antiderivatives, which may prove intractable, the rule offers a practical motivational bridge for numerical approximation, geometrically interpreting the area as a series of fitted trapezoids.[11][8]
Historical Development
Early Origins
The earliest documented use of a method analogous to the trapezoidal rule appears in ancient Babylonian astronomy, where tablets from approximately 350 to 50 BCE describe calculations of Jupiter's position along the ecliptic by approximating the area under a graph of velocity versus time using trapezoidal figures.[12] This approach effectively computed the planet's displacement as the integral of its velocity, demonstrating an intuitive grasp of geometric area summation for predictive purposes without algebraic notation. Such techniques highlight the trapezoidal approximation's role in early scientific computation, particularly for celestial tracking.
In the classical era, precursors to the trapezoidal rule emerged through geometric methods for area estimation. Archimedes (c. 287–212 BCE) applied the method of exhaustion to approximate areas bounded by curves, such as parabolas and circles, by successively refining polygons that inscribed or circumscribed the region, providing a rigorous limit-based foundation for numerical quadrature.[13] This iterative polygon approximation shares conceptual similarities with trapezoidal summation as a natural extension of basic area calculations using linear segments. In the 17th century, Bonaventura Cavalieri (1598–1647) advanced area approximations via his method of indivisibles, summing infinitely thin planar slices to compute areas under curves, which parallels trapezoidal integration when slices are treated as linear trapezoids.
The trapezoidal rule gained prominence in the late 17th and 18th centuries amid the development of calculus, with Isaac Newton employing numerical summation techniques, including trapezoidal approximations, in his manuscript Of Quadrature by Ordinates around 1695 for evaluating definite integrals. By the early 18th century, these ideas were formalized in quadrature tables within calculus texts, where trapezoidal sums facilitated practical computations of integrals for astronomical orbits and surveying measurements. Roger Cotes further systematized the approach in his 1722 posthumous work Harmonia mensurarum, presenting the general Newton-Cotes formulas of which the trapezoidal rule is the linear (n=1) case, enabling efficient table-based approximations without contemporary error bounds. Early applications extended to astronomy for integrating planetary velocities and to land surveying for estimating irregular plot areas by chaining trapezoids, reflecting its utility in pre-digital scientific practice.
In the early 20th century, the trapezoidal rule gained formal recognition within the burgeoning discipline of numerical analysis, as evidenced in E. T. Whittaker and G. N. Watson's seminal text A Course of Modern Analysis (first published in 1902, with the fourth edition appearing in 1927), which systematically presented it alongside other quadrature methods for approximating definite integrals. This integration reflected the rule's evolution from geometric heuristics into a precise tool for computational mathematics, emphasizing its simplicity and utility for practical calculations.
Following World War II, the trapezoidal rule became a cornerstone of computational mathematics amid the rise of electronic computers, where its straightforward implementation suited early programming efforts, such as those for ballistic trajectory integrations on the ENIAC. By the mid-1950s, it was firmly established as a standard technique in numerical analysis textbooks; for instance, F. B. Hildebrand's Introduction to Numerical Analysis (1956) detailed the composite form of the rule, highlighting its error characteristics and role in broader quadrature strategies.
In contemporary formulations, the trapezoidal rule has been refined for enhanced efficiency, particularly in adaptive quadrature schemes that dynamically adjust subinterval sizes to meet tolerance requirements, as implemented in modern software libraries like SciPy's integrate.trapz and Romberg integration routines. A notable theoretical advancement is the exponentially convergent variant for analytic functions over periodic intervals or the real line, which achieves geometric convergence rates superior to polynomial methods, as analyzed in detail by Trefethen and Weideman (2014).[14] These developments underscore the rule's enduring relevance in high-performance computing and scientific simulations as of the 2020s.
The uniform grid implementation of the trapezoidal rule approximates the definite integral \int_a^b f(x) \, dx by partitioning the interval [a, b] into n equal subintervals, each of width h = (b - a)/n. The grid points are defined as x_k = a + k h for k = 0, 1, \dots, n, forming an equally spaced mesh that enables straightforward summation of local approximations.[15][16]
The composite formula arises by applying the basic trapezoidal rule to each subinterval and summing the results, yielding
\int_a^b f(x) \, dx \approx \frac{h}{2} \left( f(a) + 2 \sum_{k=1}^{n-1} f(a + k h) + f(b) \right).
This expression weights the endpoint values f(a) and f(b) by $1/2 and the interior points by $1, scaled by the subinterval width h.[15][17]
To compute the approximation iteratively, evaluate f at the grid points and accumulate the weighted sum as follows (in pseudocode):
function composite_trapezoidal(a, b, n, f):
h = (b - a) / n
total = f(a) + f(b)
for k = 1 to n-1:
total += 2 * f(a + k * h)
return (h / 2) * total
function composite_trapezoidal(a, b, n, f):
h = (b - a) / n
total = f(a) + f(b)
for k = 1 to n-1:
total += 2 * f(a + k * h)
return (h / 2) * total
This loop-based approach is simple and suitable for small n, requiring O(n) evaluations of f.[18][19]
For large n, a vectorized form enhances efficiency by leveraging array operations on the vector of function values \mathbf{y} = [f(x_0), f(x_1), \dots, f(x_n)], computed as
\frac{h}{2} \left( y_0 + 2 \sum_{k=1}^{n-1} y_k + y_n \right) = h \left( \frac{y_0 + y_n}{2} + \sum_{k=1}^{n-1} y_k \right).
This avoids explicit loops, allowing optimized library functions (e.g., in NumPy or MATLAB) to perform the summation in a single pass, which is particularly beneficial for high-dimensional or parallel computations.[20][21]
The non-uniform grid implementation of the trapezoidal rule adapts the composite formulation to handle partitions of the integration interval [a, b] where subinterval widths differ. The interval is divided into n subintervals defined by strictly increasing points x_0 = a < x_1 < \cdots < x_n = b, with each subinterval width given by h_i = x_i - x_{i-1} for i = 1, \dots, n. This setup accommodates irregular spacing, contrasting with the uniform grid case where all h_i are equal.
The approximation to \int_a^b f(x) \, dx is obtained by applying the single trapezoid rule to each subinterval and summing the results:
\sum_{i=1}^n \frac{h_i}{2} \left( f(x_{i-1}) + f(x_i) \right).
$$/7:_Integration/7.06:_Integrating_Functions_Given_as_Discrete_Data_Points)
This generalized composite rule is employed when the function's behavior varies significantly across the domain, such as regions of rapid change requiring finer resolution, or when integrating discrete data from non-uniform sampling, like [sensor](/page/Sensor) measurements or observational datasets. By allowing variable $h_i$, it supports adaptive strategies that allocate more points where accuracy is critical, enhancing efficiency over fixed uniform grids.[](https://www.researchgate.net/publication/317339672_Numerical_Integration_Schemes_for_Unequal_Data_Spacing)
Computationally, the method is straightforward and implemented via a simple loop that computes each $h_i$, evaluates the function at the endpoints if needed, and accumulates the contributions without relying on equal spacing. In programming environments, this involves arrays for the $x_i$ and $f(x_i)$ values, making it versatile for one-dimensional [integration](/page/Integration) in scientific [computing](/page/Computing) libraries. The approach scales linearly with n and avoids [interpolation](/page/Interpolation) overhead for given irregular points./7:_Integration/7.02:_Trapezoidal_Rule_of_Integration)
## Error Analysis
### Derivation of the Error Bound
The derivation of the error bound for the trapezoidal rule begins with the single-interval case, assuming the function $f$ is twice continuously differentiable on the closed [interval](/page/Interval) $[a, b]$, denoted $f \in C^2[a, b]$. Let $h = b - a$. The trapezoidal rule approximates $\int_a^b f(x) \, dx \approx \frac{h}{2} \left( f(a) + f(b) \right)$. To find the error $E = \int_a^b f(x) \, dx - \frac{h}{2} \left( f(a) + f(b) \right)$, consider the linear interpolating [polynomial](/page/Polynomial) $P_1(x)$ that matches $f$ at $a$ and $b$:
P_1(x) = f(a) + \frac{f(b) - f(a)}{h} (x - a).
The interpolation error at any $x \in [a, b]$ is given by
f(x) - P_1(x) = \frac{(x - a)(x - b)}{2} f''(\xi_x),
for some $\xi_x \in (a, b)$, assuming $f''$ exists. Integrating both sides over $[a, b]$ yields the exact integral error:
E = \int_a^b \left[ f(x) - P_1(x) \right] dx = \int_a^b \frac{(x - a)(x - b)}{2} f''(\xi_x) , dx.
Since $f''$ is continuous on the compact interval $[a, b]$, it is bounded and uniformly continuous. By the mean value theorem for integrals, there exists some $\xi \in (a, b)$ such that
\int_a^b f''(\xi_x) , dx = f''(\xi) \cdot h,
leading to
E = \frac{f''(\xi)}{2} \int_a^b (x - a)(x - b) , dx.
To evaluate the integral, substitute $u = x - a$, so $dx = du$ and the limits change from 0 to $h$:
\int_0^h u (u - h) , du = \int_0^h (u^2 - h u) , du = \left[ \frac{u^3}{3} - \frac{h u^2}{2} \right]_0^h = \frac{h^3}{3} - \frac{h \cdot h^2}{2} = \frac{h^3}{3} - \frac{h^3}{2} = -\frac{h^3}{6}.
Thus,
E = \frac{f''(\xi)}{2} \left( -\frac{h^3}{6} \right) = -\frac{h^3}{12} f''(\xi),
for some $\xi \in (a, b)$. This establishes the error bound for a single interval, with $|E| \leq \frac{h^3}{12} \max_{x \in [a, b]} |f''(x)|$.[](http://homepage.math.uiowa.edu/~atkinson/ftp/ENA_Materials/Overheads/sec_5-2.pdf)[](https://mathweb.ucsd.edu/~ebender/20B/77_Trap.pdf)
For the composite trapezoidal rule on a uniform grid, divide $[a, b]$ into $n$ subintervals, each of width $h = (b - a)/n$, with partition points $x_i = a + i h$ for $i = 0, 1, \dots, n$. The composite approximation is
\int_a^b f(x) , dx \approx h \left( \frac{f(a) + f(b)}{2} + \sum_{i=1}^{n-1} f(x_i) \right).
The total error is the sum of the errors over each subinterval $[x_{i-1}, x_i]$:
E_{\text{total}} = \sum_{i=1}^n E_i = \sum_{i=1}^n \left( -\frac{h^3}{12} f''(\xi_i) \right) = -\frac{h^3}{12} \sum_{i=1}^n f''(\xi_i),
for $\xi_i \in (x_{i-1}, x_i)$. Since $f''$ is continuous on $[a, b]$, by the intermediate value theorem for continuous functions, there exists some $\xi \in (a, b)$ such that
\frac{1}{n} \sum_{i=1}^n f''(\xi_i) = f''(\xi).
Thus,
E_{\text{total}} = -\frac{h^3}{12} \cdot n \cdot f''(\xi) = -\frac{(b - a) h^2}{12} f''(\xi),
demonstrating $O(h^2)$ convergence (or $O(1/n^2)$) as $n \to \infty$. The bound is $|E_{\text{total}}| \leq \frac{(b - a) h^2}{12} \max_{x \in [a, b]} |f''(x)|$.[](http://homepage.math.uiowa.edu/~atkinson/ftp/ENA_Materials/Overheads/sec_5-2.pdf)[](https://mathweb.ucsd.edu/~ebender/20B/77_Trap.pdf)
### Behavior for Specific Function Classes
The trapezoidal rule exhibits particularly favorable behavior for periodic analytic functions, where it achieves [exponential](/page/Exponential) (geometric) convergence rates, significantly outperforming the standard O(1/n²) error estimate derived from the Euler-Maclaurin formula. This superior accuracy arises because the endpoint values match exactly due to periodicity, causing higher-order correction terms in the error expansion to vanish, effectively leveraging the function's [Fourier series](/page/Fourier_series) representation for rapid decay of [aliasing](/page/Aliasing) errors. For instance, when integrating functions like [cos](/page/Cos)(2πkx) over [0,1] for [integer](/page/Integer) k, the rule yields exact results, leading to overall [exponential](/page/Exponential) error reduction as the number of points increases.[](https://epubs.siam.org/doi/10.1137/130932132)
In contrast, the rule performs worse for functions with sharp peaks or near singularities, where local variations in the second derivative amplify the [error](/page/Error) contributions. Gaussian peaks, often used to model such [behavior](/page/Behavior), illustrate this: although smooth globally, narrow Gaussians require denser sampling to control [errors](/page/Error), with approximately 0.62 points per standard deviation needed for 0.1% accuracy, highlighting deviations from the expected [quadratic](/page/Quadratic) [convergence](/page/Convergence) due to the peak's rapid [curvature](/page/Curvature) changes. Qualitative [error](/page/Error) comparisons show that halving the step size near the [peak](/page/Peak) reduces the [error](/page/Error) by less than a factor of four, underscoring the method's [sensitivity](/page/Sensitivity) to localized [sharpness](/page/Sharpness).[](http://www.multichrom.ru/Docs/2018ChILS-CompiIntRules.pdf)
For rough functions lacking sufficient [smoothness](/page/Smoothness), such as those continuous but with discontinuous first [derivatives](/page/Hartshorn), the trapezoidal rule's [error](/page/Error) bound breaks down, resulting in only linear O(1/n) [convergence](/page/Convergence) instead of [quadratic](/page/Quadratic). A classic example is f(x) = |x| integrated over [-1,1], where the [kink](/page/Kink) at x=0 prevents the second [derivative](/page/Derivative) from being bounded, causing the [error](/page/Error) to scale linearly with the step size h rather than h². [Error](/page/Error) plots for this case reveal a steady but slower decay, with the absolute [error](/page/Error) halving upon doubling the number of subintervals, confirming the reduced [order](/page/Order) for non-smooth integrands.[](https://math.mit.edu/~stevenj/trap-iap-2011.pdf)
## Applications and Comparisons
### Practical Applications
The trapezoidal rule finds widespread use in [engineering](/page/Engineering) and physics for approximating [integrals](/page/Integral) that arise in practical computations, such as estimating areas under curves derived from experimental [data](/page/Data) or physical models. In [signal processing](/page/Signal_processing), it is employed to integrate continuous-time signals approximated from discrete samples, providing a simple method for calculating [energy](/page/Energy) or [power](/page/Power) spectral densities in audio and vibration analysis.[](https://www.dsprelated.com/freebooks/pasp/Trapezoidal_Rule.html) For [trajectory](/page/Trajectory) calculations, the rule facilitates the determination of [displacement](/page/Displacement) from velocity-time [data](/page/Data) in [mechanics](/page/Mechanics), where it approximates the integral of velocity over time to yield [position](/page/Position) with sufficient accuracy for preliminary simulations.[](https://www.geeksforgeeks.org/maths/trapezoidal-rule/) Additionally, in solving ordinary differential equations (ODEs), the implicit trapezoidal method serves as a second-order accurate [integrator](/page/Integrator), balancing stability and efficiency for stiff systems in dynamic simulations like [chemical kinetics](/page/Chemical_kinetics) or electrical circuits.[](https://www.cs.cornell.edu/~bindel/class/cs3220-s12/notes/lec25.pdf)
In computational software, the trapezoidal rule is implemented as a core function for [numerical integration](/page/Numerical_integration), enabling [rapid prototyping](/page/Rapid_prototyping) and analysis. MATLAB's `trapz` function computes the [integral](/page/Integral) using the composite trapezoidal rule over vectors or matrices, supporting both uniform and non-uniform spacing for multidimensional [data integration](/page/Data_integration) in [engineering](/page/Engineering) workflows.[](https://www.mathworks.com/help/matlab/ref/trapz.html) Similarly, Python's [NumPy](/page/NumPy) library provides `numpy.trapezoid` (with the deprecated alias `numpy.trapz` as of NumPy 2.0 in 2024), which integrates array-like data along specified axes using the trapezoidal approximation, making it a standard tool for scientific computing in data-driven physics applications.[](https://numpy.org/doc/stable/reference/generated/numpy.trapezoid.html)
Adaptive variants of the trapezoidal rule enhance its utility in [quadrature](/page/Quadrature) libraries by incorporating error estimation and mesh refinement. In [SciPy](/page/SciPy), the `romberg` function leverages repeated trapezoidal integrations with [Richardson extrapolation](/page/Richardson_extrapolation) to achieve higher-order accuracy adaptively, suitable for functions with varying smoothness in optimization and modeling tasks.[](https://docs.scipy.org/doc/scipy/tutorial/integrate.html) The library's `trapezoid` function further supports composite applications with automatic handling of subintervals for improved precision.
In modern contexts, the non-uniform trapezoidal rule is particularly valuable for [data analysis](/page/Data_analysis) from sensors, where sampling intervals are irregular due to event-driven acquisition in [IoT](/page/IOT) devices or [environmental monitoring](/page/Environmental_monitoring). This extension approximates integrals over unevenly spaced points, enabling accurate computation of accumulated quantities like total exposure or flow rates from real-world sensor streams without [interpolation](/page/Interpolation) artifacts.[](https://www.researchgate.net/publication/317339672_Numerical_Integration_Schemes_for_Unequal_Data_Spacing)
### Alternatives and Limitations
While the trapezoidal rule provides a straightforward [approximation](/page/Approximation) for [numerical integration](/page/Numerical_integration), its second-order accuracy, characterized by an error term of O(h²) where h is the step size, limits its suitability for scenarios demanding high [precision](/page/Precision), as the [convergence](/page/Convergence) [rate](/page/Rate) slows significantly with increasing n compared to higher-order methods.[](https://math.dartmouth.edu/~m3cod/klbookLectures/406unit/trap.pdf) This order of [convergence](/page/Convergence) arises from the [linear interpolation](/page/Linear_interpolation) underlying the rule, which inadequately captures higher-order [curvature](/page/Curvature) in the integrand.[](https://www-users.cse.umn.edu/classes/Spring-2024/csci5302/Notes/Slides3/chap08.pdf)
The method also exhibits poor performance for oscillatory functions or those with singularities in the interval of integration, where the error bound can degrade substantially due to rapid variations or non-smooth behavior not well-approximated by piecewise linear segments.[](https://www.colorado.edu/amath/sites/default/files/attached-files/2019_f_improving_trap_rule_sirev_submitted.pdf)
Prominent alternatives include [Simpson's rule](/page/Simpson's_rule), which fits parabolic arcs to the data and achieves fourth-order accuracy O(h⁴), enabling faster convergence and better handling of smooth functions at the cost of requiring an even number of subintervals. [Gaussian quadrature](/page/Gaussian_quadrature) stands out for its exactness on polynomials of degree up to 2n-1 using only n evaluation points, offering superior efficiency for polynomial-like integrands by optimally placing nodes and weights, though it demands precomputed abscissas and is less flexible for arbitrary intervals without transformation.[](https://www.gcsu.edu/sites/files/page-assets/node-808/attachments/rothstein.pdf) Romberg integration builds directly on the trapezoidal rule by applying [Richardson extrapolation](/page/Richardson_extrapolation) to successive refinements, yielding higher-order estimates (up to exponential convergence for analytic functions) without additional function evaluations beyond the base method.[](https://www.math.ttu.edu/~vhowle/Courses/2010Spring_Math5335/quadNotes2.pdf)
The trapezoidal rule remains preferable for rapid preliminary estimates, problems emphasizing endpoint function values, or as a foundational component in extrapolated schemes like Romberg, particularly when simplicity and minimal setup outweigh precision needs.[](https://www.johndcook.com/blog/2020/02/18/trapezoid-romberg/)
In terms of trade-offs, the trapezoidal rule's computational cost is low, involving O(n) evaluations and simple arithmetic, but its lower order necessitates more points for comparable accuracy to alternatives like Gaussian quadrature, which, despite requiring fewer evaluations for high precision on smooth functions, involves more complex node selection and is computationally heavier per step.[](https://relate.cs.illinois.edu/course/cs450-s17/file-version/108b563f0496870001ffa4a77b504ff4d6ef57d1/lecture-notes/lec19.pdf) Simpson's rule strikes a balance, doubling the order over trapezoidal with similar ease of implementation but still lagging behind Gaussian for non-polynomial integrands.[](http://showard.sdsmt.edu/Math373/_AppliedNumMethodsText_SMH/09_Numerical_Integration/009_Numerical_Integration.pdf)
## Illustrative Examples
### Basic Numerical Example
To illustrate the basic application of the trapezoidal rule, consider approximating the definite [integral](/page/Integral) $\int_0^1 e^x \, dx$. The exact value of this [integral](/page/Integral), obtained via the [fundamental theorem of calculus](/page/Fundamental_theorem_of_calculus), is $e - 1 \approx 1.71828$.
For a single-interval implementation on the uniform grid with step size $h = b - a = 1$, the trapezoidal rule approximates the [integral](/page/Integral) as $\frac{h}{2} [f(a) + f(b)]$, where $f(x) = e^x$, $a = 0$, and $b = 1$./7%3A_Integration/7.02%3A_Trapezoidal_Rule_of_Integration) Substituting the values step by step: $f(0) = e^0 = 1$, $f(1) = e^1 \approx 2.71828$, so the approximation is $\frac{1}{2} (1 + 2.71828) = \frac{1 + e}{2} \approx 1.85914$./7%3A_Integration/7.02%3A_Trapezoidal_Rule_of_Integration)
The absolute error for this approximation is the difference between the estimated and exact values: $1.85914 - 1.71828 \approx 0.14086$. This positive error indicates an overestimate, consistent with the rule's behavior for [convex](/page/Convex) functions like $e^x$.
Geometrically, the trapezoidal rule estimates the area under the [curve](/page/Curve) $y = e^x$ from $x = 0$ to $x = 1$ by the area of a trapezoid with parallel sides of lengths $f(0) = 1$ and $f(1) = e \approx 2.71828$, and height $h = 1$. The straight-line segment connecting the endpoints $(0, 1)$ and $(1, e)$ lies above the concave-up [curve](/page/Curve), enclosing a region that includes the [integral](/page/Integral) area plus a small segment between the [chord](/page/Chord) and the [graph](/page/Graph)./7%3A_Integration/7.02%3A_Trapezoidal_Rule_of_Integration)
### Composite Rule Example
To illustrate the application of the composite trapezoidal rule, consider the integral $\int_0^1 e^x \, dx$, whose exact value is $e - 1 \approx 1.71828$./7:_Integration/7.02:_Trapezoidal_Rule_of_Integration) Divide the interval $[0, 1]$ into $n=4$ equal subintervals, yielding step size $h = 1/4 = 0.25$. The grid points are $x_k = kh$ for $k = 0, 1, 2, 3, 4$, and the function values $f(x_k) = e^{x_k}$ are computed as follows.
The following table lists the points, function values, and multipliers used in the weighted sum (1 for the endpoints, 2 for interior points):
| $k$ | $x_k$ | $f(x_k) \approx$ | Multiplier |
|-----|-------|------------------|------------|
| 0 | 0.00 | 1.00000 | 1 |
| 1 | 0.25 | 1.28403 | 2 |
| 2 | 0.50 | 1.64872 | 2 |
| 3 | 0.75 | 2.11700 | 2 |
| 4 | 1.00 | 2.71828 | 1 |
The composite trapezoidal approximation is given by
\frac{h}{2} \left[ f(x_0) + 2 \sum_{k=1}^{3} f(x_k) + f(x_4) \right] = 0.125 \times (1 + 2 \times 5.04975 + 2.71828) \approx 1.72722.
The absolute error is $|1.72722 - 1.71828| \approx 0.00894$./7:_Integration/7.02:_Trapezoidal_Rule_of_Integration)
To demonstrate convergence, apply the rule with $n=2$ subintervals ($h=0.5$), yielding points $x_k = 0, 0.5, 1$ and function values $f(0)=1$, $f(0.5) \approx 1.64872$, $f(1) \approx 2.71828$. The approximation is $\frac{0.5}{2} [1 + 2 \times 1.64872 + 2.71828] \approx 1.75393$, with absolute error $\approx 0.03565$. The error for $n=4$ is approximately one-fourth that for $n=2$, consistent with the $O(1/n^2)$ convergence rate of the method./7:_Integration/7.02:_Trapezoidal_Rule_of_Integration) This reduction aligns with the predicted behavior from the error bound analysis.