kill(all)$
load(fourie)$

       My objective in this work is to find the Fourier Coefficients
       of common functions so that I can listen to their shape.
       I see two potential connections:
           1) adding a sound track to common math problems
           2) creating basis functions for studying acoustics,
              particularly violin acoustics

       Definition:

F(x) = 1/2*a0 + sum(an*cos(n*x) + bn*sin(n*x),n,1,inf);

a0_unweighted:(1/%pi)*integrate(F(u),u,-%pi,%pi);

      With periodic functions:
      If f(x) is symmetric about the y axis then f(-x) = f(x).
      We say in this case f(x) is 'even' and only the cos(nx) terms contribute.

      If f(x) is not symmetric about the y axis and  f(x) = -f(x).
      We say in this case f(x) is 'odd' and only the sin(nx) terms contribute.

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

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

F(x)=(sum(bn*sin(n*x)+an*cos(n*x),n,1,inf))+a0/2;

f(x):=4*x^2-3*x+3;

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,8));

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

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

foo:map('fs,[1,2,3,4]);

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,-2*%pi,2*%pi],
            [x,-2*%pi,2*%pi],
            sixLineStyles,
            [xlabel,"x"],
            [ylabel,"y"],
            [gnuplot_term, ps],
            [gnuplot_out_file, "/Users/van/Desktop/friggle.eps"]
      )$

plot2d(     foo,
            [x,-2*%pi,2*%pi],
            [x,-2*%pi,2*%pi],
            sixLineStyles,
            [xlabel,"x"],
            [ylabel,"y"]
      )$

plot3d(    2^(x^2 - y^2),
          [x, -1, 1],
          [y, -2, 2],
          [plot_format, gnuplot]
      );