scipy.special.legendre

scipy.special.legendre(n, monic=False)[source]

Legendre polynomial.

Defined to be the solution of

\[\frac{d}{dx}\left[(1 - x^2)\frac{d}{dx}P_n(x)\right] + n(n + 1)P_n(x) = 0;\]

\(P_n(x)\) is a polynomial of degree \(n\).

Parameters
nint

Degree of the polynomial.

monicbool, optional

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

Returns
Porthopoly1d

Legendre polynomial.

Notes

The polynomials \(P_n\) are orthogonal over \([-1, 1]\) with weight function 1.

Examples

Generate the 3rd-order Legendre polynomial 1/2*(5x^3 + 0x^2 - 3x + 0):

>>> from scipy.special import legendre
>>> legendre(3)
poly1d([ 2.5,  0. , -1.5,  0. ])