2

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!

user48441
  • 29
  • 1
  • 2
    Check the documentation for the setting of FourierParameters option. – Daniel Lichtblau Nov 06 '12 at 21:58
  • This is answered in the docs for every one of the Fourier functions you've used – Rojo Nov 06 '12 at 23:31
  • 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 – user48441 Nov 06 '12 at 23:38
  • Can you share either by link or simply writing it, the definition you are using to get the coefficients by hand? – Rojo Nov 06 '12 at 23:45
  • 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... – J. M.'s missing motivation Nov 07 '12 at 03:54
  • @Rojo: I'm using a_n = 1/Pi*Integral from -Pi to Pi f(t)*cos(n*t)dt since the period is 2Pi. As you can see in my code the function is 1 at 0->Pi/2 and 0 otherwise. This makes the integral `a_n = 1/PiIntegral from 0 to Pi/2 cos(nt)dt`. The expected result is Sin(nPi/2)/(n*Pi) but I don't get that as previously stated. – user48441 Nov 07 '12 at 14:46
  • Anyone? Further help would be really appreciated. @J.M. – user48441 Nov 08 '12 at 22:55

0 Answers0