We are given:
$$\tag 1 f(x) = x^3$$
Legendre
Note: see my response here for the Legendre approach.
Using the method from the referenced approach, we find:
$$\tag 2 f(x) = x^3 = c_0P_0(x) + c_1P_1(x) + c_2P_2(x) = \frac{3}{5}P_1(x) + \frac{2}{5} P_3(x)$$
Please note that $(2)$ only has a finite number of terms as mentioned in the problem statement.
Fourier Sine Series
Note that since $f(-x) = -f(x)$, $(1)$ is an odd function and that is very helpful!
If a function is odd, then $a_n = 0$ and the Fourier sin series collapses to:
$$f(x) = \sum_{n=1}^\infty b_n~\sin(n x)$$
where
$$b_n = \frac{2}{\pi} \int_0^{\pi} f(x)~\sin(n x)~dx$$
However, the question wants us to extend the range to $L$, so we have:
$$b_n = \frac{2}{L} \int_0^{L} f(x)~\sin(\frac{n \pi x}{L})~dx$$
Lets calculate these terms:
$\displaystyle b_1 = \frac{2}{L} \int_0^{L} x^{3}~\sin(\frac{1 \pi x}{L})~dx = \frac{2 (\pi^2-6) L^3}{\pi^3}$
$\displaystyle b_2 = \frac{2}{L} \int_0^{L} x^{3}~\sin(\frac{2 \pi x}{L})~dx = -\frac{(2 \pi^2-3) L^3}{2 \pi^3}$
$\displaystyle b_3 = \frac{2}{L} \int_0^{L} x^{3}~\sin(\frac{3 \pi x}{L})~dx = \frac{2 (3 \pi^2-2) L^3}{9 \pi^3}$
$\ldots$
$\displaystyle b_n = \frac{2}{L} \int_0^{L} x^{3}~\sin(\frac{n \pi x}{L})~dx = -\frac{2 L^3 (\pi n (\pi^2 n^2-6) \cos(\pi n)-3 (\pi^2 n^2-2) \sin(\pi n))}{(\pi^4 n^4)}$
Please note that the Fourier sin series has an infinite number of terms as mentioned in the problem statement.
In the context of separation of variables, why is it important to understand both of these very different-looking series representations of a function?
Update to the last question
We have now written two very different ways to solve this problem (function). The first, based on the Legendre polynomials, provided a closed form solution, while the second is based on an infinite series Fourier analysis. These can aid us with different perspectives to solve separation of variable problems.
These two solutions are merely two facets of the same solution. The Fourier series formula shows how every piece-wise component of the solution can be decomposed into its constituent parts, while the Legendre approach demonstrates how all the components combine into a single solution.
Mathematically, both of these provide us with the ability to look at behaviors from a different perspective and are both very useful to analyze the behavior of the function (globally or component wise) and provide another tool in our tool-box for qualitative and quantitative analyses (do they converge, how fast, how large is the error $\ldots$).
Regards
Best Answer
As $f(x)$ itself is a Legendre polynomial, namely $P_1$, the expansion can directly be seen to be $$f(x) = x = 0\cdot P_0+1\cdot P_1+0\cdot P_2+0\cdot P_3+ \cdot\cdot\cdot$$ Formally, you could look at the Fourier-Legendre expansion defined for any $f(x)$ as follows: $$f(x)=\sum_{j=0}^\infty a_jP_j(x)$$ where the coefficients can be calculated from $$a_j=\frac{\int_{-1}^{+1} f(x)P_jdx}{\int_{-1}^{+1} P_j^2dx}$$ The integral $\int_{-1}^{+1} P_j^2dx$ is easily evaluated to be equal to $\frac{2}{2j+1}$, see for instance (Legendre Polynomials: proofs). Here, the other integral can be evaluated for $j=0$ and $j>=1$ separately as follows: $$\int_{-1}^{+1} f(x)P_0dx=\int_{-1}^{+1} xdx=0$$ and $$\int_{-1}^{+1} f(x)P_jdx=\int_{-1}^{+1} xP_jdx=\int_{-1}^{+1} \frac{(j+1)P_{j+1}+jP_{j-1}}{2j+1}dx$$ which equals zero for $j>=2$ because $\int_{-1}^{+1} P_jdx=0$ when $j>=1$, and only the term for $j=1$ evaluates to a non-zero-value: $$\int_{-1}^{+1} xP_1dx=\int_{-1}^{+1} \frac{2P_2+P_0}{3}=\int_{-1}^{+1} \frac{P_0}{3}=\int_{-1}^{+1} \frac{1}{3}=\frac{2}{3}$$ And thus the only non-zero coefficient is $$a_1=\frac{2/3}{2/3}=1$$ as expected.
Above use has been made of the recurrence formula $(n+1)P_{n+1}=(2n+1)xP_n−nP_{n−1}$ for which a proof can be found in (Legendre Equation Properties), and the fact that when $n\not =m$, then $P_n$ and $P_m$ are orthogonal, that is to say $\int_{-1}^{+1} P_nP_mdx=0$, with as special case $\int_{-1}^{+1} P_ndx=\int_{-1}^{+1} P_nP_0dx=0$ when $n\not=0$.
Of course, using this same orthogonality property and noting that $f(x)=x=P_1(x)$, you could derive immediately that $\int_{-1}^{+1} f(x)P_j(x)dx=\int_{-1}^{+1} P_1(x)P_j(x)dx=0$, thus also $a_j=0$, when $j\not=1$.