0

我试图在 SciPy 中插值后获得一组中间点。但似乎没有任何直接的方法可以做到这一点。任何人都可以帮忙吗?

示例代码:

from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
x = np.arange(10)
y = np.sin(x)
cs = CubicSpline(x, y)
xs = np.arange(-0.5, 9.6, 0.1)
plt.figure(figsize=(6.5, 4))
plt.plot(x, y, 'o', label='data')
plt.plot(xs, np.sin(xs), label='true')
plt.plot(xs, cs(xs), label="S")
plt.plot(xs, cs(xs, 1), label="S'")
plt.plot(xs, cs(xs, 2), label="S''")
plt.plot(xs, cs(xs, 3), label="S'''")
plt.xlim(-0.5, 9.5)
plt.legend(loc='lower left', ncol=2)
plt.show()
4

1 回答 1

2

正如CubicSpline 文档所说,它返回的对象是可调用的,带有参数

  • x : array_like
    计算插值的点。
  • nu : int,可选
    的要评估的导数顺序。
  • 推断:{bool,'周期性',无},可选

因此,cs(5)给出样条曲线在 5 处的值,而 cs(5, 2)它的二阶导数在 5 处,依此类推。

于 2017-10-02T16:04:12.750 回答