scipy.interpolate 中的 interp1d 函数使用什么算法 [英] What algorithm used in interp1d function in scipy.interpolate

查看:175
本文介绍了scipy.interpolate 中的 interp1d 函数使用什么算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在为我的数值课程编写一个 python 程序,我不得不编写一个三次样条程序.所以我实现了像 数值方法这样的书中给出的三次样条公式作者:Chapra 和 canale数值数学,作者:chenny 和金凯德.

So i was writing a python program for my numerical course, and I had to code a cubic spline program. So i implement the formula for cubic spline given in books like 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

Using this data and applying cubic spline I get for x=1.5 , y=1.79122340426

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

While using this same data but using the scipy function gives:

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

那么,为什么结果会有这种差异?很明显,他们没有使用相同的公式.该 scipy 函数中使用的三次样条公式是什么?它是自然三次样条公式还是改进的东西?注意:值 1.2656 更准确.

So, why is that difference in result? It is obvious that they are not using the same formula. What is the cubic spline formula used in that scipy function? Is it a natural cubic spline formula or something improved? Note: The value 1.2656 is more acurate.

推荐答案

此答案的评论中的 @ev-br 对我的答案进行了重要更正.实际上 interp1D 样条不是基于 FITPACK 的.检查@ev-br 提供的链接的评论.

@ev-br in the comments for this answer provided an important correction to my answer. In fact interp1D spline is not FITPACK based. Check the comments for the link provided by @ev-br.

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

The Scipy functions for curve fitting are based on FITPACK. Try seeing the documentation on the functions you are using and you'll be able to see a "References" chapter where something like this will appear:

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 的样条进行非常彻底的比较,请参阅文档:

These references in particular where taken from the source of fitpack.py on the function "splrep". If you need to do a very thorough comparison between your algorithm and the spline from interp1D just go to the docs:

scipy.interpolate.interp1d

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

And you'll see a link called [source] right after the definition of the name of the function (so: scipy.interpolate.interp1D [source]). Remember that there's a lot of routine handlers on these functions so be patient while navigating the source.

这篇关于scipy.interpolate 中的 interp1d 函数使用什么算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆