# (Should be easy) Legendre polynomial integration debugging

I am trying to evaluate the following integral:

$$I_n=\int\limits_{-1}^1 f(x)P_n(x)dx$$ where $f(x)=1$ for $x\in[-1,0)$ and $f(x)=-1$ for $x\in(0,1]$ and $P_n(x)$ is the Legendre polynomial of degree n.

What I did (which is most probably wrong):

Argue that $I_n=0$ for all even n since $P_{even \,\,\, n}$ is symmetric along $x=0$. But then when I tried to evaluate the odd $n$'s , I get $I_n=2\int\limits_{-1}^0 P_n(x) dx=2\int\limits_{-1}^0 P'_{n+1}(x) -P'_{n-1}(x)dx=0$??

Thanks for helping!

-

The Legendre polynomials satisfy $(2n+1)P_n(x)=P'_{n+1}(x)-P'_{n-1}(x)$, and $P_n(-1)=(-1)^n$, so for odd $n$ we have:

$$\begin{eqnarray} I_n&=&2\int_{-1}^0 P_n(x)dx\\ &=&\frac{2}{2n+1}\left[ (P_{n+1}(0)-P_{n-1}(0)) - (P_{n+1}(-1)-P_{n-1}(-1)) \right] \\ &=&\frac{2}{2n+1}(P_{n+1}(0)-P_{n-1}(0))\end{eqnarray}$$ But for odd $n$, $P_{n+1}(0)\ne P_{n-1}(0)$, so $I_n \ne 0$.

-
Also, for the only even $n = 0$, it yields $2$. – Felix Marin Jan 28 '14 at 1:57

Well, your $f(x)$ is odd, and Legendre polynomials are even for even $n$ and odd for odd $n$. The product of an even and an odd function is odd (so your integral should indeed be zero in that case), but the product of two odd functions is even. So...

-

We have \begin{align*}\int_0^1P_n(x)dx&=-\frac 1{n(n+1)}\int_0^1\frac{d }{dx}\left((1-x^2)\frac d{dx}P_n(x)\right)dx\\ &=-\frac 1{n(n+1)}\left[(1-x^2)\frac d{dx}P_n(x)\right]_{x=0}^{x=1}\\ &=\frac 1{n(n+1)}P_n'(0). \end{align*} Thanks to the formula $P_n(x)=\frac 1{2^nn!}\frac{d^n}{dx^n}(1-x^2)^n$, we get that $P_n'(0)=P_{n-1}(0)$ for all $n$. Since $P_n(0)=\frac 1{2^n}\sum_{k=0}^n(-1)^k\binom nk^2$, we finally find that $I_{2p}=0$ for all $p$ and $$I_{2p+1}=\frac 1{(2p+1)(2p+2)2^{2p}}\sum_{k=0}^{2p}(-1)^k\binom{2p}k^2.$$

-

$\newcommand{\+}{^{\dagger}}% \newcommand{\angles}[1]{\left\langle #1 \right\rangle}% \newcommand{\braces}[1]{\left\lbrace #1 \right\rbrace}% \newcommand{\bracks}[1]{\left\lbrack #1 \right\rbrack}% \newcommand{\ceil}[1]{\,\left\lceil #1 \right\rceil\,}% \newcommand{\dd}{{\rm d}}% \newcommand{\down}{\downarrow}% \newcommand{\ds}[1]{\displaystyle{#1}}% \newcommand{\equalby}[1]{{#1 \atop {= \atop \vphantom{\huge A}}}}% \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}% \newcommand{\fermi}{\,{\rm f}}% \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}% \newcommand{\half}{{1 \over 2}}% \newcommand{\ic}{{\rm i}}% \newcommand{\iff}{\Longleftrightarrow} \newcommand{\imp}{\Longrightarrow}% \newcommand{\isdiv}{\,\left.\right\vert\,}% \newcommand{\ket}[1]{\left\vert #1\right\rangle}% \newcommand{\ol}[1]{\overline{#1}}% \newcommand{\pars}[1]{\left( #1 \right)}% \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\pp}{{\cal P}}% \newcommand{\root}[2][]{\,\sqrt[#1]{\,#2\,}\,}% \newcommand{\sech}{\,{\rm sech}}% \newcommand{\sgn}{\,{\rm sgn}}% \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}} \newcommand{\ul}[1]{\underline{#1}}% \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}$ \begin{align} \sum_{\ell = 0}^{\infty}h^{\ell}\int_{-1}^{0}{\rm P}_{\ell}\pars{x} &=\int_{-1}^{0}{\dd x \over \root{1 - 2xh + h^{2}}} =\left.{\root{1 - 2xh + h^{2}} \over -h}\right\vert_{x\ =\ 0}^{x\ =\ 1} ={1 \over h}\bracks{\root{1 + h^{2}} - 1 + h} \\[3mm]&={1 \over h}\bracks{\sum_{\ell = 0}^{\infty} {1/2 \choose \ell}h^{2\ell} - 1 + h}= 1 + \sum_{\ell = 1}^{\infty} {1/2 \choose \ell}h^{2\ell - 1} \end{align}

\begin{align} {1/2 \choose \ell} &= {\Gamma\pars{3/2} \over \ell!\,\Gamma\pars{3/2 - \ell}} = {\root{\pi} \over 2}\,{1 \over \ell!\,\Gamma\pars{3/2 - \ell}} \\[3mm]&= {\root{\pi} \over 2}\, {1 \over \ell!\braces{\pi/\bracks{\Gamma\pars{\ell - 1/2}} \sin\pars{\pi\bracks{\ell - 1/2}}}} = {1 \over 2\root{\pi}}\, {\pars{-1}^{\ell + 1}\Gamma\pars{\ell - 1/2} \over \ell!} \\[2mm]&= {1 \over \root{\pi}}\, {\pars{-1}^{\ell + 1}\Gamma\pars{\ell + 1/2} \over \pars{2\ell - 1}\ell!} = {1 \over \root{\pi}}\, {\pars{-1}^{\ell + 1} \over \pars{2\ell - 1}\ell!}\, {\Gamma\pars{2\ell}\root{\pi} \over 2^{2\ell - 1}\Gamma\pars{\ell}} \\[3mm]&= {\pars{-1}^{\ell + 1} \over \pars{2\ell - 1}\ell!}\, {\pars{2\ell - 1}! \over 2^{2\ell - 1}\pars{\ell - 1}!} \end{align}

$$\color{#00f}{\large\left\lbrace% \begin{array}{rcl} \int_{-1}^{0}{\rm P}_{0}\pars{x}\,\dd x & = & 1 \\[2mm] \int_{-1}^{0}{\rm P}_{2\ell - 1}\pars{x}\,\dd x & = & \pars{-1}^{\ell + 1}\, {2^{-\pars{2\ell - 1}} \over 2\ell - 1}\,{2\ell - 1 \choose \ell}\,,\quad \ell = 1,2,3,\ldots \\[2mm] && 0\ \mbox{otherwise} \end{array}\right.}$$

-