annotate doc/interpreter/splineimages.m @ 19742:1170c849952b

don't force gnuplot for creating figures for documentation * geometryimages.m, interpimages.m, plotimages.m, sparseimages.m, splineimages.m: Don't set graphics_toolkit to "gnuplot".
author John W. Eaton <jwe@octave.org>
date Fri, 13 Feb 2015 14:02:06 -0500
parents 4197fc428c7d
children 606b05352351
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19627
diff changeset
1 ## Copyright (C) 2012-2015 Ben Abbott, Jonas Lundgren
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
2 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
3 ## This file is part of Octave.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
4 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
8 ## your option) any later version.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
9 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
13 ## General Public License for more details.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
14 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
18
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
19 function splineimages (nm, typ)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
20 set_print_size ();
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
21 hide_output ();
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
22 if (strcmp (typ, "png"))
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
23 set (0, "defaulttextfontname", "*");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
24 endif
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
25 if (strcmp (typ, "eps"))
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
26 d_typ = "-depsc2";
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
27 else
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14526
diff changeset
28 d_typ = ["-d" typ];
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
29 endif
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
30
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
31 if (strcmp (typ, "txt"))
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
32 image_as_txt (nm);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
33 elseif (strcmp (nm, "splinefit1")) ## Breaks and Pieces
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
34 x = 2 * pi * rand (1, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
35 y = sin (x) + sin (2 * x) + 0.2 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
36 ## Uniform breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
37 breaks = linspace (0, 2 * pi, 41); ## 41 breaks, 40 pieces
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
38 pp1 = splinefit (x, y, breaks);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
39 ## Breaks interpolated from data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
40 pp2 = splinefit (x, y, 10); ## 11 breaks, 10 pieces
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
41 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
42 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
43 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
44 y2 = ppval (pp2, xx);
17504
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
45 plot (x, y, ".", xx, [y1; y2]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
46 axis tight;
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
47 ylim ([-2.5 2.5]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
48 legend ("data", "41 breaks, 40 pieces", "11 breaks, 10 pieces");
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14526
diff changeset
49 print ([nm "." typ], d_typ);
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
50 elseif (strcmp (nm, "splinefit2")) ## Spline orders
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
51 ## Data (200 points)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
52 x = 2 * pi * rand (1, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
53 y = sin (x) + sin (2 * x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
54 ## Splines
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
55 pp1 = splinefit (x, y, 8, "order", 0); ## Piecewise constant
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
56 pp2 = splinefit (x, y, 8, "order", 1); ## Piecewise linear
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
57 pp3 = splinefit (x, y, 8, "order", 2); ## Piecewise quadratic
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
58 pp4 = splinefit (x, y, 8, "order", 3); ## Piecewise cubic
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
59 pp5 = splinefit (x, y, 8, "order", 4); ## Etc.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
60 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
61 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
62 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
63 y2 = ppval (pp2, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
64 y3 = ppval (pp3, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
65 y4 = ppval (pp4, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
66 y5 = ppval (pp5, xx);
17504
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
67 plot (x, y, ".", xx, [y1; y2; y3; y4; y5]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
68 axis tight;
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
69 ylim ([-2.5 2.5]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
70 legend ({"data", "order 0", "order 1", "order 2", "order 3", "order 4"});
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14526
diff changeset
71 print ([nm, "." typ], d_typ);
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
72 elseif (strcmp (nm, "splinefit3"))
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
73 ## Data (100 points)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
74 x = 2 * pi * [0, (rand (1, 98)), 1];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
75 y = sin (x) - cos (2 * x) + 0.2 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
76 ## No constraints
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
77 pp1 = splinefit (x, y, 10, "order", 5);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
78 ## Periodic boundaries
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
79 pp2 = splinefit (x, y, 10, "order", 5, "periodic", true);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
80 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
81 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
82 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
83 y2 = ppval (pp2, xx);
17504
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
84 plot (x, y, ".", xx, [y1; y2]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
85 axis tight;
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
86 ylim ([-2 3]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
87 legend ({"data", "no constraints", "periodic"});
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14526
diff changeset
88 print ([nm "." typ], d_typ);
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
89 elseif (strcmp (nm, "splinefit4"))
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
90 ## Data (200 points)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
91 x = 2 * pi * rand (1, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
92 y = sin (2 * x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
93 ## Breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
94 breaks = linspace (0, 2 * pi, 10);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
95 ## Clamped endpoints, y = y" = 0
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
96 xc = [0, 0, 2*pi, 2*pi];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
97 cc = [(eye (2)), (eye (2))];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
98 con = struct ("xc", xc, "cc", cc);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
99 pp1 = splinefit (x, y, breaks, "constraints", con);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
100 ## Hinged periodic endpoints, y = 0
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
101 con = struct ("xc", 0);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
102 pp2 = splinefit (x, y, breaks, "constraints", con, "periodic", true);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
103 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
104 xx = linspace (0, 2 * pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
105 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
106 y2 = ppval (pp2, xx);
17504
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
107 plot (x, y, ".", xx, [y1; y2]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
108 axis tight;
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
109 ylim ([-1.5 1.5]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
110 legend({"data", "clamped", "hinged periodic"});
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14526
diff changeset
111 print ([nm "." typ], d_typ);
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
112 elseif (strcmp (nm, "splinefit5"))
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
113 ## Truncated data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
114 x = [0, 1, 2, 4, 8, 16, 24, 40, 56, 72, 80] / 80;
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
115 y = [0, 28, 39, 53, 70, 86, 90, 79, 55, 22, 2] / 1000;
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
116 xy = [x; y];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
117 ## Curve length parameter
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
118 ds = sqrt (diff (x).^2 + diff (y).^2);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
119 s = [0, cumsum(ds)];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
120 ## Constraints at s = 0: (x,y) = (0,0), (dx/ds,dy/ds) = (0,1)
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
121 con = struct ("xc", [0 0], "yc", [0 0; 0 1], "cc", eye (2));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
122 ## Fit a spline with 4 pieces
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
123 pp = splinefit (s, xy, 4, "constraints", con);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
124 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
125 ss = linspace (0, s(end), 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
126 xyfit = ppval (pp, ss);
17504
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
127 xyb = ppval (pp, pp.breaks);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
128 plot (x, y, ".", xyfit(1,:), xyfit(2,:), "r", xyb(1,:), xyb(2,:), "ro");
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
129 legend ({"data", "spline", "breaks"});
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
130 axis tight;
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
131 ylim ([0 0.1]);
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14526
diff changeset
132 print ([nm "." typ], d_typ);
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
133 elseif (strcmp (nm, "splinefit6"))
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
134 ## Data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
135 x = linspace (0, 2*pi, 200);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
136 y = sin (x) + sin (2 * x) + 0.05 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
137 ## Add outliers
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
138 x = [x, linspace(0,2*pi,60)];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
139 y = [y, -ones(1,60)];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
140 ## Fit splines with hinged conditions
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
141 con = struct ("xc", [0, 2*pi]);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
142 pp1 = splinefit (x, y, 8, "constraints", con, "beta", 0.25); ## Robust fitting
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
143 pp2 = splinefit (x, y, 8, "constraints", con, "beta", 0.75); ## Robust fitting
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
144 pp3 = splinefit (x, y, 8, "constraints", con); ## No robust fitting
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
145 ## Plot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
146 xx = linspace (0, 2*pi, 400);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
147 y1 = ppval (pp1, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
148 y2 = ppval (pp2, xx);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
149 y3 = ppval (pp3, xx);
17504
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
150 plot (x, y, ".", xx, [y1; y2; y3]);
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
151 legend ({"data with outliers","robust, beta = 0.25", ...
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
152 "robust, beta = 0.75", "no robust fitting"});
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
153 axis tight;
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
154 ylim ([-2 2]);
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14526
diff changeset
155 print ([nm "." typ], d_typ);
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
156 endif
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
157 hide_output ();
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
158 endfunction
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
159
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
160 function set_print_size ()
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
161 image_size = [5.0, 3.5]; # in inches, 16:9 format
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
162 border = 0; # For postscript use 50/72
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
163 set (0, "defaultfigurepapertype", "<custom>");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
164 set (0, "defaultfigurepaperorientation", "landscape");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
165 set (0, "defaultfigurepapersize", image_size + 2*border);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
166 set (0, "defaultfigurepaperposition", [border, border, image_size]);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
167 endfunction
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
168
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
169 ## Use this function before plotting commands and after every call to
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
170 ## print since print() resets output to stdout (unfortunately, gnpulot
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
171 ## can't pop output as it can the terminal type).
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
172 function hide_output ()
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
173 f = figure (1);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
174 set (f, "visible", "off");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
175 endfunction
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
176
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
177 ## generate something for the texinfo @image command to process
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
178 function image_as_txt(nm)
14526
e12945668746 doc: Stop constant rebuild of spline images in txt format.
Rik <octave@nomad.inbox5.com>
parents: 14509
diff changeset
179 fid = fopen (sprintf ("%s.txt", nm), "wt");
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
180 fputs (fid, "\n");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
181 fputs (fid, "+---------------------------------+\n");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
182 fputs (fid, "| Image unavailable in text mode. |\n");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
183 fputs (fid, "+---------------------------------+\n");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
184 fclose (fid);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
185 endfunction
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
186
17504
8b692d9ea54e Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents: 16994
diff changeset
187
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
188 %!demo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
189 %! for s = 1:6
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
190 %! splineimages (sprintf ("splinefit##d", s), "pdf")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
191 %! endfor
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
192