# (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$.

-

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.$$

-

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...

-