gpt4 book ai didi

python - 使用三次样条插值时确保一阶和二阶微分是连续的

转载 作者:太空宇宙 更新时间:2023-11-04 01:28:21 25 4
gpt4 key购买 nike

我正在读这个 paper .在第286页的这篇论文中,他们说他们使用三次样条插值来确保连续的一阶微分和二阶微分的存在。

我目前正尝试在 python 中执行此操作。从这句话我推断他们想要确保彼此相邻的样条的一阶和二阶导数相同。我现在的问题是,我怎样才能用 scipy 做到这一点?我发现了这个:http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.splev.html

其中有一个参数der(要计算的样条的导数阶数)。那么这个参数就是2吗?


*A follow-up questio*n about this, they use the first-order differential points later.我可以假设这些只是每个样条的一阶导数吗?怎么可能得到这些?

最佳答案

scipy.interpolate 计算的 k 样条具有连续的 1 ... k-1:th 导数。对于您的情况,订单 k=3 将具有连续的一阶和二阶导数。您可以通过样条的数值微分自己检查这是否属实:

import numpy as npfrom scipy import interpolateimport matplotlib.pyplot as pltx = np.linspace(0, 10, 100)y = np.sin(x)spl = interpolate.splrep(x, y, k=3)xx = np.linspace(0, 10, 100000)yy = interpolate.splev(xx, spl)d1 = np.diff(yy) / np.diff(xx)d2 = np.diff(d1) / np.diff(xx[1:])d3 = np.diff(d2) / np.diff(xx[1:-1])plt.subplot(311)plt.plot(xx[1:], d1)plt.title('first derivative')plt.subplot(312)plt.plot(xx[1:-1], d2)plt.title('second derivative')plt.subplot(313)plt.plot(xx[2:-1], d3)plt.title('third derivative')plt.show()

三阶导数是第一个显示不连续性的导数。

二阶导数确实可以直接通过 splev(..., der=2) 完成。

(没有阅读论文,我无法评论你的第二个问题。)

关于python - 使用三次样条插值时确保一阶和二阶微分是连续的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15928129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com