1
## Copyright (C) 2007 David Bateman
3
## This file is part of Octave.
5
## Octave is free software; you can redistribute it and/or modify it
6
## under the terms of the GNU General Public License as published by
7
## the Free Software Foundation; either version 3 of the License, or (at
8
## your option) any later version.
10
## Octave is distributed in the hope that it will be useful, but
11
## WITHOUT ANY WARRANTY; without even the implied warranty of
12
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
## General Public License for more details.
15
## You should have received a copy of the GNU General Public License
16
## along with Octave; see the file COPYING. If not, see
17
## <http://www.gnu.org/licenses/>.
19
function interpimages (nm, typ)
21
if (strcmp (typ, "png"))
22
set (0, "defaulttextfontname", "*");
24
if (strcmp (typ, "txt"))
26
elseif (strcmp (nm, "interpft"))
27
t = 0 : 0.3 : pi; dt = t(2)-t(1);
28
n = length (t); k = 100;
29
ti = t(1) + [0 : k-1]*dt*n/k;
30
y = sin (4*t + 0.3) .* cos (3*t - 0.1);
31
yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1);
32
plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ...
33
ti, interpft (y, k), 'c', t, y, 'r+');
34
legend ('sin(4t+0.3)cos(3t-0.1','spline','interpft','data');
35
print (strcat (nm, ".", typ), strcat ("-d", typ))
36
elseif (strcmp (nm, "interpn"))
38
f = @(x,y,z) x.^2 - y - z.^2;
39
[xx, yy, zz] = meshgrid (x, y, z);
41
xi = yi = zi = -1:0.1:1;
42
[xxi, yyi, zzi] = ndgrid (xi, yi, zi);
43
vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline');
44
mesh (zi, yi, squeeze (vi(1,:,:)));
45
print (strcat (nm, ".", typ), strcat ("-d", typ))
46
elseif (strcmp (nm, "interpderiv1"))
52
ys = interp1(t,y,ti,'spline');
53
yp = interp1(t,y,ti,'pchip');
54
plot (ti, ys,'r-', ti, yp,'g-');
55
legend('spline','pchip', 4);
56
print (strcat (nm, ".", typ), strcat ("-d", typ))
57
elseif (strcmp (nm, "interpderiv2"))
63
ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti;
64
ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti;
65
plot (ti(2:end-1),ddys,'r*', ti(2:end-1),ddyp,'g+');
66
legend('spline','pchip');
67
print (strcat (nm, ".", typ), strcat ("-d", typ))
72
## Use this function before plotting commands and after every call to
73
## print since print() resets output to stdout (unfortunately, gnpulot
74
## can't pop output as it can the terminal type).
75
function bury_output ()
77
set (f, "visible", "off");
80
## generate something for the texinfo @image command to process
81
function image_as_txt(nm)
82
fid = fopen (sprintf ("%s.txt", nm), "wt");
84
fputs (fid, "+---------------------------------+\n");
85
fputs (fid, "| Image unavailable in text mode. |\n");
86
fputs (fid, "+---------------------------------+\n");