Fourier Series for x^2

The nonzero Fourier coefficients:

Integrate[1/(2π)*E^(-I*n*x)*x^2,{x,-π,π}]

The zero coefficient:

Integrate[1/(2*π)*x^2,{x,-π,π}]

f[x_,n_]:=Sum[2/(m^2)*Exp[I*m*x]*(-1)^m,{m,-n,-1}]+((π^2)/3)+Sum[2/(m^2)*Exp[I*m*x]*(-1)^m,{m,1,n}]

FullSimplify[f[x,10]]

Plot[{x^2,f[x,1],f[x,2],f[x,3]},{x,-π,π}]

Fourier Series of Sawtooth Function

ST[x_,L_,H_]:=Piecewise[{{H/L*x+H,x<0},{-H/L*x+H,x>0}}]

a_0 coefficient

1/L*Integrate[ST[x,L,H],{x,-L,L},Assumptions->L>0]

a_n coefficient

1/L*Integrate[ST[x,L,H]*Cos[n*x*π/L],{x,-L,L},Assumptions->L>0]

f[x_,n_,L_,H_]:=H/2+Sum[2*H/(m^2*π^2)*(1+(-1)^(m+1))*Cos[m*π*x/L],{m,1,n}]

Plot[{ST[x,5,10],f[x,1,5,10],f[x,5,5,10],f[x,10,5,10]},{x,-5,5}]