Skip to content
fn

legendre_polynomial_p

→Tensor
legendre_polynomial_p(x: TensorOrScalar, n: TensorOrScalar)

Legendre polynomial Pn(x)P_n(x).

The Legendre polynomials are orthogonal on [−1,1][-1, 1] with uniform weight, and serve as the angular eigenfunctions of the Laplacian on the sphere (spherical harmonics with m=0m = 0) and as a basis for Gauss-Legendre quadrature.

Parameters

xTensor | Scalar
Where PnP_n is evaluated, of any real dtype. Customarily on [−1,1][-1, 1].
nTensor | Scalar
Degree of PnP_n, for every element or one per element; truncated toward zero, and a negative degree gives 0.

Returns

Tensor

Pn(x)P_n(x) element-wise, broadcast over x and n.

Notes

Bonnet recurrence:

P0(x)=1,P1(x)=x,(k+1) Pk+1(x)=(2k+1) x Pk(x)−k Pk−1(x).P_0(x) = 1, \quad P_1(x) = x, \quad (k+1)\, P_{k+1}(x) = (2k + 1)\, x\, P_k(x) - k\, P_{k-1}(x).

On [−1,1][-1, 1], ∣Pn(x)∣≤1|P_n(x)| \le 1 with boundary values Pn(1)=1P_n(1) = 1, Pn(−1)=(−1)nP_n(-1) = (-1)^n.

Examples

>>> import lucid
>>> from lucid.special import legendre_polynomial_p
>>> legendre_polynomial_p(lucid.tensor([-1.0, 0.0, 0.5, 1.0]), n=3)
tensor([-1., -0., -0.4375, 1.])

Used by 1