# Calculating Fourier series of $\cos^2(t)$ gives unexpected result

As I understand it:

$$\cos^2(t)$$ is even because it is a product of two even functions $$\cos(t)$$.

The Fourier series and Fourier cosine series of an even function is the same link.

So in the fourier series expansion $$\cos^2(t)={a_0 \over 2}+\sum_{n=1}^\infty(a_n\cos(n \omega t) + b_n \sin(n \omega t))$$, I expect $$a_n\neq 0$$ and $$b_n=0$$.

I try to get the the coefficients with wolfram alpha like this:

$$a_n$$ with FourierCosCoefficient[$$\cos(t)^2,t,n$$] gives zero link

$$b_n$$ with FourierSinCoefficient[$$\cos(t)^2,t,n$$] gives non-zero link

Which of my assumptions are wrong?

(I also got $$a_n=0$$ when calculating by hand so the question is not primarily about wolfram alpha but about the relation between Fourier series, Fourier cosine series, and even functions)

• Looks to me that already $a_0 = \frac{1}{2} \ne 0$... Can you detail your computations ? – Gâteau-Gallois Mar 9 at 11:30
• I'm not familiar enough with WolframAlpha to say, but it seems to me this is likely to be a misunderstanding of what the function does. For example, where's the $\omega$ in that call? Maybe it's trying to project the function on a different period? As it stands, $cos^2(t) = 1/2+1/2cos(2t)$, so that's all your Fourier series. – Okarin Mar 9 at 11:41
• The correct answer is $a_0=a_2=\frac 1 2$ and all other coefficients $0$. – Kabo Murphy Mar 9 at 11:41
• Surprisingly Mathematica gives the same answer. OTOH to the integral FourierCosCoefficient[(1+Cos[2t])/2,t,n]it gives the expected (DiscreteDelta[n-2]+2 DiscreteDelta[n])/2 – Jyrki Lahtonen Mar 9 at 11:50
• FWIW, I asked this at Mathematica.SE. – Jyrki Lahtonen Mar 9 at 12:06

Just read the documentation: https://reference.wolfram.com/language/ref/FourierSinCoefficient.html

The command FourierSinCoefficient does not compute the coefficients $$b_n$$ in the full Fourier series, but the coefficients in the Fourier sine series (= the full Fourier series of the odd extension of the function in question).

• Thanks, this shows why I was wrong to assume I could calculate $b_n$ with FourierSinCoefficient. I still think I should be able to calculate $a_n$ with FourierCosCoefficient. – aardvark Mar 9 at 14:05

The simplest way to find the Fourier series of this function is to write it as $$\frac {1+\cos(2t)} 2$$. This expression is in fact the Fourier series!.

• I'm sure we all know this. The question is why WolframAlpha gives a different answer. – Jyrki Lahtonen Mar 9 at 11:46

It is clear that, for each $$n\in\mathbb N$$,$$\int_{-\pi}^\pi\cos^2(t)\sin(nt)\,\mathrm dt=0,$$since $$t\mapsto\cos^2(t)\sin(nt)$$ is an odd function.

On the other hand,$$a_0=\frac1\pi\int_{-\pi}^\pi\cos^2(t)\,\mathrm dt=1\neq0.$$It turns out that $$a_1=0$$, but $$a_2=\frac12\neq0$$.

• I'm sure we all know this. The question is why WolframAlpha gives a different answer. – Jyrki Lahtonen Mar 9 at 11:48
• No, we don't all know this, since the OP claimed to have obtained $a_n=0$ while calculating by hand. – José Carlos Santos Mar 9 at 11:49