I am trying to solve the following Fourier Series problem.
$$f(x)=\begin{cases} -1,& -1<x<0 \newline 1, & 0<x<1 \end{cases}$$
We know that on the interval $[-1,1]$ is odd. We calculate the coefficients $$a_0=0 , \quad a_n=0 , \quad b_n=\frac{4}{n\pi}$$
Thus,
$$Sf(x)= \sum_{k=1}^{\infty} \frac{4}{(2k-1)\pi} \sin[(2k-1) \pi x] $$
I tried to study the same problem on Mathematica with the following code
f[x_]=Which[-1<x<0,-1,0<x<1,1]
Plot[f[x],{x,-1,1}]
L=2;
a[n_] := (2/L)*Integrate[f[x]*Cos[2 n*Pi*x/L], {x, -L/2, L/2}]
a[0] := (1/L)*Integrate[f[x], {x, -L/2, L/2}]
b[n_] := (2/L)*Integrate[f[x]*Sin[2 n*Pi*x/L], {x, -L/2, L/2}]
F[x_, Nmax_] := a[0] + Sum[a[n]*Cos[2 n*Pi*x/L] + b[n]*Sin[2 n*Pi*x/L], {n, 1, Nmax}]
p[Nmax_, a_] :=
Plot[Evaluate[F[x, Nmax]], {x, -a, a}, PlotRange -> All,
PlotPoints -> 200]
f[x_] = If[x > 0, 1, -1];
a[n]
a[0]
b[n]
Simplify[%, n \[Element] Integers]
Table[F[0.5, k], {k, 0, 20}]
p[20,1]
We notice that with the exception of the first value all other values are double. Why is this phenomenon observed?


