繁体   English   中英

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

[英]What algorithm used in interp1d function in scipy.interpolate

所以我正在为我的数值课程编写一个 python 程序,我不得不编写一个三次样条程序。 所以我实现了三次样条的公式,如Chapra 和 canale 的数值方法以及chenny 和 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 提供的链接的评论。

曲线拟合的 Scipy 函数基于 FITPACK。 尝试查看有关您正在使用的功能的文档,您将能够看到“参考”一章,其中会出现以下内容:

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.

这些参考特别是取自fitpack.py函数“splrep”的来源。 如果您需要对您的算法和来自 interp1D 的样条进行非常彻底的比较,请参阅文档:

scipy.interpolate.interp1d

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM