kill(all)$
load(fourie)$

      Find Fourier Series Expansion of f(x) over (-%pi,pi)

declare(n,integer)$
assume(n > 0)$
facts()$

f(x):=(x-1/4)*(x-3/4)$ f(x);
xBound: 2$

a(n):=1/%pi*integrate(f(x)*cos(n*x),x,-%pi,%pi); a(n);

b(n):=1/%pi*integrate(f(x)*sin(n*x),x,-%pi,%pi); b(n);

map('a,makelist(i,i,1,4));

map('b,makelist(i,i,1,4));

fs(n):=a(0)/2+sum(a(i)*cos(i*x) + b(i)*sin(i*x),i,1,n);

foo:map('fs,[8,64])$

foo:push(f(x),foo)$

sixLineStyles: [style,
                  [lines,2,5],
                  [lines,2,2],
                  [lines,2,3],
                  [lines,2,1],
                  [lines,2,6],
                  [lines,2,4]
               ]$

plot2d(     foo,
            [x,-xBound,xBound],
            [x,-xBound,xBound],
            sixLineStyles,
            [xlabel,"x"],
            [ylabel,"y"],
            [gnuplot_term, ps],
            [gnuplot_out_file, "/Users/van/Desktop/friggle.eps"]
      )$

plot2d(     foo,
            [x,-xBound,xBound],
            [x,-xBound,xBound],
            sixLineStyles,
            [xlabel,"x"],
            [ylabel,"y"]
      )$