I want to expand $f(x)=x^2,\, x\in [0,2\pi],$ into Fourier series. Here is my step to solve coefficients $a_n$ and $b_n$:
$t=x-\pi$ , so $t\in [-\pi, \pi]$
$f(x)=(t+\pi)^2=\varphi(t)$
then I try to expand $\varphi(t)$ on $[-\pi,\pi]$
$a_n$ of $\varphi(t)$ equals to $\frac{1}{\pi}\int_{-\pi}^{\pi}\varphi(t)\cos{nt}dt=\frac{1}{\pi}\int_{-\pi}^{\pi}(t+\pi)^2\cos{nt}dt$
$b_n$ of $\varphi(t)$ equals to $\frac{1}{\pi}\int_{-\pi}^{\pi}\varphi(t)\sin{nt}dt=\frac{1}{\pi}\int_{-\pi}^{\pi}(t+\pi)^2\sin{nt}dt$
I got $a_n=\frac{4\cos{n\pi}}{n^2}$ and $b_n=-\frac{4\pi\cos{n\pi}}{n}$
so $a_n$ and $b_n$ should be coefficients of Fourier series of $f(x)$ on $[0,2\pi]$. But in solution $a_n=\frac{4}{n^2}$ and $b_n=-\frac{4\pi}{n}$. Is there any mistake about my substituting?
So my assumption is, that you were thought to always rescale/shift the interval to match $[-\pi,\pi]$? While it is generally a good idea to reduce a problem to a known issue, in this case it creates some extra effort. In your specific case you determined the coefficients but for the shifted functions that means: $$ \phi(t)=\sum_n \tilde a_n \cos(nt)+\tilde b_n \sin(nt)\\ \tilde a_n=\frac{4\cos{n\pi}}{n^2}\\ \tilde b_n=-\frac{4\pi\cos{n\pi}}{n} $$ Now if we switch to $x$ we get $$ f(x)=\sum_n \tilde a_n \cos(n(x-\pi))+\tilde b_n \sin(n(x-\pi))\\ =\sum_n \tilde a_n \left(\cos(x\pi)\cos(n\pi)-\sin(x\pi)\underbrace{\sin(n\pi)}_{=0}\right)+\tilde b_n \left(\sin(x\pi)\cos(n\pi)-\cos(x\pi)\underbrace{\sin(n\pi)}_{=0}\right)\\ =\sum_n \underbrace{\tilde a_n\cos(n\pi)}_{=a_n} \cos(x\pi)+\underbrace{\tilde b_n\cos(n\pi)}_{=b_n} \sin(x\pi) $$ which yields the result from the solution.
Hint: In this case a more direct approach would be to work directly on the interval $[0,2\pi]$. Generally you can work on any interval, you just have to make sure the trigonometric functions are a orthogonal basis and you have to take the correct scaling (divide by interval length $L/2$, in your case $\pi$).