Fourier Series on Mathematica

48 Views Asked by At

Trying to find the first few terms of the Fourier series of $e^{x^2}$ on Mathematica, but my code doesn't seem to be working. It says the first few terms are all 0. Can anyone look at it and tell me whats wrong?

ClearAll[f, a, aa, s] f[x_] := Exp[x^2]; a[n_] := Integrate[(1/Pi) f[x] Sin[n x], {x, -Pi, Pi}]; aa = Table[a[k], {k, 1, 7}] s[x_, n_] := Sum[aa[[k]] Sin[k x], {k, 1, n}];