scipy.special.

sh_legendre#

scipy.special.sh_legendre(n, monic=False)[源代码]#

平移勒让德多项式 (Shifted Legendre polynomial)。

定义为 \(P^*_n(x) = P_n(2x - 1)\),其中 \(P_n\) 为第 n 个勒让德多项式。

参数:
nint

多项式的次数。

monicbool, 可选

如果为 True,则将首项系数缩放为 1。默认值为 False

返回:
Porthopoly1d

平移勒让德多项式 (Shifted Legendre polynomial)。

附注

多项式 \(P^*_n\) 在区间 \([0, 1]\) 上关于权函数 1 正交。

示例

平移勒让德多项式 \(P_n^*\) 与非平移多项式 \(P_n\) 的关系为 \(P_n^*(x) = P_n(2x - 1)\)。我们可以在区间 \([0, 1]\) 上验证这一点。

>>> import numpy as np
>>> from scipy.special import sh_legendre, legendre
>>> from scipy.integrate import trapezoid
>>> x = np.arange(0.0, 1.0, 0.01)
>>> n = 3
>>> np.allclose(sh_legendre(n)(x), legendre(n)(2*x - 1))
True

多项式 \(P_n^*\) 满足通过在标准勒让德递推公式中进行变量代换 \(t = 2x - 1\) 所得的递推关系:

\[(n+1) P_{n+1}^*(x) = (2n+1)(2x-1)\,P_n^*(x) - n\,P_{n-1}^*(x).\]

这可以在 \([0, 1]\) 上针对 \(n = 3\) 轻松检验。

>>> n = 3
>>> x = np.linspace(0.0, 1.0, 101)
>>> lhs = (n + 1) * sh_legendre(n + 1)(x)
>>> rhs = (
...     (2*n + 1) * (2*x - 1) * sh_legendre(n)(x)
...     - n * sh_legendre(n - 1)(x)
... )
>>> np.allclose(lhs, rhs)
True

\([0,1]\) 上关于权函数 1 的正交性可以通过数值方法进行检验;例如,\(P_2^*\)\(P_3^*\) 是正交的。

>>> x = np.linspace(0.0, 1.0, 400)
>>> y = sh_legendre(2)(x) * sh_legendre(3)(x)
>>> np.isclose(trapezoid(y, x), 0.0, atol=1e-12)
True