Expand function in Legendre polynomials on the interval [-1,1] Expand the following function in Legendre polynomials on the interval [-1,1] :
$$f(x) = |x|$$
The Legendre polynomials $p_n (x)$ are defined by the formula :
$$p_n (x) = \frac {1}{2^n n!} \frac{d^n}{dx^n}(x^2-1)^2$$
for $n=0,1,2,3,...$
My attempt :
we have using the fact that $|x|$ is an even function.
$$a_0 = \frac {2}{\pi}$$
$$ a_n= \frac {2}{π} \int_{-1}^{1}x\cos(nx)\,dx$$
Then what is the next step ?
 A: We know that the Fourier-Legendre series is like 
$$
f(x)=\sum_{n=0}^\infty C_n P_n(x)
$$
where 
$$
C_n=\frac{2n+1}{2} \int_{-1}^{1}f(x)P_n(x)\,dx
$$
So now we are going to calculate the result of 
$$
\frac{2n+1}{2} \int_{-1}^{1}|x|P_n(x)\,dx
$$
As $|x|$ is an even function, and the parity of $P_n(x)$ depends on the parity of $n$, We can write
$$
\int_{-1}^{1}|x|P_n(x)\,dx
$$
as
$$
\int_{-1}^{1}|x|P_{2k}(x)\,dx\ \ k=0,1,2...
$$
and
$$
\int_{-1}^{1}|x|P_{2k}(x)\,dx \\
=\int_{-1}^{0}-xP_{2k}(x)\,dx + \int_{0}^{1}xP_{2k}(x)\,dx\\
=2\int_{0}^{1}xP_{2k}(x)\,dx
$$
As
$$
(n+1)P_{n+1}(x)-x(2n+1)P_{n}(x)+nP_{n-1}(x)=0
$$
we get
$$
2\int_{0}^{1}xP_{2k}(x)\,dx\\
=2(\frac{2k+1}{4k+1}\int_{0}^{1}P_{2k+1}(x)\,dx+\frac{2k}{4k+1}\int_{0}^{1}P_{2k-1}(x)\,dx)
$$
As 
$$
\int_{0}^{1}P_{n}(x)\,dx=\begin{cases}
0& n=2k\\
\frac{(-1)^k (2k-1)!!}{(2k+2)!!}& n=2k+1
\end{cases}
$$
We get
$$
C_{2k}=(2k+1)\frac{(-1)^k (2k-1)!!}{(2k+2)!!}+n\frac{(-1)^{k-1} (2k-3)!!}{(2k)!!}\\
=\begin{cases}
\frac{1}{2}& k=0\\
\frac{(-1)^{k+1} (4k+1)}{2^{2k}(k-1)!}\frac{(2k-2)!}{(k+1)!}& k>0
\end{cases}
$$
So
$$
|x|=\frac{1}{2}+\sum_{k=1}^\infty \frac{(-1)^{k+1} (4k+1)}{2^{2k}(k-1)!}\frac{(2k-2)!}{(k+1)!} P_{2k}(x)
$$
A: You are being asked to compute the coefficients $a_n$ in the expansion
$$
f(x)=\sum_{n=0}^\infty a_n P_n(x)
$$
See for example here for more information.
Another very useful reference (in general) is Abramowitz and Stegun's Handbook of Mathematical Functions where you will find chapters on Legendre functions and orthogonal polynomials.
