Fourier series with Maxima

If we want to compute the fourier series expansion of f(x) =
x^2, then our coefficients are readily computed on paper as:

a_0 = \frac{\pi^2}{3}

a_n = (-1)^n \frac{4}{n^2}

b_n = 0

and

f(x) = \frac{\pi^2}{3} + \Sigma_{n=1}^{\infty} a_n \cos (nx)

Now we are going to call the functions fourier, foursimp and fourexpand, which obviously calculates the coefficients, simplifies it and expands them into a series. Alternatively, you could call totalfourier which is just the composition of the three functions.

foursimp(fourier(x^2,x,%pi));

Fourier Coefficients

This will spit out the coefficients a_0, a_n and b_n. We can now use fourexpand to expand this into a finite series (four terms here).

fourexpand(%o7,x,%pi,4);

Series Expansion

Now plot the series approximation along with the original to compare:

plot ([x^2,%o8],[x,-3,3]);

Plot of function and approximation

That is all.

Possibly related:

Leave a Reply