# Expansion in terms of legendre polynomial

Obtain the first three terms in the expansion of function in terms of legendre polynomial F(x) in a series of the form $$F(x) = \sum_{k=0}^{\infty} A_k P_k(x)$$ where $$F(x)=\{\cos(x) \text{ for } 0 \le x \le \pi/2 \$$$$0 \text{ for } \frac{\pi}{2} \le x \le \pi.\}$$

What I know is I have to use legendre's expansion formula i.e,$F(x) =\sum A_kP_k(x)$ where $-1≤x≤1$ But obviously I cannot use it directly because the range of $x$ differs. I have tried substituting $x=\cos(\theta)$ but no success so far.

Extended hint: As already noted in your almost identical question Legendre polynomials you should apply a linear transformation, because the Legendre polynomial have the orthogonality interval $[-1,1]$. With $x=\frac{\pi}{2}(t+1)$ and $t=\frac{2x}{\pi}-1,$ define $F(x)=:\tilde{F}(t).$ Now $\tilde{F}$ is defined on $[-1,1]$ and you can compute $$F(x)=\tilde{F}(t) = \sum A_k P_k(t)=\sum A_k P_k\left(\frac{2x}{\pi}-1\right)$$ with $$A_k=\frac{2k+1}{2}\int_{-1}^1 \tilde{F}(t) P_k(t) dt$$
If you use this approach and compute $A_0, \dots, A_3$, you get the following graphics with the original function $F(x)$ in red and the approximation in green:
• Yes of course, because your function is not defined for $x=-1$. The transformation associates $x=0 \leftrightarrow t=-1$ and $x=\pi \leftrightarrow t=1$. You should compute the expansion for $\tilde{F}(t), t\in[-1,1].$ – gammatester Sep 18 '17 at 15:08