ben_bagelboy
ben_bagelboy

Reputation: 1

Why is my trigonometric interpolation not working?

I am working on finding the trigonometric interpolation for 8 evenly spaced points on the interval [-1, 1]. The data points are given by (t_j, f(t_j)) where f(t_j) = e^(t_j). Here is my code using matlab,

f = @(t) exp(t);
n = 8;
tim = ones(1, 8);
X = ones(1,8);
for j = 1:n
    tim(j) = -1 + (j-1)*(2/n);
    X(j) = f(tim(j));
end

Y = fft(X');
a = real(Y);
b = imag(Y);

P = @(t) a(1)/sqrt(n) + (2/sqrt(n))*((a(2)*cos(pi*(t+1))-b(2)*sin(pi*(t+1)))+(a(3)*cos(2*pi*(t+1))-b(3)*sin(2*pi*(t+1)))+(a(4)*cos(3*pi*(t+1))-b(4)*sin(3*pi*(t+1)))) + (a(5)/sqrt(n))*cos(n*pi*(t+1)/2);
hold on
fplot(P, [-1, 1]);
fplot(f, [-1, 1]);

Output of code

The interpolation doesn't even hit any of the data points. I don't really have any clue where I've gone wrong.

Upvotes: 0

Views: 198

Answers (1)

user1196549
user1196549

Reputation:

Can't it be that you are off by a scaling factor ?

enter image description here

Upvotes: 1

Related Questions