This question already has an answer here:

I'm calculating Fourier Coefficients by hand and trying to verify them in Mathematica.

However, in Mathematica I get them wrong by a factor of 2. Is there some part of the Mathematica functions I'm missing or am I doing something else wrong?

What almost makes me think there is something wrong with Mathematica is that $c_0$ should be equal to $1/2 a_0$. When computing by hand $c_0$ is indeed $1/4$ but $a_0$ should be $1/2$ (as I get by hand) and not 1 as Mathematica tells me.

Here is my code:

g[x_] := Piecewise[{{0, -Pi < x < 0}, {1, 0 < x < Pi/2}, {0, 
    Pi/2 < x < Pi}}]

makeper[f_, L_, offset_] := f[Mod[#, L, offset]] &

gTest = makeper[g, 2*Pi, -Pi]

Plot[gTest[x], {x, -4*Pi, 4*Pi}, PlotRange -> {0, 1}, 
 Ticks -> {{-4 Pi, -3 Pi, -2 Pi, -Pi, 0, Pi, 2 Pi, 3 Pi, 4 Pi}, {-1, 
    0, 1}}, Filling -> Axis]

FourierCoefficient[gTest[x], x, n]

FourierCoefficient[gTest[x], x, 0]

FourierSinCoefficient[gTest[x], x, n]

FourierCosCoefficient[gTest[x], x, n]

FourierCosCoefficient[gTest[x], x, 0]

Any help would be appreciated!


marked as duplicate by J. M. is away Apr 9 '13 at 5:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Check the documentation for the setting of FourierParameters option. $\endgroup$ – Daniel Lichtblau Nov 6 '12 at 21:58
  • $\begingroup$ This is answered in the docs for every one of the Fourier functions you've used $\endgroup$ – Rojo Nov 6 '12 at 23:31
  • $\begingroup$ Reading the docs I think I want to use FourierParameters -> {-1, 1/(2 Pi) but that gives me really strange answers. Any help with the parameters? @Rojo $\endgroup$ – user48441 Nov 6 '12 at 23:38
  • $\begingroup$ Can you share either by link or simply writing it, the definition you are using to get the coefficients by hand? $\endgroup$ – Rojo Nov 6 '12 at 23:45
  • $\begingroup$ As already noted, FourierParameters is there, since each field that uses Fourier series has a favorite convention. If you'll mention what convention you're using, we could be more helpful... $\endgroup$ – J. M. is away Nov 7 '12 at 3:54

Browse other questions tagged or ask your own question.