python中插值多项式的积分函数
我有一组点,在这些点上我使用了scipy来计算插值多项式。我希望得到该函数的原语python中插值多项式的积分函数,python,numpy,scipy,integral,Python,Numpy,Scipy,Integral,我有一组点,在这些点上我使用了scipy来计算插值多项式。我希望得到该函数的原语 self.p=interpolate.interp1d(self.__discreteDistribution['x'], self.__discreteDistribution['y'], kind='cubic') 我可以很容易地使用scipy计算区间上积分的值,使用 integrate.quad(self.p, 0, max) 相反,我想要的是self.p()的原语。 我已经找到了辛,但我没有插值多项式的
self.p=interpolate.interp1d(self.__discreteDistribution['x'], self.__discreteDistribution['y'], kind='cubic')
我可以很容易地使用scipy计算区间上积分的值,使用
integrate.quad(self.p, 0, max)
相反,我想要的是self.p()的原语。
我已经找到了辛,但我没有插值多项式的分析版本
在这种情况下,您会怎么做?该
interp1d方法
似乎只是为插值函数提供了一个函数对象,它允许您计算任意函数值
查看文档,我没有看到与内部表示的接口。
我猜这是一个分段定义的三次多项式的和。
在这种情况下,你的本原是一个分段定义的二次多项式的和。那对你真的有用吗
除了直接计算样条曲线(正如askewchan在评论中所建议的那样),您还可以尝试使用函数值和
approxist_taylor\u polymone
()对每个子区间上的poly1d
(doc)对象进行重采样,然后使用poly1d.integ
()在每个子区间上获得一个基元的系数 那interp1d方法
似乎只是为插值函数提供了一个函数对象,它允许您计算任意函数值
查看文档,我没有看到与内部表示的接口。
我猜这是一个分段定义的三次多项式的和。
在这种情况下,你的本原是一个分段定义的二次多项式的和。那对你真的有用吗
除了直接计算样条曲线(正如askewchan在评论中所建议的那样),您还可以尝试使用函数值和
approxist_taylor\u polymone
()对每个子区间上的poly1d
(doc)对象进行重采样,然后使用poly1d.integ
()在每个子区间上获得一个基元的系数 假设您使用的是分段插值器(与全局多项式插值相反),使用scipy有几种方法:
方法1:单变量样本
In [1]: import numpy as np
In [2]: x = np.arange(8)
In [3]: y = x
In [4]: from scipy.interpolate import interp1d
In [5]: from scipy.interpolate import interp1d, UnivariateSpline
In [6]: spl = UnivariateSpline(x, y, s=0)
In [7]: spl.<TAB>
spl.antiderivative spl.get_coeffs spl.roots
spl.derivative spl.get_knots spl.set_smoothing_factor
spl.derivatives spl.get_residual
spl.ext spl.integral
In [8]: spl.integral(0, 1)
Out[8]: 0.5000000000000001
方法2:splev、SPLEP和夹板
In [13]: from scipy.interpolate import splev, splint, splrep
In [14]: tck = splrep(x, y, s=0)
In [15]: splint(0, 1, tck)
Out[15]: 0.5000000000000001
这相当于使用单变量样条线,只是接口有点不同。详见文档
方法3:interp1d
在引擎盖下,interp1d
也使用b样条曲线(除非您要求kind='linear'或'nearest'),但求值例程不同。
interp1d
构造一个可调用函数,然后将其馈送给通用积分器
In [18]: from scipy.interpolate import interp1d
In [19]: interp = interp1d(x, y, kind='cubic')
In [20]: from scipy.integrate import quad
In [21]: quad(interp, 0, 1)
Out[21]: (0.5000000000000024, 5.5511151231258095e-15)
同样,要注意越界值:由interp1d构造的结果的行为不是很有用(即使它在某种程度上是可控的) 假设您使用的是分段插值器(与全局多项式插值相反),使用scipy有几种方法: 方法1:单变量样本
In [1]: import numpy as np
In [2]: x = np.arange(8)
In [3]: y = x
In [4]: from scipy.interpolate import interp1d
In [5]: from scipy.interpolate import interp1d, UnivariateSpline
In [6]: spl = UnivariateSpline(x, y, s=0)
In [7]: spl.<TAB>
spl.antiderivative spl.get_coeffs spl.roots
spl.derivative spl.get_knots spl.set_smoothing_factor
spl.derivatives spl.get_residual
spl.ext spl.integral
In [8]: spl.integral(0, 1)
Out[8]: 0.5000000000000001
方法2:splev、SPLEP和夹板
In [13]: from scipy.interpolate import splev, splint, splrep
In [14]: tck = splrep(x, y, s=0)
In [15]: splint(0, 1, tck)
Out[15]: 0.5000000000000001
这相当于使用单变量样条线,只是接口有点不同。详见文档
方法3:interp1d
在引擎盖下,interp1d
也使用b样条曲线(除非您要求kind='linear'或'nearest'),但求值例程不同。
interp1d
构造一个可调用函数,然后将其馈送给通用积分器
In [18]: from scipy.interpolate import interp1d
In [19]: interp = interp1d(x, y, kind='cubic')
In [20]: from scipy.integrate import quad
In [21]: quad(interp, 0, 1)
Out[21]: (0.5000000000000024, 5.5511151231258095e-15)
同样,要注意越界值:由interp1d构造的结果的行为不是很有用(即使它在某种程度上是可控的) 这个物体将基于一个。要访问该样条曲线的参数(节点和系数),最好直接使用样条曲线,使用
interpolate.UnivariateSpline
或interpolate.splrep
,而不是interp1d
。您想要什么形式的输出?一个多项式,还是要样条曲线?您需要使用我上面提到的函数的帮助吗?嗯,这个对象将基于一个。要访问该样条曲线的参数(节点和系数),最好直接使用样条曲线,使用interpolate.UnivariateSpline
或interpolate.splrep
,而不是interp1d
。您想要什么形式的输出?一个多项式,还是要样条曲线?使用我上面提到的函数需要帮助吗?