Obtain the fourier series on the interval: $$[-\pi,\pi]$$ of the function:
$$f(x)= \begin{cases} -\pi x&\text{if}\, -\pi \leq x\leq 0\\ x^2 &\text{if}\ , 0 <x\leq \pi\\ \end{cases}$$
Solution given by book: $$S(x) = \frac{5\pi^2}{12}+\sum_{n=1}^\infty \left[\frac{3(-1)^n -1}{n^2} \cos{nx}+2 \frac{(-1)^n - 1}{n^3\pi}\sin{nx}\right]$$
basically i'm stuck because I can't get my answer to match the solution given. I'm using the method that $-\pi x$ is an odd function so $a_n= 0$ and then working out $b_n$ using that function. Similarly $x^2$ is even so $b_n = 0$ and using that function to workout an. Can someone provide a step by step solution? or tell me what I'm doing wrong? thank you :)
\begin{align} % a_{0} &= \frac{1}{\pi} \int_{-\pi}^{\pi} x^2 dx \\ % a_{n} &= \frac{1}{\pi} \int_{-\pi}^{\pi} x^2 \cos \left( {n x} \right) dx \\ % b_{n} &= \frac{1}{\pi} \int_{-\pi}^{\pi} -\pi x \sin \left( n x \right) dx \\ % \end{align}
You can't do it that way because neither $-\pi x$ or $x^2$ are odd or even on the entire interval of $[-\pi,\pi]$. They each only take up one half.
You have to integrate the whole thing. No shortcuts.
\begin{align} a_0 &= \frac{1}{\pi}\left[-\int_{-\pi}^0 \pi x\ dx + \int_0^{\pi} x^2\ dx \right] \\ a_n &= \frac{1}{\pi} \left[-\int_{-\pi}^0 \pi x \cos (nx)\ dx + \int_0^\pi x^2 \cos(nx)\ dx \right] \\ b_n &= \frac{1}{\pi} \left[-\int_{-\pi}^0 \pi x \sin (nx)\ dx + \int_0^\pi x^2 \sin(nx)\ dx \right] \end{align}
None of these integrals will go to $0$ since you're always integrating over half the interval. You don't have a symmetric interval in any integration, so nothing simplifies.
There also may or may not be a factor of $1/2$ in the $a_0$ integral depending on how you define your Fourier series. Check your book.