The Legendre polynomials $P_n(x)$ are defined over the interval $[-1, 1]$ as the unique system of polynomials satisfying $ \int_{-1}^1 P_m(x)P_n(x)dx = 0,~m\neq n $ with the normalisation condition $P_n(1) = 1$. ## Rodrigues' Formula Legendre polynomials can be compactly expressed as $ P_n(x) = \frac{1}{2^n n!}\frac{d^n}{dx^n}(x^2-1)^n $ ## Recursive evaluation Legendre polynomials can be efficiently evaluated using the following recursion. $ (n+1)P_{n+1}(x) = (2n + 1)xP_n(x) - nP_{n-1}(x) $ The starting values are $P_0(x) = 1$ and $P_1(x) = x$. ## Normalisation It holds that $\|P_n\|_{L^2([-1, 1])} = \frac{1}{\sqrt{n + 1/2}}.$ One can hence define the normalised Legendre polynomials as $\overline{P_n} = \sqrt{n+1/2}P_n$. ## Evaluating the Legendre Series In practice we often need to evaluate the series $ S(x) = \sum_{j=0}^n \alpha_j P_j(x). $ One efficient way to do this is via the [[Clenshaw Algorithm]]. The following Python code gives an example implementation. ```Python def eval_legendre_series(xx, alpha): """Evaluate the first n + 1 terms of a Legendre series with coefficient vector alpha.""" npoints = xx.shape[0] degree = alpha.shape[0] - 1 bkp1 = np.zeros([npoints], dtype='float64') bkp2 = np.zeros([npoints], dtype='float64') for index in range(degree, 0, -1): bk = alpha[index] + (2 * index + 1) / (index + 1) * xx * bkp1 - (index + 1) / (index + 2) * bkp2 bkp2 = bkp1 bkp1 = bk return alpha[0] + xx * bkp1 - .5 * bkp2 ``` ## References - [Wikipedia Entry](https://en.wikipedia.org/wiki/Legendre_polynomials)