I am trying to get Fourier sine series for $$ f(x) = \left\{ \begin{array}{lr} 3 & : 0\le x\le 6\\ 3-x & : 6\le x \le 9 \end{array} \right. $$
So far I know that the function is aperiodic, therefore I would have to construct what is called a "odd helper function" (at least in my native language), so that the helper function $$\varphi(x)=\left\{ \begin{array}{lr} f(x) &, if \quad x\in[0;l]\\ -f(-x) &, if \quad x\in[-l;0] \end{array} \right.$$ ,where $l=9$.
So my $\varphi(x)$ would look like: $$\varphi(x)=\left\{ \begin{array}{lr} 3 &, if \quad x\in[0;6]\\ 3-x&, if \quad x\in[6;9]\\ -3 &, if \quad x\in[-6;0]\\ -3-x &, if \quad x\in[-9;-6] \end{array} \right.$$ Then I assume that I need to evaluate $$b_n=\frac{2}{l}*\int_0^l{\varphi(x)*\sin{\frac{n*\pi*x}{l}}dx}$$ And the Fourier series would be $$f(x)=\sum_{n=1}^{\infty}{b_n \cdot \sin{\frac{n\cdot\pi\cdot x}{l}}}$$ But when I try to plot this sum up to $n=5$, this does not look anything like my initial piecewise function. What am I doing wrong?