Determing the Fourier series of piecewise function

100 Views Asked by At

I am trying to determine the fourier series of $f(x)$ on $[-2,2]$

$$f(x) = \begin{cases} 2,&-2\leq x \leq 0\\ x, &0 < x \leq 2\\ \end{cases}$$

So I know that,

$$f(x) = \frac{A_0}{2} + \sum _{n=1}^{\infty} A_n \cos \Big(\frac{n\pi x}{L}\Big) + \sum _{n=1}^{\infty} B_n \sin \Big(\frac{n\pi x}{L}\Big)$$

Then calculating $A_0,$

$$A_0 = \frac{1}{L} \int_{-L}^{L} f(x) dx = \frac{1}{2} \int _{-2}^{2} f(x)dx = \frac{1}{2} \Bigg [\int_{-2}^02dx + \int_0^{2} x \Bigg]= \frac{1}{2}[4+2] = 3 $$

It is is my calculation of $A_n$ where I am not sure if I am following the correct procedure. I just want to make sure I am calculating $A_n$ correctly before I begin $B_n$. Or if someone wants to help me with $B_n$ that would be great too! So here my what I got for $A_n$

$$A_n = \frac{1}{L}\int_{-2}^{2} f(x) \cos\Big(\frac{n\pi x}{2} \Big) \\ = \frac{1}{2}\Bigg[\int_{-2}^0 2\cos\Big(\frac{n\pi x}{2}\Big) + \int _0^2 x\cos \Big(\frac{n\pi x}{2}\Big) \Bigg]\\= \frac{1}{2}\Bigg[2*\frac{2}{n\pi}\sin \Big(\frac{n\pi x}{2}\Big)\Big|_{-2}^0 \Bigg] + \frac{1}{2}\Bigg[x\frac{2}{\pi n}\sin \Big(\frac{n\pi x}{2 }\Big) + \frac{4}{n^2\pi ^2}\cos \Big(\frac{n\pi x}{2 }\Big)\Big|_0^2 \Bigg] $$

Now using the fact that $\sin (\pi n) = 0$ and $\cos (\pi n) = (-1)^n$ and plugging in the values of the definite integral, this is where I am not quite sure if I am doing the correct thing. I am pretty sure I have done everything above correctly.

$$\frac{1}{2}\Bigg[\frac{4}{\pi n } \sin(\pi n ) + \frac{4}{\pi n } \cos(\pi n )\Bigg] - \frac{1}{2}\Bigg[0 + \frac{4}{\pi ^2 n ^2 } \Bigg] \\ = \frac{2}{\pi^2 n^2 }(-1)^{n} - \frac{2}{\pi^2 n^2 }$$

So right now without calculating $B_n$ I have,

$$f(x) = \frac{3}{2} + \sum _{n=1}^{\infty} \Bigg[\frac{2}{\pi^2 n^2 }(-1)^{n} - \frac{2}{\pi^2 n^2 } \Bigg] \cos {\frac{n\pi x }{2}}$$