scipy.interpolate.

spalde#

scipy.interpolate.spalde(x, tck)[source]#

在一個點(或一組點)評估 B 樣條及其所有導數,階數最高為 k(樣條的次數),其中 0 階導數為樣條本身。

舊版

此函數被視為舊版,將不再接收更新。雖然我們目前沒有移除它的計劃,但我們建議新程式碼改用更現代的替代方案。具體來說,我們建議建構一個 BSpline 物件,並在迴圈或列表理解式中評估其導數。

參數:
xarray_like

要在其上評估導數的一個點或一組點。 請注意,對於每個 x,必須滿足 t(k) <= x <= t(n-k+1)

tcktuple

一個元組 (t,c,k),包含節點向量、B 樣條係數以及要計算其導數的樣條次數。

回傳值:
results{ndarray, ndarray 列表}

一個陣列(或陣列列表),包含每個點 x 的所有導數,階數最高為 k(包含 k),其中第一個元素是樣條本身。

參考文獻

[1]

de Boor C : On calculating with b-splines, J. Approximation Theory 6 (1972) 50-62.

[2]

Cox M.G. : The numerical evaluation of b-splines, J. Inst. Maths applics 10 (1972) 134-149.

[3]

Dierckx P. : Curve and surface fitting with splines, Monographs on Numerical Analysis, Oxford University Press, 1993.

範例

有多種方法可以計算 B 樣條的導數。 在此範例中,我們將示範 spalde 等同於呼叫 splevsplder

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.interpolate import BSpline, spalde, splder, splev
>>> # Store characteristic parameters of a B-spline
>>> tck = ((-2, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2),  # knots
...        (0, 0, 0, 6, 0, 0, 0),  # coefficients
...        3)  # degree (cubic)
>>> # Instance a B-spline object
>>> # `BSpline` objects are preferred, except for spalde()
>>> bspl = BSpline(tck[0], tck[1], tck[2])
>>> # Generate extra points to get a smooth curve
>>> x = np.linspace(min(tck[0]), max(tck[0]), 100)

評估曲線和所有導數

>>> # The order of derivative must be less or equal to k, the degree of the spline
>>> # Method 1: spalde()
>>> f1_y_bsplin = [spalde(i, tck)[0] for i in x ]  # The B-spline itself
>>> f1_y_deriv1 = [spalde(i, tck)[1] for i in x ]  # 1st derivative
>>> f1_y_deriv2 = [spalde(i, tck)[2] for i in x ]  # 2nd derivative
>>> f1_y_deriv3 = [spalde(i, tck)[3] for i in x ]  # 3rd derivative
>>> # You can reach the same result by using `splev`and `splder`
>>> f2_y_deriv3 = splev(x, bspl, der=3)
>>> f3_y_deriv3 = splder(bspl, n=3)(x)
>>> # Generate a figure with three axes for graphic comparison
>>> fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(16, 5))
>>> suptitle = fig.suptitle(f'Evaluate a B-spline and all derivatives')
>>> # Plot B-spline and all derivatives using the three methods
>>> orders = range(4)
>>> linetypes = ['-', '--', '-.', ':']
>>> labels = ['B-Spline', '1st deriv.', '2nd deriv.', '3rd deriv.']
>>> functions = ['splev()', 'splder()', 'spalde()']
>>> for order, linetype, label in zip(orders, linetypes, labels):
...     ax1.plot(x, splev(x, bspl, der=order), linetype, label=label)
...     ax2.plot(x, splder(bspl, n=order)(x), linetype, label=label)
...     ax3.plot(x, [spalde(i, tck)[order] for i in x], linetype, label=label)
>>> for ax, function in zip((ax1, ax2, ax3), functions):
...     ax.set_title(function)
...     ax.legend()
>>> plt.tight_layout()
>>> plt.show()
../../_images/scipy-interpolate-spalde-1.png