% script: fouriertest.m
% description: perform some approximation experiments with 
% Fourier polynomials on the function myfcn defined externally.

N = 50;
n = 25;
a = zeros(1,n+1);
b = zeros(1,n);
% construct the coefficients for myfcn
xnodes = linspace(0,2*pi,N+1);
xnodes = xnodes(1:N); % trim off 2*pi
xnodes = xnodes - pi; % let's work on [-pi,pi]
f = myfcn(xnodes);
% dispose of 0th coefficients
a(n+1) = 2*sum(f)/N;
% now the rest
for j = 1:n
  a(j) = 2*f*cos(j*xnodes)'/N;
  b(j) = 2*f*sin(j*xnodes)'/N;
end
% now try plotting
x = -pi:.001:pi;
clf
plot(x,myfcn(x));
hold on, grid
plot(x,trigeval(a,b,x))
