scipy.interpolate中的interp1d函数使用了什么算法

What algorithm used in interp1d function in scipy.interpolate

所以我正在为我的数值课程编写一个 python 程序,我不得不编写一个三次样条程序。所以我实现了书中给出的三次样条公式 Numerical methods by Chapra and canale and Numerical mathematics by chenny and kincaid.

所以我的数据是

x=[1.0,3.0,4.0,7.0]
y=[1.5,4.5,9.0,25.5]

使用此数据并应用三次样条我得到 x=1.5 , y=1.79122340426

虽然使用相同的数据但使用 scipy 函数给出:

  >>> scipy.interpolate.interp1d(x, y, kind='cubic')(1.5)
array(1.265624999999932)

那么,为什么结果会有所不同?很明显,他们没有使用相同的公式。 scipy 函数中使用的三次样条公式是什么?它是自然的三次样条公式还是经过改进的? 注意:1.2656这个值更准确。

编辑:@ev-br 在这个答案的评论中提供了对我的答案的重要更正。事实上 interp1D 样条不是基于 FITPACK 的。查看 @ev-br.

提供的 link 的评论

曲线拟合的Scipy函数是基于FITPACK的。尝试查看有关您正在使用的函数的文档,您将能够看到一个 "References" 章节,其中会出现如下内容:

Notes
-----
See splev for evaluation of the spline and its derivatives. Uses the
FORTRAN routine curfit from FITPACK.
If provided, knots `t` must satisfy the Schoenberg-Whitney conditions,
i.e., there must be a subset of data points ``x[j]`` such that
``t[j] < x[j] < t[j+k+1]``, for ``j=0, 1,...,n-k-2``.
References
----------
Based on algorithms described in [1]_, [2]_, [3]_, and [4]_:
.. [1] P. Dierckx, "An algorithm for smoothing, differentiation and
   integration of experimental data using spline functions",
   J.Comp.Appl.Maths 1 (1975) 165-184.
.. [2] P. Dierckx, "A fast algorithm for smoothing data on a rectangular
   grid while using spline functions", SIAM J.Numer.Anal. 19 (1982)
   1286-1304.
.. [3] P. Dierckx, "An improved algorithm for curve fitting with spline
   functions", report tw54, Dept. Computer Science,K.U. Leuven, 1981.
.. [4] P. Dierckx, "Curve and surface fitting with splines", Monographs on
   Numerical Analysis, Oxford University Press, 1993.

这些引用特别是从函数 "splrep" 的 fitpack.py 的源代码中获取的。如果您需要在您的算法和 interp1D 的样条曲线之间进行非常彻底的比较,请转到文档:

scipy.interpolate.interp1d

并且您会在函数名称定义之后看到一个名为 [source] 的 link(因此:scipy.interpolate.interp1D [source])。请记住,这些函数有很多例程处理程序,因此在浏览源代码时请耐心等待。