# 数值微分

**数值微分**是从采样函数值估计函数导数的一组方法，它使用有限差分而非定义导数时所用的极限过程。由于计算机不能取极限，每种方法都必须选择有限步长，而该领域的核心问题是平衡步长所控制的两种误差：截断误差随步长增大而增大，浮点舍入误差随步长缩小而增大。<sup>[1](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 基本公式 | 前向差分 \( f'(x_0) \approx \frac{f(x_0+h)-f(x_0)}{h} \)，误差为 \( -\frac{h}{2}f''(\xi) \)，关于 \( h \) 为一阶<sup>[1](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup> |
| 中心差分 | \( \frac{f(x+h)-f(x-h)}{2h} \) 的截断误差正比于 \( h^2 \)<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup> |
| 最优步长 | 对中心差分，双精度下总误差在 \( h \approx \varepsilon_{\mathrm{mach}}^{1/3} \approx 10^{-5} \) 附近最小，最小误差接近 \( \varepsilon_{\mathrm{mach}}^{2/3} \approx 10^{-10} \)<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup> |
| 精度提升 | 理查森外推将 \( h \) 和 \( h/2 \) 处的中心差分以权重 \( -1/3 \) 和 \( 4/3 \) 组合，把阶从 \( h^2 \) 提高到 \( h^4 \)<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup> |
| 复步长 | \( f'(x) \approx \mathrm{Im}\,\frac{f(x+\mathrm{i}h)}{h} \) 的误差为 \( O(h^2) \)，并容许任意小的 \( h \)；实践中使用过 \( h = 10^{-100} \)<sup>[3](https://www.siam.org/publications/siam-news/articles/differentiation-without-a-difference/)</sup> |
| 含噪数据 | 对测量数据微分通常是不适定问题，需先平滑或正则化，再取差分<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC7899139/)</sup> |

## 有限差分公式

起点是导数作为极限的定义。选择一个小 \( h \) 并计算差商，得到前向差分公式；其误差项由线性插值多项式导出，为 \( -\frac{h}{2}f''(\xi) \)，其中 \( \xi \) 是靠近 \( x_0 \) 的某个点。取 \( h > 0 \) 得到前向差分，取 \( h < 0 \) 得到后向差分；无论哪种方式，误差都是一阶 \( O(h) \)。<sup>[1](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup> 作为一个具体例子，用 \( h = 0.1 \) 近似 \( e^x \) 在 0 处的导数得到 1.052，实际误差为 0.052，而误差界为 0.0553。<sup>[1](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup>

对称差分或中心差分使用 \( x \) 两侧的点：

\[ D_1(h) = \frac{f(x+h)-f(x-h)}{2h} = f'(x) - \frac{h^2}{6}f'''(z) \]

其中 \( z \) 是介于 \( x-h \) 与 \( x+h \) 之间的某个点。两个泰勒展开中的偶数阶项相互抵消，留下正比于 \( h^2 \) 而非 \( h \) 的截断误差。<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup> 高阶公式以及任意阶导数的公式可以系统地生成；数学家本特·福恩伯格（Bengt Fornberg）以谱方法和有限差分方法方面的工作闻名，他于 1988 年发表了简单的递推公式，用于计算任意间距一维网格上任意导数阶和任意精度阶的紧致有限差分公式的权重。<sup>[5](https://cir.nii.ac.jp/crid/1361418521390278016)</sup>

## 步长权衡

微分在数值上不稳定，而积分并非如此：差商要除以一个很小的数，因此舍入最终会占主导，而积分会把误差平均掉。<sup>[1](https://persson.berkeley.edu/math128a/lecture_notes/math128a_lecture_notes_chapter_4.html)</sup> 其机制是相减抵消。如果舍入对 \( f(x) \) 和 \( f(x+h) \) 的计算值产生量级为 \( \varepsilon_{\mathrm{mach}} \cdot |f(x)| \) 的扰动，则计算出的差商带有约 \( \varepsilon_{\mathrm{mach}} |f(x)|/h \) 的误差，该误差随 \( h \) 缩小而增大。<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup>

总误差是截断误差与舍入误差贡献之和，最优步长使二者平衡。<sup>[6](https://www.studocu.com/en-ca/document/university-of-calgary/numerical-methods-in-engineering/chap-5-understanding-errors-in-numerical-differentiation/160595708)</sup> 对前向差分，令 \( |f''(x)|h/2 = \varepsilon_{\mathrm{mach}}|f(x)|/h \)，得到最优 \( h \) 正比于 \( \varepsilon_{\mathrm{mach}}^{1/2} \)，在双精度下约为 \( 10^{-8} \)。<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup> 对中心差分，相应的平衡 \( |f'''(x)|h^2/6 = \varepsilon_{\mathrm{mach}}|f(x)|/h \) 给出正比于 \( \varepsilon_{\mathrm{mach}}^{1/3} \) 的 \( h \)，约为 \( 10^{-5} \)，以及量级为 \( \varepsilon_{\mathrm{mach}}^{2/3} \) 的最小可达误差，约为 \( 10^{-10} \)。在 \( x = 1 \) 处对 \( \sin(x) \) 微分的算例中，前向差分的误差随 \( h \) 每减小一个数量级下降为原来的十分之一，直到 \( h \approx 10^{-7} \)，然后大致按 \( 1/h \) 上升；中心差分在触底到预测水平之前，每个数量级下降为原来的一百分之一。<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup> 存在通过直接最小化舍入误差与截断误差的组合来估计最优步长的方法。<sup>[7](https://www.sciencedirect.com/science/article/pii/0898122181900626)</sup>

## 理查森外推

**理查森外推**通过组合多个步长下的求值来改进差分公式。由于中心差分按 \( h \) 的奇次幂展开，组合

\[ D_2(h) = -\tfrac{1}{3}D_1(h) + \tfrac{4}{3}D_1(h/2) = D_1(h/2) + \frac{D_1(h/2)-D_1(h)}{3} \]

消去 \( h^2 \) 项，留下正比于 \( h^4 \) 的截断误差。再次应用同样的思想，权重为 \( -1/15 \) 和 \( 16/15 \)，消去 \( h^4 \) 项，得到 \( h^6 \) 精度。在 \( \sin(x) \) 例子中，外推误差每步下降为原来的一万分之一，直到舍入终止改进，这说明了为什么该递推不值得重复太多次。<sup>[2](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)</sup>

该方法以[刘易斯·弗莱·理查森](https://www.edgepedia.org/zh/lewis-fry-richardson)（Lewis Fry Richardson）命名，他在 1911 年关于用有限差分近似算术求解物理问题的论文中引入了该方法，并称之为“延迟取极限法”；一般过程把差分问题的解视为网格参数 \( h \) 的函数，以 \( h \) 为变量进行插值，并在 \( h = 0 \) 处计算插值函数的值。<sup>[8](https://encyclopediaofmath.org/wiki/Richardson_extrapolation)</sup> 几何递减步长应用于求积的特殊情形是龙贝格法则，由 W. 龙贝格（W. Romberg）于 1955 年发表。<sup>[8](https://encyclopediaofmath.org/wiki/Richardson_extrapolation)</sup> 亚琛工业大学（RWTH Aachen）数学家赫尔曼·恩格尔斯（Hermann Engels）在《数学史》（Historia Mathematica）（1979）中的历史分析追溯了[理查森外推](https://www.edgepedia.org/zh/richardson-extrapolation)和龙贝格求积的发展，并将二者描述为数值高效且可靠过程的典型例子。<sup>[9](https://www.sciencedirect.com/science/article/pii/0315086079901265)</sup> 除多项式插值外，也使用按 \( h^p \) 幂的有理外推。<sup>[8](https://encyclopediaofmath.org/wiki/Richardson_extrapolation)</sup>

## 复步长法

对于解析函数，另一条路径完全避免相减抵消。复步长近似

\[ f'(x) \approx \mathrm{Im}\,\frac{f(x+\mathrm{i}h)}{h} \]

的误差为 \( O(h^2) \)，并且由于不取几乎相等的实数之差，\( h \) 可以取得任意小而不使结果因舍入而失效；英国国家物理实验室（National Physical Laboratory）使用过 \( h = 10^{-100} \)。该方法已知最早出现在威廉·斯夸尔（William Squire）和乔治·特拉普（George Trapp）1998 年发表于《SIAM评论》（SIAM Review）的论文中，他们受到詹姆斯·莱尼斯（James Lyness）和[克利夫·莫勒](https://www.edgepedia.org/zh/cleve-moler)（Cleve Moler）关于复变量求导的早期工作启发。<sup>[3](https://www.siam.org/publications/siam-news/articles/differentiation-without-a-difference/)</sup> 原论文描述了一种避免经典导数近似中固有的相减抵消误差的方法。<sup>[10](https://epubs.siam.org/doi/abs/10.1137/S003614459631241X?journalCode=sireadinfo)</sup> 在尼古拉斯·海厄姆（Nicholas Higham）的解释中，这个技巧有效，是因为它充当一种以 \( h \) 为符号变量的近似自动微分；它要求 \( f \) 本身的计算不将舍入误差引入虚部，并且已被用于工程中的敏感性分析和深度学习语境中的梯度近似。<sup>[3](https://www.siam.org/publications/siam-news/articles/differentiation-without-a-difference/)</sup> 采用一般复步长计算一阶和二阶导数的扩展方法，保留了无舍入误差的特点，同时改善截断误差特性。<sup>[11](https://www.sciencedirect.com/science/article/pii/S0377042707004086)</sup>

## 含噪数据与测量数据

当输入是测量数据而非可求值函数时，微分以另一种方式变得更难。测量带有误差，其精度通常远低于机器极限，而差分核心处的减法会放大这些误差；该问题通常是不适定的。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC7899139/)</sup><sup> • </sup><sup>[12](https://arxiv.org/abs/physics/0510176)</sup> 一种常见方法是对数据施加平滑滤波器，然后取有限差分。经典实例是萨维茨基-戈莱方法，由亚伯拉罕·萨维茨基（Abraham Savitzky）和[马塞尔·J. E. 戈莱](https://www.edgepedia.org/zh/marcel-j-e-golay)（Marcel J. E. Golay）于 1964 年发表于《分析化学》（Analytical Chemistry），该方法通过数据点与表格化整数系数的最小二乘卷积进行平滑和微分，表格给出最高五阶导数、使用 5 到 25 个点的情形。<sup>[13](https://pubs.acs.org/doi/abs/10.1021/ac60214a047)</sup> 第二类方法通过线性回归建立数据的局部模型；2020 年一个多目标优化框架在选择方法参数时，平衡对数据的忠实性与导数估计的平滑性。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC7899139/)</sup>

## 软件与替代方法

库直接封装了这些思想。SciPy 的 `scipy.differentiate.derivative` 对黑箱标量函数执行有限差分微分，默认使用八阶公式、初始步长 0.5、每次迭代步长缩减因子 2.0、最多 10 次迭代，并重用嵌套模板点上先前求值的函数值；它受 jacobi、numdifftools 和 DERIVEST 项目启发。<sup>[14](https://docs.scipy.org/doc/scipy/reference/generated/scipy.differentiate.derivative.html)</sup>

主要替代方法是自动微分，软件对代码应用链式法则，以机器精度计算导数而无需步长。例如，JAX 的 `jax.grad` 返回一个计算可调用对象精确梯度的函数，并且可以链式用于高阶导数；于是数值差分可作为自动微分结果的独立检查。<sup>[15](https://docs.jax.dev/en/latest/automatic-differentiation.html)</sup> 在可微仿真设置中，自动微分避免步长敏感性，并以比有限差分更低的计算成本提供敏感性，而有限差分在高维参数空间中会变得计算不可行。<sup>[16](https://arxiv.org/abs/2606.17390)</sup> 当只有黑箱函数可用时，有限差分仍是首选工具；近期工作考察了它们作为物理信息神经网络中自动微分替代方案的情况。<sup>[17](https://arxiv.org/abs/2608.11020)</sup>

## References

1. [Per-Olof Persson, 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)
2. [James Demmel, Lecture Notes on Numerical Differentiation, Math 128a, UC Berkeley](https://people.eecs.berkeley.edu/~demmel/ma128a_Spr02/LectureNotes/Differentiation.html)
3. [Nicholas J. Higham, "Differentiation With(out) a Difference", SIAM News 51(5), 2018](https://www.siam.org/publications/siam-news/articles/differentiation-without-a-difference/)
4. [Numerical differentiation of noisy data: A unifying multi-objective optimization framework, PMC (2020)](https://pmc.ncbi.nlm.nih.gov/articles/PMC7899139/)
5. [Bengt Fornberg (1988), "Generation of finite difference formulas on arbitrarily spaced grids", Mathematics of Computation 51(184): 699–706](https://cir.nii.ac.jp/crid/1361418521390278016)
6. [Chapter 5: Understanding Errors in Numerical Differentiation, lecture notes, University of Calgary](https://www.studocu.com/en-ca/document/university-of-calgary/numerical-methods-in-engineering/chap-5-understanding-errors-in-numerical-differentiation/160595708)
7. ["Numerical estimation of the first order derivative: approximate evaluation of an optimal step", Computers & Mathematics with Applications](https://www.sciencedirect.com/science/article/pii/0898122181900626)
8. ["Richardson extrapolation", Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Richardson_extrapolation)
9. [Hermann Engels (1979), "Zur Geschichte der Richardson-Extrapolation", Historia Mathematica 6(3): 280–293](https://www.sciencedirect.com/science/article/pii/0315086079901265)
10. [William Squire, George Trapp (1998), "Using Complex Variables to Estimate Derivatives of Real Functions", SIAM Review 40(1): 110–112](https://epubs.siam.org/doi/abs/10.1137/S003614459631241X?journalCode=sireadinfo)
11. ["Extensions of the first and second complex-step derivative approximations", Journal of Computational and Applied Mathematics](https://www.sciencedirect.com/science/article/pii/S0377042707004086)
12. ["Numerical differentiation: local versus global methods", arXiv:physics/0510176](https://arxiv.org/abs/physics/0510176)
13. [Abraham Savitzky, Marcel J. E. Golay (1964), "Smoothing and Differentiation of Data by Simplified Least Squares Procedures", Analytical Chemistry 36(8): 1627–1639](https://pubs.acs.org/doi/abs/10.1021/ac60214a047)
14. [scipy.differentiate.derivative, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.differentiate.derivative.html)
15. [Automatic differentiation, JAX documentation](https://docs.jax.dev/en/latest/automatic-differentiation.html)
16. ["A Differentiable GPU-Accelerated Finite Element Framework for Inverse Characterization of Finite-Strain Anisotropic Plasticity", arXiv:2606.17390](https://arxiv.org/abs/2606.17390)
17. ["Derivative Computation in PINNs: Automatic Differentiation, Finite Differences and Beyond", arXiv:2608.11020](https://arxiv.org/abs/2608.11020)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Numerical, string, and geometric algorithms › Numerical methods and approximation

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/numerical-differentiation

English original: https://www.edgepedia.org/numerical-differentiation
