Mercurial > hg > octave-nkf
annotate doc/interpreter/splineimages.m @ 20657:c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Octave's default save format is '-text' which is confusingly referred to in the
code base as LS_ASCII (looks like '-ascii' mode).
* ls-oct-text.cc, ls-oct-text.h: Renamed from ls-oct-ascii.[cc|h].
* ls-oct-ascii.cc, ls-oct-ascii.h: Removed files.
* libinterp/corefcn/module.mk: Add ls-oct-text.cc, ls-oct-text.h to build
system.
* load-save.h (load_save_format_type): Change first value of enum from
LS_ASCII to LS_TEXT.
* load-save.cc: Rename instances of LS_ASCII to LS_TEXT. Rename instances of
read_ascii_data to read_text_data.
* ov-base-diag.cc, ov-base-int.cc, ov-base-sparse.cc, ov-bool-mat.cc,
ov-bool.cc, ov-complex.cc, ov-cx-mat.cc ov-fcn-inline.cc, ov-float.cc,
ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-perm.cc, ov-re-mat.cc, ov-scalar.cc,
ov-str-mat.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc:
Use '#include "ls-oct-text.h"' rather than ls-oct-ascii.h.
ov-cell.cc, ov-class.cc, ov-fcn-handle.cc, ov-lazy-idx.cc, ov-struct.cc:
Use '#include "ls-oct-text.h"' rather than ls-oct-ascii.h.
Rename save_ascii_data to save_text_data, read_ascii_data to read_text_data.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 17 Aug 2015 09:20:03 -0700 |
parents | b439ccc9a162 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19790
diff
changeset
|
1 ## Copyright (C) 2012-2015 Ben Abbott, Jonas Lundgren |
14509 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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. | |
9 ## | |
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. | |
14 ## | |
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/>. | |
18 | |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
19 function splineimages (d, nm, typ) |
20545
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
20 set_graphics_toolkit (); |
14509 | 21 set_print_size (); |
22 hide_output (); | |
20526
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20517
diff
changeset
|
23 outfile = fullfile (d, [nm "." typ]); |
14509 | 24 if (strcmp (typ, "png")) |
25 set (0, "defaulttextfontname", "*"); | |
26 endif | |
27 if (strcmp (typ, "eps")) | |
28 d_typ = "-depsc2"; | |
29 else | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14526
diff
changeset
|
30 d_typ = ["-d" typ]; |
14509 | 31 endif |
32 | |
33 if (strcmp (typ, "txt")) | |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
34 image_as_txt (d, nm); |
14509 | 35 elseif (strcmp (nm, "splinefit1")) ## Breaks and Pieces |
36 x = 2 * pi * rand (1, 200); | |
37 y = sin (x) + sin (2 * x) + 0.2 * randn (size (x)); | |
38 ## Uniform breaks | |
39 breaks = linspace (0, 2 * pi, 41); ## 41 breaks, 40 pieces | |
40 pp1 = splinefit (x, y, breaks); | |
41 ## Breaks interpolated from data | |
42 pp2 = splinefit (x, y, 10); ## 11 breaks, 10 pieces | |
43 ## Plot | |
44 xx = linspace (0, 2 * pi, 400); | |
45 y1 = ppval (pp1, xx); | |
46 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
|
47 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
|
48 axis tight; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
49 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
|
50 legend ("data", "41 breaks, 40 pieces", "11 breaks, 10 pieces"); |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
51 print (outfile, d_typ); |
14509 | 52 elseif (strcmp (nm, "splinefit2")) ## Spline orders |
53 ## Data (200 points) | |
54 x = 2 * pi * rand (1, 200); | |
55 y = sin (x) + sin (2 * x) + 0.1 * randn (size (x)); | |
56 ## Splines | |
57 pp1 = splinefit (x, y, 8, "order", 0); ## Piecewise constant | |
58 pp2 = splinefit (x, y, 8, "order", 1); ## Piecewise linear | |
59 pp3 = splinefit (x, y, 8, "order", 2); ## Piecewise quadratic | |
60 pp4 = splinefit (x, y, 8, "order", 3); ## Piecewise cubic | |
61 pp5 = splinefit (x, y, 8, "order", 4); ## Etc. | |
62 ## Plot | |
63 xx = linspace (0, 2 * pi, 400); | |
64 y1 = ppval (pp1, xx); | |
65 y2 = ppval (pp2, xx); | |
66 y3 = ppval (pp3, xx); | |
67 y4 = ppval (pp4, xx); | |
68 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
|
69 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
|
70 axis tight; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
71 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
|
72 legend ({"data", "order 0", "order 1", "order 2", "order 3", "order 4"}); |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
73 print (outfile, d_typ); |
14509 | 74 elseif (strcmp (nm, "splinefit3")) |
75 ## Data (100 points) | |
76 x = 2 * pi * [0, (rand (1, 98)), 1]; | |
77 y = sin (x) - cos (2 * x) + 0.2 * randn (size (x)); | |
78 ## No constraints | |
79 pp1 = splinefit (x, y, 10, "order", 5); | |
80 ## Periodic boundaries | |
81 pp2 = splinefit (x, y, 10, "order", 5, "periodic", true); | |
82 ## Plot | |
83 xx = linspace (0, 2 * pi, 400); | |
84 y1 = ppval (pp1, xx); | |
85 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
|
86 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
|
87 axis tight; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
88 ylim ([-2 3]); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
89 legend ({"data", "no constraints", "periodic"}); |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
90 print (outfile, d_typ); |
14509 | 91 elseif (strcmp (nm, "splinefit4")) |
92 ## Data (200 points) | |
93 x = 2 * pi * rand (1, 200); | |
94 y = sin (2 * x) + 0.1 * randn (size (x)); | |
95 ## Breaks | |
96 breaks = linspace (0, 2 * pi, 10); | |
97 ## Clamped endpoints, y = y" = 0 | |
98 xc = [0, 0, 2*pi, 2*pi]; | |
99 cc = [(eye (2)), (eye (2))]; | |
100 con = struct ("xc", xc, "cc", cc); | |
101 pp1 = splinefit (x, y, breaks, "constraints", con); | |
102 ## Hinged periodic endpoints, y = 0 | |
103 con = struct ("xc", 0); | |
104 pp2 = splinefit (x, y, breaks, "constraints", con, "periodic", true); | |
105 ## Plot | |
106 xx = linspace (0, 2 * pi, 400); | |
107 y1 = ppval (pp1, xx); | |
108 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
|
109 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
|
110 axis tight; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
111 ylim ([-1.5 1.5]); |
20526
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20517
diff
changeset
|
112 legend ({"data", "clamped", "hinged periodic"}); |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
113 print (outfile, d_typ); |
14509 | 114 elseif (strcmp (nm, "splinefit5")) |
115 ## Truncated data | |
116 x = [0, 1, 2, 4, 8, 16, 24, 40, 56, 72, 80] / 80; | |
117 y = [0, 28, 39, 53, 70, 86, 90, 79, 55, 22, 2] / 1000; | |
118 xy = [x; y]; | |
119 ## Curve length parameter | |
120 ds = sqrt (diff (x).^2 + diff (y).^2); | |
121 s = [0, cumsum(ds)]; | |
122 ## Constraints at s = 0: (x,y) = (0,0), (dx/ds,dy/ds) = (0,1) | |
123 con = struct ("xc", [0 0], "yc", [0 0; 0 1], "cc", eye (2)); | |
124 ## Fit a spline with 4 pieces | |
125 pp = splinefit (s, xy, 4, "constraints", con); | |
126 ## Plot | |
127 ss = linspace (0, s(end), 400); | |
128 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
|
129 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
|
130 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
|
131 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
|
132 axis tight; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
133 ylim ([0 0.1]); |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
134 print (outfile, d_typ); |
14509 | 135 elseif (strcmp (nm, "splinefit6")) |
136 ## Data | |
137 x = linspace (0, 2*pi, 200); | |
138 y = sin (x) + sin (2 * x) + 0.05 * randn (size (x)); | |
139 ## Add outliers | |
140 x = [x, linspace(0,2*pi,60)]; | |
141 y = [y, -ones(1,60)]; | |
142 ## Fit splines with hinged conditions | |
143 con = struct ("xc", [0, 2*pi]); | |
144 pp1 = splinefit (x, y, 8, "constraints", con, "beta", 0.25); ## Robust fitting | |
145 pp2 = splinefit (x, y, 8, "constraints", con, "beta", 0.75); ## Robust fitting | |
146 pp3 = splinefit (x, y, 8, "constraints", con); ## No robust fitting | |
147 ## Plot | |
148 xx = linspace (0, 2*pi, 400); | |
149 y1 = ppval (pp1, xx); | |
150 y2 = ppval (pp2, xx); | |
151 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
|
152 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
|
153 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
|
154 "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
|
155 axis tight; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
156 ylim ([-2 2]); |
20517
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19920
diff
changeset
|
157 print (outfile, d_typ); |
14509 | 158 endif |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
159 hide_output (); |
14509 | 160 endfunction |
161 | |
20545
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
162 ## This function no longer sets the graphics toolkit; That is now done |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
163 ## automatically by C++ code which will ordinarily choose 'qt', but might |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
164 ## choose gnuplot on older systems. Only a complete lack of plotting is a |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
165 ## problem. |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
166 function set_graphics_toolkit () |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
167 if (isempty (available_graphics_toolkits ())) |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
168 error ("no graphics toolkit available for plotting"); |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
169 endif |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
170 endfunction |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
171 |
14509 | 172 function set_print_size () |
173 image_size = [5.0, 3.5]; # in inches, 16:9 format | |
174 border = 0; # For postscript use 50/72 | |
175 set (0, "defaultfigurepapertype", "<custom>"); | |
176 set (0, "defaultfigurepaperorientation", "landscape"); | |
177 set (0, "defaultfigurepapersize", image_size + 2*border); | |
178 set (0, "defaultfigurepaperposition", [border, border, image_size]); | |
179 endfunction | |
180 | |
20545
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
181 ## Use this function before plotting commands and after every call to print |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
182 ## since print() resets output to stdout (unfortunately, gnuplot can't pop |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
183 ## output as it can the terminal type). |
14509 | 184 function hide_output () |
20545
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20526
diff
changeset
|
185 hf = figure (1, "visible", "off"); |
14509 | 186 endfunction |
187 | |
188 ## generate something for the texinfo @image command to process | |
20526
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20517
diff
changeset
|
189 function image_as_txt (d, nm) |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20517
diff
changeset
|
190 fid = fopen (fullfile (d, [nm ".txt"]), "wt"); |
14509 | 191 fputs (fid, "\n"); |
192 fputs (fid, "+---------------------------------+\n"); | |
193 fputs (fid, "| Image unavailable in text mode. |\n"); | |
194 fputs (fid, "+---------------------------------+\n"); | |
195 fclose (fid); | |
196 endfunction | |
197 | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
198 |
14509 | 199 %!demo |
200 %! for s = 1:6 | |
201 %! splineimages (sprintf ("splinefit##d", s), "pdf") | |
202 %! endfor | |
203 |