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!
FourierParametersis 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:54a_n = 1/Pi*Integral from -Pi to Pi f(t)*cos(n*t)dtsince 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