我已经在Python中完成了一些工作,但我是scipy
的新手。我试图使用interpolate
库中的方法来创建一个近似于一组数据的函数。获取由scipy创建的插值函数的公式
我查阅了一些例子上手,并且可以得到以下Python(x,y)工作示例代码:
import numpy as np
from scipy.interpolate import interp1d, Rbf
import pylab as P
# show the plot (empty for now)
P.clf()
P.show()
# generate random input data
original_data = np.linspace(0, 1, 10)
# random noise to be added to the data
noise = (np.random.random(10)*2 - 1) * 1e-1
# calculate f(x)=sin(2*PI*x)+noise
f_original_data = np.sin(2 * np.pi * original_data) + noise
# create interpolator
rbf_interp = Rbf(original_data, f_original_data, function='gaussian')
# Create new sample data (for input), calculate f(x)
#using different interpolation methods
new_sample_data = np.linspace(0, 1, 50)
rbf_new_sample_data = rbf_interp(new_sample_data)
# draw all results to compare
P.plot(original_data, f_original_data, 'o', ms=6, label='f_original_data')
P.plot(new_sample_data, rbf_new_sample_data, label='Rbf interp')
P.legend()
该地块显示如下:
现在,是否有任何方法可以获得表示由Rbf
创建的插值函数的多项式表达式(即创建为rbf_interp
的方法)?
或者,如果Rbf
不可能,那么也欢迎使用不同插值方法,另一个库或甚至不同工具的建议。
看看'scipy.interpolate.Rbf'和'scipy.interpolate'模块的文档,我看不到任何与你想要的相关的东西。我能想到的唯一方法是阅读源代码并了解如何根据参数创建函数,然后编写能够返回可读表示的拥有函数。但这取决于实施细节。即使我看不到你如何消除这一点。 – Bakuriu
考虑两个步骤:数据 - >曲线(通过Rbf或其他),然后曲线 - >分段多项式:样条。保存样条参数很容易,(npiece + 1)* 4 - 进一步询问您是否想要这样做。 – denis