gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:38 25 4
gpt4 key购买 nike

所以我正在为我的数值类(class)编写一个Python程序,并且我必须编写一个三次样条程序。所以我实现了像Numerical methods by Chapra and canale这样的书中给出的三次样条公式和 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.5y=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 [来源])。请记住,这些函数有很多例程处理程序,因此在浏览源代码时要有耐心。

关于python - scipy.interpolate 中的 interp1d 函数使用什么算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36088340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com