Could somebody please tell me if I've gotten this question correct? I'm unsure about my answer.
Consider the periodic function:
$$f(x)= \begin{cases} 0,\ -\pi \lt x \le 0\\ 1,\ 0\lt x\le \pi \end{cases}$$ with $f(x)=f(x+2\pi )$.
Find the Fourier series for $f(x)$.
$\\[10pt]$
Here's my working:
$a_0=\frac {1}{2\pi }\int_{-\pi} ^\pi f(x) \,dx$
$a_0=\frac {1}{2\pi }(\pi )$
$a_0=\frac {1}{2}$
$\\[10pt]$
$a_n=\frac {1}{\pi }\int_{-\pi }^\pi f(x)\cos nx\,dx$
$a_n=\frac {1}{\pi }[\int_{-\pi }^0\require{cancel}\cancelto{0}{0.\cos nx\,dx} +\int_0^{\pi }1.\cos nx\,dx]$
$a_n=\frac{1}{\pi }[\frac{1}{n}\sin nx]_0^{\pi }$
$a_n=\frac{1}{n\pi }[\cancelto{0}{\sin nx]_0^{\pi }}$
$a_n=0$
$\\[10pt]$
$b_n=\frac {1}{\pi }\int_{-\pi }^\pi f(x)\sin nx\,dx$
$b_n=\frac {1}{\pi }[\int_{-\pi }^0\cancelto{0}{0.\sin nx\,dx} +\int_0^{\pi }1.\sin nx\,dx]$
$b_n=\frac{1}{\pi }[-\frac{1}{n}\cos nx]_0^{\pi }$
$b_n=-\frac{1}{n\pi }(\cos n\pi -{\cos n0})$
$b_n=-\frac{1}{n\pi }[(-1)^n-1]$
$b_n= \begin{cases} 0,\ \text{if n is even}\\ -\frac{2}{n\pi },\ \text{if n is odd} \end{cases}$
$\therefore Sf(x)=\frac {1}{2}-\frac{2}{\pi }\mathop{\LARGE \Sigma} _{n=odd}^\infty \frac{1}{n}\sin n x$
$\\[10pt]$
If anyone could tell me either if I got this right or where I went wrong it'd be greatly appreciated.
Some notes:
i) $$b_n = \begin{cases} 0, &\text{$n$ is even} \\[2ex] \dfrac 2{n\pi}, & \text{$n$ is odd} \end{cases}$$
ii) The Fourier series of $f$ is: $$Sf(x) \begin{array}[t]{l} = a_0 + \displaystyle \sum_{n=1}^{\infty} \left[a_n \cdot \cos \left(\dfrac{2 n \pi x}{2\pi}\right) + b_n \cdot \sin \left( \dfrac{2 n \pi x}{2\pi}\right)\right]\\[2ex] = \dfrac 12 + \dfrac 2\pi\cdot \displaystyle \sum_{n = 1,3,5,\ldots}^\infty \frac 1n\cdot sin (nx) \end{array}$$