[Math] Finding Fourier cosine series of sine function

eigenfunctionsfourier analysisfourier series

I am trying to find Fourier cosine series of following function, but think that I am messing up somewhere.

$$
f(x)=\sin \bigg ( \frac{\pi x}{l} \bigg )
$$
Fourier cosine series can be written as
$$
f(x)=\frac{a_0}{2} + \sum\limits_{n=1}^\infty a_n \cos \bigg ( \frac{n \pi x}{l} \bigg )\\
a_n=\frac{2}{l} \Bigg [\int\limits_{0}^l \sin \bigg ( \frac{\pi x}{l} \bigg )\cos \bigg ( \frac{n \pi x}{l} \bigg)\,dx \Bigg]\\
=\frac{-1}{l} \Bigg [\frac{\cos(n(1+\pi))}{\frac{n(1+\pi)}{l}} + \frac{\cos(n(1-\pi))}{\frac{n(1-\pi)}{l}} – \frac{1}{\frac{n(1+\pi)}{l}} + \frac{1}{\frac{n(1-\pi)}{l}} \Bigg]\\
=\Bigg [\frac{-\cos(n(1+\pi))}{n(1+\pi)} + \frac{\cos(n(1-\pi))}{n(1-\pi)} + \frac{1}{n(1+\pi)} – \frac{1}{n(1-\pi)} \Bigg]
$$

The problem is I am getting cosine terms in the expansion, which is against my thinking that cosine series expansion of sine function should be zero. Am I messing up in the algebra part or thinking? Can someone comment? Thanks!

Best Answer

Certainly you should get cosine terms in the Fourier cosine series for $f(x)$.

I think you are confusing your situation with the result regarding full Fourier series on $-\ell<x<\ell$, $$ {1\over 2}a_0+\sum_{n=1}^\infty a_n\cos(n\pi x/\ell)+b_n\sin(n\pi x/\ell), $$ that says if $f(x)$ is an odd function on $-\ell<x<\ell$, then $a_n=0$ for all $n=0,1,2,\dots$ (and if $f(x)$ is an even function on $-\ell<x<\ell$, then $b_n=0$ for all $n=1,2,\dots$)