Task:
Let $f(x)=\begin{cases}\frac{1}{\pi}x-2 \quad \text{ for } 2\pi\leq x < 3\pi \\ 4-\frac{1}{\pi}x \quad \text{ for } 3\pi \leq x < 4\pi\end{cases}$, $f:\mathbb{R}\to\mathbb{R}$
and $f(x+2\pi)=f(x)$ for all $x\in\mathbb{N}$. How do I create a Fourier-Series for that function?
Solution/Problem:
The function is periodical for every $2\pi$. That's why $T=2\pi$. $$a_k=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cdot \cos(k\cdot x)dx,$$ $k=0,1,2,3,\dots$
$$b_k=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cdot \sin(k\cdot x) dx,$$ $k=1,2,3,\dots$ and
$$F_n(x)=\frac{a_0}{2}+\sum\limits_{k=1}^{n}\left(a_k\cos(k\cdot x)+b_k\cdot \sin(k\cdot x)\right)$$ is the Taylor-Polynomial, the Taylor-Series is $$F_\infty(x)=\frac{a_0}{2}+\sum\limits_{k=1}^{\infty}(a_k\cos(k\cdot x)+b_k\cdot \sin(k\cdot x)).$$
Because the function is periodical, we can change the integration-limits to $2\pi$, $4\pi$ or is this wrong? Afterwards, I've computed the integrals for $a_k$ and $b_k$ with $k$ arbitrary except for $a_0$, which needs to be computed too.
$$a_k=\frac{1}{\pi}\left(\displaystyle\int\limits_{2\pi}^{3\pi}\frac{1}{\pi}x-2\cdot \cos(kx)dx+\int\limits_{3\pi}^{4\pi}4-\frac{1}{\pi}x\cdot \cos(kx)dx\right)$$
$$a_k=\frac{2\sin(2\pi k)+\sin(3\pi k)-4\sin(4\pi k)}{\pi k}+\frac{13}{2}$$ for $k>0$ and $a_0=1$.
(I've left out the integration-steps, because that takes too mucht time to type in $\LaTeX$)
The computation for $b_k$ is similar except that we need to insert the other function and multiply by $\sin(kx)$.
$$b_k=\frac{\sin(3\pi k)-\sin(4\pi k)}{\pi^2k^2}+\frac{-2\cos(2\pi k)-\cos(3\pi k)+4\cos(4\pi k)}{\pi k}+\frac{13}{2}$$
and therefore, the Taylor-Polynomial is $$F_n(x)=\frac{1}{2}+\sum\limits_{n=1}^{n}(a_k\cdot \cos(kx)+b_k\cdot \sin(kx))dx$$ and the Series:
$$F_\infty(x)=\frac{1}{2}+\sum\limits_{n=1}^{\infty}(a_k\cdot \cos(kx)+b_k\cdot \sin(kx))dx,$$
which is a kinda weird solution and I've probably made some mistakes while computing. Can you tell me what I've done wrong and how to do it right?
The problem is unfortunately in the part you skipped: the integrals, here is the result you should arrive to
\begin{eqnarray} a_0 &=& 1 \\ a_k &=& \frac{1}{k^2\pi^2}[-\cos 2\pi k + 2 \cos 3\pi k - \cos 4\pi k] = \frac{2}{k^2\pi^2}(-1 + (-1)^k) ~~~ k = 1, 2, \cdots \\ b_k &=& 0 \end{eqnarray}
This is a plot that shows convergence for different number of terms in the series $N$
EDIT Code to generate the previous plot