Find Fourier series of the given function (Check the solution).

calculusfourier seriessequences-and-series

I have to find Fourier series of the function $f(x)$ on the :
$$
f(x)=\begin{cases}
0,\ -\pi\leqslant x< 0\\
\sin x,\ 0,\leqslant x\leqslant \pi
\end{cases}\ \ \ x\in[-\pi, \pi]
$$

Here is what I've done:
$$
\begin{aligned}
&\text{Fourier series: }\ a_0+\sum_{n=1}^\infty (a_n\cos nx+b_n\sin nx)\\
&a_0=\frac{1}{2\pi}\int\limits_0^\pi \sin(x)dx=\frac{1}{\pi}\\
&a_n=\frac{1}{\pi}\int\limits_0^\pi \sin x\cos(nx)dx=\frac{(-1)^n+1}{\pi(1-n^2)}\\
&b_n=\frac{1}{\pi}\int\limits_0^\pi \sin x\sin(nx)dx=0\\
&\text{So, the answer is }\ \ \frac{1}{\pi}+\sum_{n=1}^\infty\frac{(-1)^n+1}{\pi(1-n^2)}\cos nx=\frac{1}{\pi}+\frac{2}{\pi}\sum_{n=1}^\infty\frac{\cos(2nx)}{1-4n^2}
\end{aligned}
$$

However, the problem book gives me another answer:
$$
\frac{1}{\pi}+\frac{1}{2}\sin x-\frac{2}{\pi}\sum_{n=1}^\infty\frac{\cos(2nx)}{4n^2-1}
$$

And I do not understand where the term $\frac{1}{2}\sin x$ comes from.
I would appreciate it if someone checked my solution for any errors.

Best Answer

I see someone else already answered it in your comments, but one way to remember it is $$\frac{2}{\pi}\int\limits_0^\pi \sin(mx)\sin(nx)dx=\delta_{mn}$$

Where $\delta_{mn}$ is 1 if $m=n$ and 0 otherwise.

A way of thinking about it in Linear Algebra terms is that the functions $\sin(nx)$ are basis vectors in a space with $n$ vectors ($\sin(x)$,$\sin(2x)$, $\sin(3x)$, etc...).

All of those vectors are mutually perpendicular, so when you take that integral it's like asking the dot product between those two vectors (dot product and this integral are actually related). In this case every vector is mutually perpendicular except the vector and itself.

Related Question