I'm new to Matlab, and I'm trying to evaluate a function via fast
fourier transform using Matlab, then compare the values at each
gridpoint with the exact value.
The function is
y1 = cos(x)-20*sin(5*x)+6*sin(12*x)
on the interval [-pi, pi], using n = 9 gridpoints.
I first tried to find the Fourier coefficients F1:
n = 9;
x = -pi:(2*pi/(n-1)):pi;
y1 = cos(x)-20*sin(5*x)+6*sin(12*x);
F1 = fft(y1);
I checked the values of my coefficients with the formula given by my
F1_k = SUM[y1(x_j)*exp(pi*i*j*k/m)]
where m = n/2, k = 0, 1, ..., 2m-1, and SUM is from j = 0 to j = 2m-1.
The coefficients matched.
Then I tried to compute the function F(x) at each grid point x_j using
F(x) = (1/m)*SUM(F1_k*exp(i*k*x))
where SUM is from k = 0 to 2m-1
(This is the formula given by my teacher.)
However, the values for F(x) that I got were
-4.6765 + 1.8450i
-2.0000 + 0.0000i
instead of the actual values
What is wrong with my program?