6721
|
1 function interpimages (nm, typ) |
|
2 bury_output (); |
|
3 if (strcmp (nm, "interpft")) |
|
4 t = 0 : 0.3 : pi; dt = t(2)-t(1); |
|
5 n = length (t); k = 100; |
|
6 ti = t(1) + [0 : k-1]*dt*n/k; |
|
7 y = sin (4*t + 0.3) .* cos (3*t - 0.1); |
|
8 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); |
|
9 plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ... |
|
10 ti, interpft (y, k), 'c', t, y, 'r+'); |
|
11 legend ('sin(4t+0.3)cos(3t-0.1','spline','interpft','data'); |
|
12 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
13 elseif (strcmp (nm, "interpn")) |
|
14 x = y = z = -1:1; |
|
15 f = @(x,y,z) x.^2 - y - z.^2; |
|
16 [xx, yy, zz] = meshgrid (x, y, z); |
|
17 v = f (xx,yy,zz); |
|
18 xi = yi = zi = -1:0.1:1; |
|
19 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); |
|
20 vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); |
6723
|
21 mesh (zi, yi, squeeze (vi(1,:,:))); |
6721
|
22 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
23 elseif (strcmp (nm, "interpderiv")) |
|
24 t = 0 : 0.3 : pi; dt = t(2)-t(1); |
|
25 n = length (t); k = 100; dti = dt*n/k; |
|
26 ti = t(1) + [0 : k-1]*dti; |
|
27 y = sin (4*t + 0.3) .* cos (3*t - 0.1); |
|
28 ddyc = diff(diff(interp1(t,y,ti,'cubic'))./dti)./dti; |
|
29 ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti; |
|
30 ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti; |
|
31 plot (ti(2:end-1), ddyc,'g+',ti(2:end-1),ddys,'b*', ... |
|
32 ti(2:end-1),ddyp,'c^'); |
|
33 legend('cubic','spline','pchip'); |
|
34 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
35 endif |
|
36 bury_output (); |
|
37 endfunction |
|
38 |
|
39 ## Use this function before plotting commands and after every call to |
|
40 ## print since print() resets output to stdout (unfortunately, gnpulot |
|
41 ## can't pop output as it can the terminal type). |
|
42 function bury_output () |
|
43 f = figure (1); |
|
44 set (f, "visible", "off"); |
|
45 endfunction |