Scipy.interpolate.make_interp_Spline如何检索所有系数? [英] scipy.interpolate.make_interp_spline how to retrieve all the coefficients?

查看:0
本文介绍了Scipy.interpolate.make_interp_Spline如何检索所有系数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下程序:

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值的数组:

[ 1.          2.71828183  7.3890561  20.08553692]

但是,我缺少bcd系数的数组。我怎么才能提取出来呢?或者是我遗漏了什么步骤?我阅读了有关make_interp_Spline的Scipy文档,但我不了解如何获取bcd系数。

推荐答案

我建议您查看interpolate.CubicSpline。如果你想要的是多项式系数,那就方便多了。使用您的变量:

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]])

有关分段多项式系数的存储方式,请参阅PPoly文档。

附录: 可以make_interp_spline的输出中提取系数,但不是直接的它需要@ev-br描述的额外步骤,因为B样条线的系数和多项式系数不同。

这篇关于Scipy.interpolate.make_interp_Spline如何检索所有系数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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