I am trying to plot the partial sums for $N=5,10,15,20$ of the Fourier series of $f(x)=(1-x^2)^2$ and $-1<x<1.$ I have:
f[x_] = If[1 > x > -1, (1-x^2)^2];
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_, N_] :=
a[0] + Sum[a[n]*Cos[2 n*Pi*x/L] + b[n]*Sin[2 n*Pi*x/L], {n, 1, N}]
Table[F[x, N], {N, 5, 20, 5}]
p[N_, a_] :=
Plot[Evaluate[F[x, N]], {x, -a, a}, PlotRange -> All,
PlotPoints -> 200]
a[n]
a[0]
b[n]
Table[p[N, 1], {N, 5, 20, 5}]
g[x_, N_] := Abs[f[x] - F[x, N]]
Table[g[x, 7], {x, -1, 1, 2/10}]
Something is getting wrong. What should I do? Then, how could I use FourierTrigSeries, FourierParameters and FourierCoefficient?
N
is a built-in symbol name, try using a different name. $\endgroup$ – Rohit Namjoshi Jan 18 '20 at 16:17