scipy.interpolate.make_interp_spline 如何检索所有系数?

2023-12-25

我有以下程序:

nknots = 4
x_i = [0, 1, 2, 3]
y_i = [1, np.exp(1), np.exp(2), np.exp(3)]
coeff = interpolate.make_interp_spline(x_i, y_i, bc_type="natural")

我想使用坐标由 x_i 和 y_i 数组给出的结构造三次样条。但是,我很难获得所有系数。三次样条函数具有以下形式:

y_i(x) = a + b*(x - x_i) + c*(x - x_i)^2 + d*(x - x_i)^3

当我做

print(coeff(x_i))

我只得到数组a values:

[ 1.          2.71828183  7.3890561  20.08553692]

但是,我缺少数组b, c, and d系数。我如何提取这些?或者我缺少什么步骤?我阅读了 make_interp_spline 上的 scipy 文档,但我不明白如何获取b, c and d系数。


我建议检查一下interpolate.CubicSpline https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.CubicSpline.html。如果你想要的是多项式系数,那就方便多了。使用您的变量:

spl = interpolate.CubicSpline( x_i, y_i )
spl.c

array([[-1.57973952e-01,  2.93118310e-01, -1.35144359e-01],
       [ 1.11022302e-16, -4.73921855e-01,  4.05433076e-01],
       [-3.01723742e-01, -7.75645598e-01, -8.44134377e-01],
       [ 1.00000000e+00,  5.40302306e-01, -4.16146837e-01]])

see the PPoly https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.PPoly.html#scipy.interpolate.PPoly有关如何存储分段多项式系数的文档。

附录: 它是possible从输出中提取系数make_interp_spline,但是这并不简单它需要@ev-br描述的额外步骤,因为“系数”B样条曲线(重点是 B)与多项式系数不同。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

scipy.interpolate.make_interp_spline 如何检索所有系数? 的相关文章

随机推荐