70 likes | 228 Views
Lecture 20: Trigonometric interpolations. Download triginterp.m. Calculate trig interpolation at interval [t0, tn] In p points based on interpolation in n points. t0=-10; tn=10; n=50; p=n*10; t=t0+(tn-t0)*(0:n-1)/n; % n evenly-spaced time points
E N D
Lecture 20: Trigonometric interpolations Download triginterp.m Calculate trig interpolation at interval [t0, tn] In p points based on interpolation in n points
t0=-10; tn=10; n=50; p=n*10; t=t0+(tn-t0)*(0:n-1)/n; % n evenly-spaced time points tp=t0+(tn-t0)*(0:p-1)/p; % p evenly-spaced time points f = inline('exp(-t.^2)'); %test function to interpolate x=f(t); xexact=f(tp); y=fft(x); % apply DFT yp=zeros(p,1); % yp will hold coefficients for ifft yp(1:n/2+1)=y(1:n/2+1); % move n frequencies from n to p yp(p-n/2+2:p)=y(n/2+2:n); % same for upper tier xp=real(ifft(yp))*(p/n); % invert fft to recover data error=xp-xexact'; subplot(2,1,1); plot(t,x,'o',tp,xp) % plot data points and interpolant title('trigonometric nterpolation'); subplot(2,1,2); plot(tp,error,'o') % plot error title('error')
Gibb’s phenomenon %Example of Gibb's phenomenon - failure of trig interpolation for nonperiodic functions t0=0; tn=10; n=50; p=n*10; t=t0+(tn-t0)*(0:n-1)/n; % n evenly-spaced time points tp=t0+(tn-t0)*(0:p-1)/p; % p evenly-spaced time points f = inline('exp(-t.^2)'); %test function to interpolate x=f(t); xexact=f(tp); y=fft(x); % apply DFT yp=zeros(p,1); % yp will hold coefficients for ifft yp(1:n/2+1)=y(1:n/2+1); % move n frequencies from n to p yp(p-n/2+2:p)=y(n/2+2:n); % same for upper tier xp=real(ifft(yp))*(p/n); % invert fft to recover data error=xp-xexact'; subplot(2,1,1); plot(t,x,'o',tp,xp) % plot data points and interpolant title('trigonometric nterpolation'); subplot(2,1,2); plot(tp,error,'o') % plot error title('error')
Download triginterpgibbs.m
Inclass • Interpolate function exp(-x^4) at interval [-10,10] from • 50 equally spaced points. Plot your result.