%                     Program fast
%
%    Program fast computes the DFT coefficients of a function f(x)
%    given on [0, 2pi] using the fft of MATLAB. It plots the real
%    part of the partial sums. The input is N, the number of
%    sample points in the interval [0, 2pi]. N should be a power of 2.
%    The function f should be given in the mfile f.m.



N = input('enter the number of sampling points  ')
delx = 2*pi/N;

xsample = 0:delx :2*pi -delx;
x = 0: pi/100:2*pi;
u = f(xsample);
v = fft(u)/N;

d0 = v(1);
d = v(2:N);
sum = d0;

for k = 1: N/2 -1
   sum = sum + d(k)*exp(i*k*x) + d(N-k)*exp(-k*i*x);
end

plot(x, f(x), x,sum)
M = max(real(sum))+.5;
m = min(real(sum))-.5;

axis([0 2*pi  m  M])

d0



