comparison scripts/general/interp1.m @ 6721:01036667884a

[project @ 2007-06-14 06:56:41 by dbateman]
author dbateman
date Thu, 14 Jun 2007 06:56:42 +0000
parents b2391d403ed2
children ebf96cc00ee9
comparison
equal deleted inserted replaced
6720:fa2f5d4e55db 6721:01036667884a
343 %! plot(xf,yf,"r",xf,near,"g",xf,lin,"b",xf,cub,"c",xf,spl,"m",xp,yp,"r*"); 343 %! plot(xf,yf,"r",xf,near,"g",xf,lin,"b",xf,cub,"c",xf,spl,"m",xp,yp,"r*");
344 %! legend ("*original","*nearest","*linear","*cubic","*spline") 344 %! legend ("*original","*nearest","*linear","*cubic","*spline")
345 %! %-------------------------------------------------------- 345 %! %--------------------------------------------------------
346 %! % confirm that interpolated function matches the original 346 %! % confirm that interpolated function matches the original
347 347
348 %!demo
349 %! t = 0 : 0.3 : pi; dt = t(2)-t(1);
350 %! n = length (t); k = 100; dti = dt*n/k;
351 %! ti = t(1) + [0 : k-1]*dti;
352 %! y = sin (4*t + 0.3) .* cos (3*t - 0.1);
353 %! ddyc = diff(diff(interp1(t,y,ti,'cubic'))./dti)./dti;
354 %! ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti;
355 %! ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti;
356 %! plot (ti(2:end-1), ddyc,'g+',ti(2:end-1),ddys,'b*', ...
357 %! ti(2:end-1),ddyp,'c^');
358 %! legend('cubic','spline','pchip');
359 %! title("Second derivative of interpolated 'sin (4*t + 0.3) .* cos (3*t - 0.1)'");
360
348 ## For each type of interpolated test, confirm that the interpolated 361 ## For each type of interpolated test, confirm that the interpolated
349 ## value at the knots match the values at the knots. Points away 362 ## value at the knots match the values at the knots. Points away
350 ## from the knots are requested, but only 'nearest' and 'linear' 363 ## from the knots are requested, but only 'nearest' and 'linear'
351 ## confirm they are the correct values. 364 ## confirm they are the correct values.
352 365