# 线性插值

**线性插值**是一种函数估值方法，它假定函数在两个已知数据点之间沿连接这两点的直线变化，据此估计中间点的函数值。给定两个点 \( (x_0, y_0) \) 和 \( (x_1, y_1) \)，且 \( x_0 \ne x_1 \)，插值函数就是穿过这两点的直线，任何中间值都从这条直线上读取。它是最简单、应用最广的插值方法，从古代的天文表到现代的数值计算库，处处可见其身影。<sup>[1](https://sites.pitt.edu/~trenchea/MATH1070/slides/MATH1070.pdf)</sup><sup> • </sup><sup>[2](https://www.sciencedirect.com/topics/engineering/interpolants)</sup>

| 关键事实 | 详情 |
|---|---|
| 公式 | \( p_1(x) = f(x_0) + \dfrac{f(x_1) - f(x_0)}{x_1 - x_0}\,(x - x_0) \)，即穿过两个数据点的直线<sup>[3](https://people.bath.ac.uk/jmf68/ma20222/Numerical%20analysis%20notes.pdf)</sup> |
| 误差界 | 对光滑的 \( f \)，有 \( \|e\|_{\infty,[x_0,x_1]} \le \dfrac{(x_1 - x_0)^2}{8}\,\|f''\|_{\infty,[x_0,x_1]} \)<sup>[3](https://people.bath.ac.uk/jmf68/ma20222/Numerical%20analysis%20notes.pdf)</sup> |
| 光滑性 | 分段线性插值函数连续，但在内部数据点处一般不可微<sup>[4](https://gustavdelius.github.io/NumericalAnalysis2018-23/chapter06.html)</sup> |
| 有界性 | 插值结果始终位于两端值之间，这使该方法在实践中十分可靠<sup>[2](https://www.sciencedirect.com/topics/engineering/interpolants)</sup> |
| 软件 | NumPy 的 `numpy.interp` 返回一维分段线性插值；SciPy 提供 `interp1d` 和 `make_interp_spline(..., k=1)`<sup>[5](https://docs.scipy.org/doc/numpy-1.11.0/reference/generated/numpy.interp.html)</sup><sup> • </sup><sup>[6](https://scipy.github.io/devdocs/tutorial/interpolate.html)</sup> |
| 早期历史 | 托勒密在《天文学大成》（约公元 140 年）中使用了线性插值技术；喜帕恰斯用它来填补弦表中中间点的值<sup>[7](https://imagescience.org/meijering/research/chronology/)</sup><sup> • </sup><sup>[8](https://mathshistory.st-andrews.ac.uk/Biographies//Hipparchus/)</sup> |

## 公式

设 \( x \) 方向的数据点按升序排列，\( x_i < x_{i+1} \)，并设 \( x \) 满足 \( x_i < x < x_{i+1} \)。在 \( x \) 处的线性插值为

\[ \hat{y}(x) = y_i + \frac{(y_{i+1} - y_i)(x - x_i)}{x_{i+1} - x_i}. \]

用文字表述：估值从左侧的数据值出发，沿着连接两点的直线，按 \( x \) 在区间中所走过的比例向前移动。<sup>[9](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter17.02-Linear-Interpolation.html)</sup> 一个等价的对称形式把插值写成两个值的加权平均，

\[ \ell(x) = \frac{(x_1 - x)\,y_0 + (x - x_0)\,y_1}{x_1 - x_0}, \]

由此可以清楚地看出 \( \ell(x_0) = y_0 \) 且 \( \ell(x_1) = y_1 \)。<sup>[1](https://sites.pitt.edu/~trenchea/MATH1070/slides/MATH1070.pdf)</sup> 若将两个节点归一化为 \( x_0 = 0 \) 和 \( x_1 = 1 \)，并以 \( t \) 表示它们之间的相对位置，[美国国家标准与技术研究院](https://www.edgepedia.org/zh/national-institute-of-standards-and-technology)的数学函数数字图书馆给出的两点公式为 \( f_t = (1-t)\,f_0 + t\,f_1 + R_{1,t} \)，其中 \( R_{1,t} \) 为误差项。<sup>[10](https://dlmf.nist.gov/3.3)</sup>

一个实例可以说明具体做法。对于数据 \( x = [0, 1, 2] \)、\( y = [1, 3, 2] \)，在 \( x = 1.5 \) 处的估值使用第二个和第三个点：\( \hat{y}(1.5) = 3 + \frac{(2 - 3)(1.5 - 1)}{2 - 1} = 2.5 \)。SciPy 函数 `interp1d` 返回相同的值。<sup>[9](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter17.02-Linear-Interpolation.html)</sup>

## 误差

线性插值的误差由被插值函数的二阶导数决定。对 \( [x_0, x_1] \) 上的光滑函数 \( f \)，在开区间内每一点 \( x \) 处，都存在一个点 \( \xi \)（依赖于 \( x \)），使得

\[ e(x) = f(x) - p_1(x) = \frac{f''(\xi)}{2}\,w_2(x), \qquad w_2(x) = (x - x_0)(x - x_1). \]

由于 \( |w_2(x)| \le (x_1 - x_0)^2/4 \)，最大值在中点处取得，因此整个区间上的误差满足

\[ \|e\|_{\infty,[x_0,x_1]} \le \frac{(x_1 - x_0)^2}{8}\,\|f''\|_{\infty,[x_0,x_1]}. \]

因此，误差与数据点间距的平方成正比，也与函数曲率的大小成正比。<sup>[3](https://people.bath.ac.uk/jmf68/ma20222/Numerical%20analysis%20notes.pdf)</sup> 在 DLMF 的归一化形式中，相应的误差界系数为 \( c_1 = 1/8 \)，是同一个常数。<sup>[10](https://dlmf.nist.gov/3.3)</sup>

二阶导数因子解释了该方法何时表现不佳。在 \( [1/4, 1] \) 上对 \( f(x) = \sqrt{x} \) 插值，误差很小；但在 \( [0, 3/4] \) 上对同一函数插值，误差则大得多，因为当 \( x \to 0 \) 时 \( f''(x) \to -\infty \)，所以二阶导数在该区间上的上确界范数为无穷大。<sup>[3](https://people.bath.ac.uk/jmf68/ma20222/Numerical%20analysis%20notes.pdf)</sup>

## 分段线性插值

要在整个区间上近似一个函数，可将区间细分为网格 \( a = y_0 < y_1 < \cdots < y_J = b \)，并在每个子区间 \( [y_{j-1}, y_j] \) 上应用线性插值。所得结果是一个连续的分段线性函数，用直线段连接所有数据点。<sup>[3](https://people.bath.ac.uk/jmf68/ma20222/Numerical%20analysis%20notes.pdf)</sup><sup> • </sup><sup>[4](https://gustavdelius.github.io/NumericalAnalysis2018-23/chapter06.html)</sup>

这种构造有一个明显的局限：插值函数在内部数据点处一般不可微，斜率从一个线段到下一个线段发生突变。高阶导数在这些点处不连续，当需要光滑导数时，这就限制了该方法的应用。<sup>[4](https://gustavdelius.github.io/NumericalAnalysis2018-23/chapter06.html)</sup><sup> • </sup><sup>[2](https://www.sciencedirect.com/topics/engineering/interpolants)</sup> 在光滑性重要的场合，三次样条插值是常用的替代方案，它在节点之间拟合三次多项式，并使一阶和二阶导数在节点处保持匹配。<sup>[4](https://gustavdelius.github.io/NumericalAnalysis2018-23/chapter06.html)</sup>

从样条的角度看，线性插值本身就是一次样条，以数据点为节点。它的流行既源于简单，也源于一种高阶方法所不具备的安全性：插值结果始终介于两端值之间，因此该方法不会对数据产生过冲。<sup>[2](https://www.sciencedirect.com/topics/engineering/interpolants)</sup>

## 相关应用

**反插值。** 点与值的角色可以互换：给定 \( x_0 \) 和 \( x_1 \) 处两个符号相反的值 \( f_0 \) 和 \( f_1 \)，在函数值上做线性插值可得到交点的估计

\[ x_2 = \frac{f_1\,x_0 - f_0\,x_1}{f_1 - f_0}. \]

这是求解 \( f(x) = 0 \) 的假位法（regula falsi）和割线法的第一步，迭代呈线性收敛。<sup>[11](https://dlmf.nist.gov/3.8)</sup>

**多维插值。** 在二维情形下，双线性插值先沿一个方向做一维线性插值，再沿另一个方向做一次。它在图像重采样和地图重投影中是标准做法，与最近邻重采样相比结果更清晰，但计算代价更高。<sup>[12](https://ntrs.nasa.gov/api/citations/19760018546/downloads/19760018546.pdf)</sup><sup> • </sup><sup>[13](https://step.esa.int/docs/tutorials/Collocation_S3TBX_Tutorial_v1_rev6.pdf)</sup>

**软件。** NumPy 的 `numpy.interp(x, xp, fp)` 为数据点 `xp`、`fp` 计算一维分段线性插值，并可选择数据范围之外的返回值以及角度等周期坐标的处理方式。一个有文档记载的局限是，它不允许控制数据范围之外的外推。<sup>[5](https://docs.scipy.org/doc/numpy-1.11.0/reference/generated/numpy.interp.html)</sup><sup> • </sup><sup>[14](https://docs.scipy.org/doc/scipy/tutorial/interpolate/1D.html)</sup> SciPy 的插值指南将 `numpy.interp` 列为一维线性插值的例程，替代方案是 `make_interp_spline(..., k=1)`，而高维散乱数据则使用 `LinearNDInterpolator`。<sup>[6](https://scipy.github.io/devdocs/tutorial/interpolate.html)</sup>

## 历史

线性插值历史悠久。约公元 140 年，克劳狄乌斯·托勒密（Claudius Ptolemy）在《[天文学大成](https://www.edgepedia.org/zh/almagest)》（Almagest）中为天文目的构造多变量函数表时，使用了一种自适应线性插值技术。<sup>[7](https://imagescience.org/meijering/research/chronology/)</sup> 更早的时候，据图默（Toomer）的复原，公元前二世纪的希腊天文学家[喜帕恰斯](https://www.edgepedia.org/zh/hipparchus)（Hipparchus）以 7.5 度为间隔定义其弦函数，并用线性插值求中间点的值。<sup>[8](https://mathshistory.st-andrews.ac.uk/Biographies//Hipparchus/)</sup>

后来的传统对这一思想做了改进。在印度，直到婆什迦罗二世（Bhaskara II）时代，正弦表的制表间隔都不细于 \( 3\tfrac{3}{4} \) 度，表列弧之间的最简单近似就是线性插值；早在七世纪，[婆罗摩笈多](https://www.edgepedia.org/zh/brahmagupta)（Brahmagupta）就利用二阶差分发展出一种更精确的方案，这种二次校正与三个连续表列弧处的正弦值吻合。<sup>[15](https://www.math.mcgill.ca/darmon/courses/history/katz.pdf)</sup> 在中国，天文学家[沈括](https://www.edgepedia.org/zh/shen-kuo)（Shen Kuo）批评当时行用的历法方案，恰恰是因为它实质上就是线性插值，“把黄道当成多边形而非圆”，并主张采用更高阶的插值。<sup>[16](https://mathshistory.st-andrews.ac.uk/DSB/Shen_Kua.pdf)</sup>

这个词本身相对晚近：*interpolation*（插值）一词由约翰·沃利斯（John Wallis）引入数学，见于 1685 年出版的其代数著作英译本。<sup>[17](https://mathshistory.st-andrews.ac.uk/Miller/mathword/i/)</sup>

## References

1. [Numerical Mathematical Analysis, MATH 1070 lecture slides, University of Pittsburgh](https://sites.pitt.edu/~trenchea/MATH1070/slides/MATH1070.pdf)
2. [Linear Interpolation, ScienceDirect Topics overview](https://www.sciencedirect.com/topics/engineering/interpolants)
3. [MA20222: Numerical Analysis lecture notes, University of Bath](https://people.bath.ac.uk/jmf68/ma20222/Numerical%20analysis%20notes.pdf)
4. [Approximation and interpolation, Numerical Analysis 2018-23, University of York](https://gustavdelius.github.io/NumericalAnalysis2018-23/chapter06.html)
5. [numpy.interp, NumPy v1.11 Manual](https://docs.scipy.org/doc/numpy-1.11.0/reference/generated/numpy.interp.html)
6. [Interpolation (scipy.interpolate), SciPy v2.0.0.dev Manual](https://scipy.github.io/devdocs/tutorial/interpolate.html)
7. [Erik Meijering, A Chronology of Interpolation: From Ancient Astronomy to Modern Signal and Image Processing](https://imagescience.org/meijering/research/chronology/)
8. [Hipparchus (190 BC - 120 BC), MacTutor History of Mathematics](https://mathshistory.st-andrews.ac.uk/Biographies//Hipparchus/)
9. [Linear Interpolation, Python Numerical Methods, UC Berkeley](https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter17.02-Linear-Interpolation.html)
10. [DLMF §3.3 Interpolation, NIST Digital Library of Mathematical Functions](https://dlmf.nist.gov/3.3)
11. [DLMF §3.8 Nonlinear Equations, NIST Digital Library of Mathematical Functions](https://dlmf.nist.gov/3.8)
12. [NASA Technical Reports: map projection resampling by bilinear interpolation](https://ntrs.nasa.gov/api/citations/19760018546/downloads/19760018546.pdf)
13. [S3TBX Collocation Tutorial, ESA Sentinel Toolbox](https://step.esa.int/docs/tutorials/Collocation_S3TBX_Tutorial_v1_rev6.pdf)
14. [1-D interpolation, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/tutorial/interpolate/1D.html)
15. [Victor J. Katz, A History of Mathematics, Chapter 8: Ancient and Medieval India](https://www.math.mcgill.ca/darmon/courses/history/katz.pdf)
16. [N. Sivin, Cosmos and Computation in Early Chinese Mathematical Astronomy (Shen Kua biography, DSB)](https://mathshistory.st-andrews.ac.uk/DSB/Shen_Kua.pdf)
17. [Earliest Known Uses of Some of the Words of Mathematics (I), MacTutor History of Mathematics](https://mathshistory.st-andrews.ac.uk/Miller/mathword/i/)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: 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/linear-interpolation

English original: https://www.edgepedia.org/linear-interpolation
