Skip to main content
`Ctrl`+`K`
scipy.special.

# sh_legendre

scipy.special.sh_legendre(n, monic=False)

  Shifted Legendre polynomial.

  Defined as \(P^*_n(x) = P_n(2x - 1)\) for \(P_n\) the nth Legendre polynomial.

  Parameters:
    n int

      Degree of the polynomial.

    monic bool, optional

      If True, scale the leading coefficient to be 1. Default is False.

  Returns:
    P orthopoly1d

      Shifted Legendre polynomial.

  See also

  `scipy.special.legendre`
  `scipy.special.roots_sh_legendre`

  Notes

  The polynomials \(P^*_n\) are orthogonal over \([0, 1]\) with weight function 1.

  Examples

  The shifted Legendre polynomials \(P_n^*\) are related to the non-shifted polynomials \(P_n\) by \(P_n^*(x) = P_n(2x - 1)\). We can verify this on the interval \([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

  The polynomials \(P_n^*\) satisfy a recurrence relation obtained by the change of variables \(t = 2x - 1\) in the standard Legendre recurrence:

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

  This can be easily checked on \([0, 1]\) for \(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

  Orthogonality over \([0,1]\) with weight 1 can be checked numerically; for example, \(P_2^*\) is orthogonal to \(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