scipy.interpolate.BSpline.

integrate#

BSpline.integrate(a, b, extrapolate=None)[source]#

計算 spline 的定積分。

參數:
afloat

積分下限。

bfloat

積分上限。

extrapolatebool 或 ‘periodic’, optional

是否外插超出基礎區間 t[k] .. t[-k-1],或者將 spline 視為在基礎區間外為零。如果為 ‘periodic’,則使用週期性外插。如果為 None (預設值),則使用 self.extrapolate

返回:
Iarray_like

spline 在區間 [a, b] 上的定積分。

範例

在基礎區間 \([0, 2]\) 上建構線性 spline x if x < 1 else 2 - x,並積分它

>>> from scipy.interpolate import BSpline
>>> b = BSpline.basis_element([0, 1, 2])
>>> b.integrate(0, 1)
array(0.5)

如果積分限制超出基礎區間,結果會由 extrapolate 參數控制

>>> b.integrate(-1, 1)
array(0.0)
>>> b.integrate(-1, 1, extrapolate=False)
array(0.5)
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.grid(True)
>>> ax.axvline(0, c='r', lw=5, alpha=0.5)  # base interval
>>> ax.axvline(2, c='r', lw=5, alpha=0.5)
>>> xx = [-1, 1, 2]
>>> ax.plot(xx, b(xx))
>>> plt.show()
../../_images/scipy-interpolate-BSpline-integrate-1.png