How do I express $$f(x)=\sin \frac{\pi x}{L} \quad ,0\le x\le L$$ in the form $$f(x)=c_0+\sum_{n=1}^{\infty}c_n\cos \frac{2\pi n x}{L}$$
The simplest approach would be to take the Half-range cosine expansion:
$$c_0=\frac{1}{L}\int_{0}^{L}f(x)dx=\frac{1}{L}\int_{0}^{L}\sin \frac{\pi x}{L}dx=\frac{2}{\pi}$$
$$c_n=\frac{2}{L}\int_{0}^{L}f(x)\cos \frac{n\pi x}{L}dx=\frac{2}{L}\int_{0}^{L}\sin \frac{\pi x}{L}\cos \frac{n\pi x}{L}dx=\frac{2}{(n^2-1)\pi}(1+(-1)^{n-1})$$
But, the problem is Half-range cosine expansion is of the form: $$f(x)=c_0+\sum_{n=1}^{\infty}c_n\cos \frac{\pi *\textbf{n x}}{L}$$ and not:
$$f(x)=c_0+\sum_{n=1}^{\infty}c_n\cos \frac{\textbf{2}\pi *n x}{L}$$
So, is there any other way of Fourier series expansion to express my function in the desired form?
First of all, half range cosine series is used for even functions. Clearly, $\sin\left(\frac{\pi x}{L}\right)$ is not even in $-L\le x\le L $ (It's odd).
So we have to use either Fourier full-range series or half-range sine series.
1) Fourier half-range sine series.
So, $$ \sin\left(\frac{\pi x}{L}\right) = \sum_{n=1}^\infty b_n \sin\left(\frac{n\pi x}{L}\right)$$ $$b_n = \frac2L\int_0^L\sin\left(\frac{\pi x}{L}\right)\sin\left(\frac{n\pi x}{L}\right)dx =\frac 2{\pi(1-n^2)}\sin(n\pi) = 0 , (n\ne1)$$
$$b_1 =\frac2L\int_0^L\sin\left(\frac{\pi x}{L}\right)\sin\left(\frac{\pi x}{L}\right)dx =1$$
This one can't be expressed in the required way as in this case we'd again get $$\sum_{n=1}^\infty b_n \sin\left(\frac{n\pi x}{L}\right) = b_1 \sin\left(\frac{1\cdot\pi x}{L}\right) =\sin\left(\frac{\pi x}{L}\right) $$
So, we've to use the formula of Fourier full range series.
2) Fourier full range series.
$$f(x) = \frac{a_0}2 + \sum_{n=1}^\infty a_n \cos\left(\frac{n\pi x}{k}\right) +\sum_{n=1}^\infty b_n \sin\left(\frac{n\pi x}{k}\right)$$
for $f(x)$ defined for $0\le x\le 2k$.
Here, we have $2k = L \Rightarrow k = \frac L2$
So,
$$f(x) = \frac{a_0}2 + \sum_{n=1}^\infty a_n \cos\left(\frac{2n\pi x}{L}\right) +\sum_{n=1}^\infty b_n \sin\left(\frac{2n\pi x}{L}\right)$$
$$a_0 = \frac 2L\int_0^L \sin\left(\frac{\pi x}{L}\right)dx = \frac 4\pi$$
$$a_n = \frac 2L\int_0^L \sin\left(\frac{\pi x}{L}\right)\cos\left(\frac{2n\pi x}{L}\right)dx = \frac{2}{\pi(1-4n^2)}(1+\cos(2n\pi)) = \frac{4}{\pi(1-4n^2)}$$
$$b_n=\frac 2L\int_0^L \sin\left(\frac{\pi x}{L}\right)\sin\left(\frac{2n\pi x}{L}\right)dx =\frac{2}{\pi(1-4n^2)}(\sin(2n\pi))=0$$
Finally, let $c_ 0 = \frac{a_ 0}2 = \frac 2\pi$
$c_n = a_n = \frac{4}{\pi(4n^2-1)}$
So,
$$\sin\left(\frac{\pi x}{L}\right) = c_0 + \sum_{n=1}^\infty c_n \cos\left(\frac{2n\pi x}{L}\right)$$