Why does this Fourier series have a finite number of terms? I am learning about Fourier series in class and the basic form of a Fourier Series is
$$a_{0}+\sum_{n=1}^{\infty} [a_{n}\cos(nx)+b_{n}\sin(nx)]$$
so a fourier series should have an infinity number of terms. 
I was reading the book and it says that the fourier series of $\cos^{2}(3x)$ is $\frac{1}{2}+\frac{1}{2}\cos(6x)$. I am assuming the $\frac{1}{2}$ is the $a_{0}$ term. If this is the fourier series, why does it not have an infiniti number of terms like the form above? Why does it only stop at one term after the $\frac{1}{2}$ term?
 A: Well, you can still think of it as having an infinite number of terms, just that most terms are zero.
For a similar example, consider the Taylor series of $1 + x + x^2$. Since everything past the second derivative is zero, all the coefficients of terms with power greater than $2$ are zero, so the series expansion is just the function itself. A similar thing is happening with the Fourier transform: $\cos^2(3x)$ is orthogonal to the terms whose coefficients are not $a_0$ and $a_6$, so their contribution to the Fourier decomposition is zero.
A: It doesn't stop. They are just all zero. $a_n = 0$. So you can write $\frac{1}{2} + \frac{1}{2}cos(6x) + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 \dots$ if you want.
A: One 'practical' reason could be, that the function, you are trying to approximate using a sinusoidal series is itself a sinusoidal function. So it is not an approximation but an exact description.
cos^2 3x = 1/2 + cos 6x/2 (using the trig identity). 
The same thing happens with polynomial functions, when you try to approximate them with Taylor series. (Taylor series approximation is nothing but, trying to approximate a function using a polynomial.)
A: Let's say you want to expand a function $f$ using whatever basis functions (call them $b_n$). Then if your $f$ is already a linear combination of a finite number of $f_n$'s you expansion will be finite too. It works both ways. Finite linear combination means finite expansion and finite expansion means finite linear combination.
In the case of fourier series, the basis functions are sines and cosines. Since you are getting only a finite expansion, then your function is made up of a bunch of (finite number of) sines and cosines. It doesn't matter what it may "look" like.
Same thing happens with Taylor expansion. When using Taylor expansions, the basis functions are $1,x,x^2,x^3,x^4,...$ so if a function had a finite Taylor expansion then it itself must be a polynomial. And its true, polynomials (and only polynomials) have a finite Taylor expansion. Just for giggles, try $f(x)=\cos(3\arccos(x))$. You will see that it has a finite Taylor expansion and hence it is a polynomial.
A: Because your function is actually a finite linear combination of terms like those appearing in Fourier series. There is no magic involved: if you compute all coefficients you will find that most are zero. The series has infinitely many terms, but all but a finite number of them vanish.
For a simpler example, try to find the Fourier series of $\cos(17x)$.
A: A related problem. Notice that, $b_n=0$, since the integrand $\sin(nx)\cos^{2}(3x)$ is an odd function on the interval $[-\pi,\pi]$. For $a_n$, we have
$$ a_n = \frac{2}{\pi}\,{\frac {\sin \left( \pi \,n \right)  \left( {n}^{2}-18 \right) }{n
 \left( {n}^{2}-36 \right) }}.$$
From the above, you can see that $a_n=0,\forall n\neq 6 $. To Find $a_6$, just take the limit of the above expression as $n \to 6.$ 
See here for formulas for $a_n$ and $b_n$.   
A: The fourier decomposition of the function $$f(x) = a_{0}+\sum_{n=1}^{\infty} [a_{n}\cos(nx)+b_{n}\sin(nx)]$$ is just the original function $$a_{0}+\sum_{n=1}^{\infty} [a_{n}\cos(nx)+b_{n}\sin(nx)].$$
If the sequences $a_n$, $b_n$ are always zero after finitely many nonzero terms then you will have a finite decomposition, exactly as in your example.
Functions of this type are called "trigonometric polynomials".
A: Actually, the Fourier series of periodic functions that are smooth (no discontinuity and no sharp corners) is  finite. In other words, all smooth periodic functions can be represented as a trigonometric polynomial.
Since your function is smooth, its Fourier series is finite. Even smooth periodic functions as peculiar as $f(x)=sin(\sin x)$ or $f(x)=e^{\sin x}$ have a finite fourier series expantions.This is such a curious and interesting property of smooth periodic functions!
Source of the first paragraph: Physics: Foundations and Applications, by Robert M. Eisberg and Laurence Lerner. 
