# 梯形法则

梯形法则是一种数值积分（求积）公式，它用连接区间两端点处函数值的直线来替代被积函数，从而近似计算定积分，使得每一小块的面积成为梯形而非矩形。在单个区间 \([a,b]\) 上，令 \(h = b-a\)，公式为

\[ \int_a^b f(x)\,dx = \frac{1}{2}h\bigl(f(a)+f(b)\bigr) - \frac{1}{12}h^3 f''(\xi), \]

其中 \(\xi \in (a,b)\)，假定 \(f \in C^2[a,b]\)<sup>[1](https://dlmf.nist.gov/3.5)</sup>。尽管在单个子区间上精度平平，这条法则却有一个不同寻常的性质：用于光滑周期函数或全实数轴上的积分时，它按几何速率收敛——这一事实构成了科学计算中诸多方法的基础<sup>[2](https://epubs.siam.org/doi/10.1137/130932132)</sup>。

| 关键事实 | 详情 |
|---|---|
| 基本法则 | \(\int_a^b f\,dx = \tfrac{1}{2}h(f(a)+f(b)) - \tfrac{1}{12}h^3 f''(\xi)\)，其中 \(h=b-a\)，\(f \in C^2[a,b]\)<sup>[1](https://dlmf.nist.gov/3.5)</sup> |
| 复合误差 | 对 \(n\) 个宽度为 \(h=(b-a)/n\) 的子区间，\(E_n(f) = -\tfrac{b-a}{12}h^2 f''(\xi)\)：关于 \(h\) 为二阶<sup>[1](https://dlmf.nist.gov/3.5)</sup> |
| 周期情形 | 若 \(f \in C^k(\mathbb{R})\) 为周期函数并在一个周期上积分，则 \(E_n(f) = O(h^k)\)；当 \(k=\infty\) 时，误差的衰减快于 \(h\) 的任何代数幂，但不一定按 \(1/h\) 指数级小<sup>[1](https://dlmf.nist.gov/3.5)</sup><sup> • </sup><sup>[7](https://people.maths.ox.ac.uk/trefethen/publication/PDF/2014_149.pdf)</sup> |
| 实数轴 | 对在包含 \(\mathbb{R}\) 的带域内解析的 \(f\)，有 \(\int_{-\infty}^{\infty} f\,dt = h\sum_{k=-\infty}^{\infty} f(kh) + E_h(f)\)<sup>[1](https://dlmf.nist.gov/3.5)</sup> |
| 细化 | 龙贝格积分对复合法则施加理查森外推；误差展开中只含 \(h\) 的偶次幂<sup>[3](https://roesner.pages.ub.uni-bielefeld.de/lectures/computational-physics/semester/sose2026/lecture/03_differentiation_integration/04_romberg.html)</sup> |
| 比较 | 复合辛普森法则达到四阶误差 \(-\tfrac{b-a}{180}h^4 f^{(4)}(\mu)\)，在相同函数求值次数下好两个阶<sup>[4](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup> |
| 软件 | SciPy 的 `integrate.trapezoid` 对采样数据实现复合法则；旧名 `trapz` 在 SciPy 1.12 中弃用，1.14 中移除<sup>[5](https://docs.scipy.org/doc/scipy-1.15.2/release/1.12.0-notes.html)</sup> |

## 复合法则

单个梯形很少足够精确，因此将区间 \([a,b]\) 分成 \(n\) 个等宽子区间，宽度 \(h = (b-a)/n\)，节点为 \(x_j = a + jh\)，对每个子区间施加法则。合并各项后，内部节点同属两个子区间，权重为 2，得到

\[ \int_a^b f(x)\,dx \approx \frac{h}{2}\left[f(x_0) + 2\sum_{j=1}^{n-1} f(x_j) + f(x_n)\right]. \]

对 \(f \in C^2[a,b]\)，总误差坍缩为单项，

\[ E(f) = -\frac{b-a}{12}h^2 f''(\mu), \qquad \mu \in (a,b), \]

因此该方法是关于 \(h\) 的二阶方法<sup>[1](https://dlmf.nist.gov/3.5)</sup><sup> • </sup><sup>[4](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup>。一个实例展示了实际误差的大小：在 \([0,4]\) 上以 10 个区间积分 \(f(x) = x e^{-x}\)，得 0.8944624935，精确值为 0.9084218056，误差 0.0139593121，与用区间上 \(f''\) 的平均值代入误差公式的预测高度吻合<sup>[6](https://www.ece.uwaterloo.ca/~dwharder/NumericalAnalysis/13Integration/comptrap/error.html)</sup>。

误差界可用于选取 \(n\)。由于 \(|E(f)| \le \tfrac{b-a}{12}h^2 \max|f''|\)，对二阶导数的界可将容差换算为所需的子区间数<sup>[4](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup>。

## 周期积分与全直线积分的指数收敛

**该法则的非凡情形。** 若被积函数周期且光滑，且积分取在一个完整周期上，则限制一般区间上复合法则的端点修正项消失。DLMF 记载，对周期函数 \(f \in C^k(\mathbb{R})\)，误差为 \(O(h^k)\)；当 \(k=\infty\)（解析周期被积函数）时，误差是 \(1/h\) 的指数级小函数，使复合法则异常高效<sup>[1](https://dlmf.nist.gov/3.5)</sup>。对无穷梯形和

\[ \int_{-\infty}^{\infty} f(t)\,dt = h\sum_{k=-\infty}^{\infty} f(kh) + E_h(f) \]

同样成立，只要 \(f\) 在包含实轴的带域内解析<sup>[1](https://dlmf.nist.gov/3.5)</sup>。

[牛津大学](https://www.edgepedia.org/zh/university-of-oxford)数值分析教授[劳埃德·N·特雷费森](https://www.edgepedia.org/zh/lloyd-n-trefethen)（Lloyd N. Trefethen）与斯泰伦博斯大学的 J. A. C. 魏德曼（J. A. C. Weideman）在 2014 年《SIAM 评论》的论文《指数收敛的梯形法则》（SIAM Review 56(3), pp. 385–458）中综述了这一现象<sup>[2](https://epubs.siam.org/doi/10.1137/130932132)</sup>。他们表明，这种几何收敛与科学计算中的诸多方法相关联，包括拉普拉斯逆变换、特殊函数、复分析、有理逼近、积分方程，以及矩阵与算子的函数和特征值计算<sup>[2](https://epubs.siam.org/doi/10.1137/130932132)</sup>。他们的综述指出了解释快速收敛的四类论证：级数与混叠、围道积分与留数演算、插值，以及其他途径<sup>[7](https://people.maths.ox.ac.uk/trefethen/publication/PDF/2014_149.pdf)</sup>。[爱丁堡大学](https://www.edgepedia.org/zh/university-of-edinburgh)数值分析教授德斯蒙德·J·海厄姆（Desmond J. Higham）总结了该综述对方法何以仍然有价值的评估：易于使用、收敛性质强大且分析直截了当，以及在生成显式逼近公式方面的实用性<sup>[8](https://www.siam.org/publications/siam-news/articles/the-mathematics-and-history-of-the-trapezoidal-rule/)</sup>。

收敛速率由被积函数最近的奇点决定。在综述的积分方程示例中，用尼斯特伦方法配合梯形法则求解椭圆内的[拉普拉斯方程](https://www.edgepedia.org/zh/laplaces-equation)，观测到的收敛符合速率 \(O(e^{-2\pi a/h})\)，\(a \approx 0.55\)，与被积函数在 \(\operatorname{Im}(\varphi) = \pm\operatorname{arcsinh}(1/\sqrt{3}) \approx \pm 0.549\) 处的奇点一致<sup>[7](https://people.maths.ox.ac.uk/trefethen/publication/PDF/2014_149.pdf)</sup>。

## 欧拉–麦克劳林与龙贝格积分

欧拉–麦克劳林公式解释了复合法则的误差结构。对 \(f \in C^{2m+2}[a,b]\)，误差按步长的偶次幂展开，

\[ E_n(f) = c_1 h^2 + c_2 h^4 + \cdots + c_m h^{2m} + O(h^{2m+2}), \]

系数涉及[伯努利数](https://www.edgepedia.org/zh/bernoulli-numbers)以及 \(f\) 在端点 \(a\) 和 \(b\) 处的奇数阶导数<sup>[1](https://dlmf.nist.gov/3.5)</sup><sup> • </sup><sup>[3](https://roesner.pages.ub.uni-bielefeld.de/lectures/computational-physics/semester/sose2026/lecture/03_differentiation_integration/04_romberg.html)</sup>。当奇数阶端点导数已知时，可直接加入欧拉–麦克劳林修正项来改进法则<sup>[1](https://dlmf.nist.gov/3.5)</sup>。

龙贝格积分利用这一展开。它以按 2 的幂次减半的步长计算复合梯形法则，并施加[理查森外推](https://www.edgepedia.org/zh/richardson-extrapolation)，在每次加倍时消去首项误差，每步获得两个阶的精度提升<sup>[3](https://roesner.pages.ub.uni-bielefeld.de/lectures/computational-physics/semester/sose2026/lecture/03_differentiation_integration/04_romberg.html)</sup>。对 C∞ 周期被积函数，所有端点项消失，梯形误差为超代数小，但不一定指数级小，因此在该特殊情形下龙贝格外推增益甚微<sup>[3](https://roesner.pages.ub.uni-bielefeld.de/lectures/computational-physics/semester/sose2026/lecture/03_differentiation_integration/04_romberg.html)</sup><sup> • </sup><sup>[7](https://people.maths.ox.ac.uk/trefethen/publication/PDF/2014_149.pdf)</sup>。

## 与其他法则的比较

复合辛普森法则在每对子区间上拟合一条抛物线，对 \(f \in C^4[a,b]\) 且 \(n\) 为偶数，误差为 \(-\tfrac{b-a}{180}h^4 f^{(4)}(\mu)\)，在相同函数求值次数下比复合梯形法则好两个阶<sup>[4](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup>。在 \(\int_0^\pi \sin^2 x\,dx\) 上，\(n=4\)（五次求值）的[辛普森法则](https://www.edgepedia.org/zh/simpsons-rule)即达到梯形法则需 \(n=10\)（十一次求值）才能保证的误差界<sup>[4](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup>。辛普森法则本身可视为步长 \(h\) 与 \(h/2\) 的两个梯形法则的组合，经细化以消去误差项<sup>[1](https://dlmf.nist.gov/3.5)</sup>。

与高斯求积和克伦肖–柯蒂斯求积相比，特雷费森–魏德曼的后记措辞审慎：快速收敛的梯形法则并非不可或缺，高斯求积始终是一个选项，但梯形法则往往是周期区间或圆周上积分最自然的工具，而其简单性意味着其收敛速率异常易于分析和预测<sup>[7](https://people.maths.ox.ac.uk/trefethen/publication/PDF/2014_149.pdf)</sup>。

## 实际使用

由于该法则只需等距点上的函数值，它是积分采样数据的标准方法——当被积函数没有公式可依时尤其如此。SciPy 为此提供 `integrate.trapezoid`，以及用于累积积分的 `cumulative_trapezoid`；该函数在 SciPy 1.6 中由 `trapz` 更名，1.12 中弃用，1.14 中移除<sup>[5](https://docs.scipy.org/doc/scipy-1.15.2/release/1.12.0-notes.html)</sup><sup> • </sup><sup>[9](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.trapezoid.html)</sup>。它也能处理参数曲线：给定采样 \((x(t), y(t))\)，它计算 \(\int y(t)\,\frac{dx}{dt}\,dt\)，这正是估计闭合曲线所围面积的方式<sup>[9](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.trapezoid.html)</sup>。

## 古代渊源

将位移作为时间–速度空间中梯形图形的面积来计算，通常追溯到 14 世纪的欧洲，但四块公元前 350 年至公元前 50 年的巴比伦楔形文字泥板，以木星沿黄道的每日位移对时间作图所得的梯形面积，计算了木星的位移。[柏林洪堡大学](https://www.edgepedia.org/zh/humboldt-university-of-berlin)古代科学史家马蒂厄·奥森德里弗（Mathieu Ossendrijver）于 2016 年在《科学》上发表了这一解读，称这些泥板是巴比伦数学天文学中几何方法的首个证据——该领域此前被认为只使用算术概念<sup>[10](https://www.topoi.org/publication/33131/)</sup>。巴比伦天文学家还将梯形图形分成两个等面积的小梯形，以求出木星走完其 60 天路程一半所用的时间<sup>[11](https://www.sciencenews.org/article/babylonians-used-geometry-track-jupiters-movements)</sup>。

## References

1. [§3.5 Quadrature, NIST Digital Library of Mathematical Functions](https://dlmf.nist.gov/3.5)
2. [Lloyd N. Trefethen and J. A. C. Weideman (2014). The Exponentially Convergent Trapezoidal Rule. SIAM Review 56(3), 385–458.](https://epubs.siam.org/doi/10.1137/130932132)
3. [Romberg Integration, Computational Physics lecture notes, Universität Bielefeld](https://roesner.pages.ub.uni-bielefeld.de/lectures/computational-physics/semester/sose2026/lecture/03_differentiation_integration/04_romberg.html)
4. [Chapter 4: Numerical Differentiation and Integration, MATH 128A lecture notes, UC Berkeley](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)
5. [SciPy 1.12.0 Release Notes](https://docs.scipy.org/doc/scipy-1.15.2/release/1.12.0-notes.html)
6. [Topic 13.2: Composite-Trapezoidal Rule (Error Analysis), University of Waterloo](https://www.ece.uwaterloo.ca/~dwharder/NumericalAnalysis/13Integration/comptrap/error.html)
7. [Trefethen and Weideman, The Exponentially Convergent Trapezoidal Rule (PDF)](https://people.maths.ox.ac.uk/trefethen/publication/PDF/2014_149.pdf)
8. [Desmond J. Higham (2014). The Mathematics and History of the Trapezoidal Rule. SIAM News.](https://www.siam.org/publications/siam-news/articles/the-mathematics-and-history-of-the-trapezoidal-rule/)
9. [scipy.integrate.trapezoid, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.trapezoid.html)
10. [Mathieu Ossendrijver (2016). Ancient Babylonian astronomers calculated Jupiter's position from the area under a time-velocity graph. Science 351(6272), 482–484.](https://www.topoi.org/publication/33131/)
11. [Babylonians used geometry to track Jupiter's movements, Science News](https://www.sciencenews.org/article/babylonians-used-geometry-track-jupiters-movements)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 算法与计算方法 › 数值、字符串与几何算法 › 数值方法与近似

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/trapezoidal-rule

English original: https://www.edgepedia.org/trapezoidal-rule
