scipy.special.
spherical_kn#
- scipy.special.spherical_kn(n, z, derivative=False)[原始碼]#
第二類修正球貝索函數或其導數。
定義為 [1],
\[k_n(z) = \sqrt{\frac{\pi}{2z}} K_{n + 1/2}(z),\]其中 \(K_n\) 是第二類修正貝索函數。
- 參數:
- nint, array_like
貝索函數的階數 (n >= 0)。
- zcomplex 或 float, array_like
貝索函數的引數。
- derivativebool, optional
若為 True,則回傳導數的值(而非函數本身)。
- 回傳值:
- knndarray
註解
此函數使用其與第二類修正柱貝索函數的定義關係計算。
導數使用關係式 [2] 計算,
\[ \begin{align}\begin{aligned}k_n' = -k_{n-1} - \frac{n + 1}{z} k_n.\\k_0' = -k_1\end{aligned}\end{align} \]在 0.18.0 版本中新增。
參考文獻
[AS]Milton Abramowitz and Irene A. Stegun, eds. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. New York: Dover, 1972.
範例
第二類修正球貝索函數 \(k_n\) 接受實數和複數作為第二個引數。它們可以回傳複數類型
>>> from scipy.special import spherical_kn >>> spherical_kn(0, 3+5j) (0.012985785614001561+0.003354691603137546j) >>> type(spherical_kn(0, 3+5j)) <class 'numpy.complex128'>
我們可以驗證 \(n=3\) 在區間 \([1, 2]\) 中導數的關係式,從註解中得知
>>> import numpy as np >>> x = np.arange(1.0, 2.0, 0.01) >>> np.allclose(spherical_kn(3, x, True), ... - 4/x * spherical_kn(3, x) - spherical_kn(2, x)) True
前幾個帶有實數引數的 \(k_n\)
>>> import matplotlib.pyplot as plt >>> x = np.arange(0.0, 4.0, 0.01) >>> fig, ax = plt.subplots() >>> ax.set_ylim(0.0, 5.0) >>> ax.set_title(r'Modified spherical Bessel functions $k_n$') >>> for n in np.arange(0, 4): ... ax.plot(x, spherical_kn(n, x), label=rf'$k_{n}$') >>> plt.legend(loc='best') >>> plt.show()