Using the general Fourier series expansion: $$f(x)=\frac{a_0}{2}+ \sum_{r=1}^{r=\infty}\left(a_r\cos\left(\frac{2\pi r x}{T}\right)+b_r\sin\left(\frac{2\pi r x}{T}\right)\right)\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\color{blue}{(1)}$$ and noting that $f(x)=x$ is odd such that only the sine terms contribute to the sum. Here $T$ is the period of the function.
Taking $T$ to be $2\pi$. To find the coefficients $b_r$ I used $$b_r= \frac{2}{T}\int_{-\pi}^{\pi}f(x)\sin\left(\frac{2 \pi r x}{T}\right)=\frac{2}{2\pi}\int_{-\pi}^{\pi}f(x)\sin\left(\frac{2 \pi r x}{2\pi}\right)=\frac{4}{2\pi}\int_{0}^{\pi}x\sin(rx)=\left[-\frac{2}{\pi}\frac{x\cos(rx)}{r}\right]_{x=0}^{\pi}+\frac{2}{\pi}\int_{x=0}^{\pi}\frac{\cos(rx)}{r}\mathrm{d}x=-\frac{2\pi (-1)^r}{\pi r}+ \left[\frac{2}{\pi}\frac{\sin(rx)}{r^2}\right]_{x=0}^{\pi}=-2\frac{(-1)^r}{r}=2\frac{(-1)^{r+1}}{r}$$
To find $a_0$ I used $$a_0=\color{red}{\frac{2}{T}\int_{-\pi}^{\pi}f(x)\mathrm{d}x=\frac{2}{2\pi}\int_{-\pi}^{\pi}x\mathrm{d}x}=0$$
Insertion of $a_0$ and $b_r$ into $\color{blue}{(1)}$ yields $$f(x) = x =2\sum_{r=1}^{\infty}\frac{(-1)^{r+1}}{r}\sin(rx)$$ as the Fourier series for $f(x)=x$ in $-\pi\lt x \le \pi$
Now setting $x=\frac{\pi}{2}$ in the expression found for $f(x)$ yields $$\frac{\pi}{4} = 1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+....$$ as required.
Finally, my question involves the part of the calculation coloured $\color{red}{red}$. I do not understand the origin of this formula since it was given to me without proof in a text book.
In order for the above calculation to be plausible I need to know the derivation and meaning of the left hand side of the general formula marked red for computing $a_0$.
Could someone please explain where this equation comes from?
Or, put in another way, should I use $$a_r = \frac{2}{T}\int_{-\pi}^{\pi}f(x)\cos\left(\frac{2 \pi r x}{T}\right)\mathrm{d}x$$$$=\frac{2}{2\pi}\int_{-\pi}^{\pi}f(x)\cos\left(\frac{2 \pi r x}{2\pi}\right)\mathrm{d}x$$$$=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\mathrm{d}x= \frac{1}{\pi}\int_{-\pi}^{\pi}x\mathrm{d}x=a_0=0$$ formula with $r=0$ even though I don't have any cosine terms in my series?
Thank you
Kindest regards,
Blaze.
Fourier Series is defined as $$f(x)=\frac{a_0}{2}+ \sum_{r=1}^{r=\infty}\left(a_r\cos\left(\frac{2\pi r x}{T}\right)+b_r\sin\left(\frac{2\pi r x}{T}\right)\right)\space\space\space\space\space\space\space\space\space\space\space\space\space\space\space\color{blue}{(1)}$$
For $r>0$ You can obtain the coefficients using the formulas you wrote down first. For the case $r=0$ you have to use the formula for $a_r$
$$a_r=\frac{2}{T}\int_{-\pi}^{\pi}f(x)\cos{(\frac{2\pi rx}{T})}\mathrm{d}x$$
and set $r = 0$. Applying this will lead to $f(x)\cos(\frac{2\pi x\cdot0}{T})=f(x)\cos(0)=f(x)$. Now integrate this from $-\pi$ to $\pi$ and multiply this by $\frac{2}{T}$ to get what is written in red.
Alternatively: