\(フーリエ級数展開とグラフ \((1)\)\)

Clear[f]; f[x_] := x /; -π < x < π; 
    f[x_] := x + 2  π /; -3 π < x < -π; 
    f[x_] := x + 4  π /; -5 π < x < -3 π; 
    f[x_] := x - 2  π /; π < x < 3  π; 
    f[x_] := x - 4  π /; 3  π < x < 5  π; 
    Plot[f[x], {x, -5 Pi, 5  Pi}, AspectRatio -> Automatic, 
      PlotRange -> {-Pi - 1, (Pi) + 1}, 
      PlotStyle -> Hue[0.6]]

\(上のグラフはアニメ - ションできません\)

Clear[a]; a[m_] := 0; Clear[b]; b[m_] := -(2/m) (((-1))^m); 
    Clear[S]; 
    S[n_, x_] := 
      a[0] + (∑_(k = 1)^n)(a[k]*Cos[k*x] + b[k]*Sin[k*x]); 
    Clear[g]; 
    g[n_] := Plot[S[n, x], {x, -5 Pi, 5  Pi}, PlotStyle -> Hue[0.0], 
        AspectRatio -> Automatic, 
        PlotRange -> {-1 - Pi, Pi + 1}]; Clear[G]; 
    G[n_] := Plot[{S[n, x], f[x]}, {x, -5 Pi, 5  Pi}, 
        PlotStyle -> {Hue[0.0], Hue[0.6]}, 
        AspectRatio -> Automatic, 
        PlotRange -> {-Pi - 1, Pi + 1}]; 
    Do[G[n], {n, 1, 40, 2}]

S[10, x]