We have the following periodic function.
$$f(x)=\begin{cases} x+2,& -2<x<0 \newline 2-2x, & 0<x<2 \end{cases}$$
We define the function and we make the plot
f[x_] := Which[-2 < x < 0, x + 2, 0 < x < 2, 2 - 2 x]
Plot[f[x], {x, -2, 2}]
L = 4;
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, 2 - 2 x, x + 2];
a[n]
a[0]
b[n]
Simplify[%, n \[Element] Integers]
p[5, 2]
p[10, 2]
p[15, 2]
p[20, 2]
With the following 4 partial sum plots
Now we want to define an error function $E(x)=|f(x)-S_N(x)|$ where $S_n$ for the partial sums of the Fourier series of the above function for N=7,14,20. I would like to calculate its values at the points of a 10-point partition of the base interval $[-L,L]$ using the Table and Tableform commands.
We have already defined $S_n$ above as
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}]
Now I have defined $E(x)$
e[x_, Nmax_] := Abs[f[x] - F[x, Nmax]]
But I think I miss something. Any suggestions?