comparison doc/interpreter/splineimages.m @ 17504:8b692d9ea54e

Use Octave coding conventions for m-files which generate images for manual. * doc/interpreter/geometryimages.m, doc/interpreter/interpimages.m, doc/interpreter/sparseimages.m, doc/interpreter/splineimages.m: Use Octave coding conventions for m-files which generate images for manual.
author Rik <rik@octave.org>
date Fri, 27 Sep 2013 09:39:33 -0700
parents 333243133364
children d63878346099
comparison
equal deleted inserted replaced
17503:d99785217634 17504:8b692d9ea54e
41 pp2 = splinefit (x, y, 10); ## 11 breaks, 10 pieces 41 pp2 = splinefit (x, y, 10); ## 11 breaks, 10 pieces
42 ## Plot 42 ## Plot
43 xx = linspace (0, 2 * pi, 400); 43 xx = linspace (0, 2 * pi, 400);
44 y1 = ppval (pp1, xx); 44 y1 = ppval (pp1, xx);
45 y2 = ppval (pp2, xx); 45 y2 = ppval (pp2, xx);
46 plot (x, y, ".", xx, [y1; y2]) 46 plot (x, y, ".", xx, [y1; y2]);
47 axis tight 47 axis tight;
48 ylim ([-2.5 2.5]) 48 ylim ([-2.5 2.5]);
49 legend ("data", "41 breaks, 40 pieces", "11 breaks, 10 pieces") 49 legend ("data", "41 breaks, 40 pieces", "11 breaks, 10 pieces");
50 print ([nm "." typ], d_typ); 50 print ([nm "." typ], d_typ);
51 elseif (strcmp (nm, "splinefit2")) ## Spline orders 51 elseif (strcmp (nm, "splinefit2")) ## Spline orders
52 ## Data (200 points) 52 ## Data (200 points)
53 x = 2 * pi * rand (1, 200); 53 x = 2 * pi * rand (1, 200);
54 y = sin (x) + sin (2 * x) + 0.1 * randn (size (x)); 54 y = sin (x) + sin (2 * x) + 0.1 * randn (size (x));
63 y1 = ppval (pp1, xx); 63 y1 = ppval (pp1, xx);
64 y2 = ppval (pp2, xx); 64 y2 = ppval (pp2, xx);
65 y3 = ppval (pp3, xx); 65 y3 = ppval (pp3, xx);
66 y4 = ppval (pp4, xx); 66 y4 = ppval (pp4, xx);
67 y5 = ppval (pp5, xx); 67 y5 = ppval (pp5, xx);
68 plot (x, y, ".", xx, [y1; y2; y3; y4; y5]) 68 plot (x, y, ".", xx, [y1; y2; y3; y4; y5]);
69 axis tight 69 axis tight;
70 ylim ([-2.5 2.5]) 70 ylim ([-2.5 2.5]);
71 legend ({"data", "order 0", "order 1", "order 2", "order 3", "order 4"}) 71 legend ({"data", "order 0", "order 1", "order 2", "order 3", "order 4"});
72 print ([nm, "." typ], d_typ); 72 print ([nm, "." typ], d_typ);
73 elseif (strcmp (nm, "splinefit3")) 73 elseif (strcmp (nm, "splinefit3"))
74 ## Data (100 points) 74 ## Data (100 points)
75 x = 2 * pi * [0, (rand (1, 98)), 1]; 75 x = 2 * pi * [0, (rand (1, 98)), 1];
76 y = sin (x) - cos (2 * x) + 0.2 * randn (size (x)); 76 y = sin (x) - cos (2 * x) + 0.2 * randn (size (x));
80 pp2 = splinefit (x, y, 10, "order", 5, "periodic", true); 80 pp2 = splinefit (x, y, 10, "order", 5, "periodic", true);
81 ## Plot 81 ## Plot
82 xx = linspace (0, 2 * pi, 400); 82 xx = linspace (0, 2 * pi, 400);
83 y1 = ppval (pp1, xx); 83 y1 = ppval (pp1, xx);
84 y2 = ppval (pp2, xx); 84 y2 = ppval (pp2, xx);
85 plot (x, y, ".", xx, [y1; y2]) 85 plot (x, y, ".", xx, [y1; y2]);
86 axis tight 86 axis tight;
87 ylim ([-2 3]) 87 ylim ([-2 3]);
88 legend ({"data", "no constraints", "periodic"}) 88 legend ({"data", "no constraints", "periodic"});
89 print ([nm "." typ], d_typ); 89 print ([nm "." typ], d_typ);
90 elseif (strcmp (nm, "splinefit4")) 90 elseif (strcmp (nm, "splinefit4"))
91 ## Data (200 points) 91 ## Data (200 points)
92 x = 2 * pi * rand (1, 200); 92 x = 2 * pi * rand (1, 200);
93 y = sin (2 * x) + 0.1 * randn (size (x)); 93 y = sin (2 * x) + 0.1 * randn (size (x));
103 pp2 = splinefit (x, y, breaks, "constraints", con, "periodic", true); 103 pp2 = splinefit (x, y, breaks, "constraints", con, "periodic", true);
104 ## Plot 104 ## Plot
105 xx = linspace (0, 2 * pi, 400); 105 xx = linspace (0, 2 * pi, 400);
106 y1 = ppval (pp1, xx); 106 y1 = ppval (pp1, xx);
107 y2 = ppval (pp2, xx); 107 y2 = ppval (pp2, xx);
108 plot (x, y, ".", xx, [y1; y2]) 108 plot (x, y, ".", xx, [y1; y2]);
109 axis tight 109 axis tight;
110 ylim ([-1.5 1.5]) 110 ylim ([-1.5 1.5]);
111 legend({"data", "clamped", "hinged periodic"}) 111 legend({"data", "clamped", "hinged periodic"});
112 print ([nm "." typ], d_typ); 112 print ([nm "." typ], d_typ);
113 elseif (strcmp (nm, "splinefit5")) 113 elseif (strcmp (nm, "splinefit5"))
114 ## Truncated data 114 ## Truncated data
115 x = [0, 1, 2, 4, 8, 16, 24, 40, 56, 72, 80] / 80; 115 x = [0, 1, 2, 4, 8, 16, 24, 40, 56, 72, 80] / 80;
116 y = [0, 28, 39, 53, 70, 86, 90, 79, 55, 22, 2] / 1000; 116 y = [0, 28, 39, 53, 70, 86, 90, 79, 55, 22, 2] / 1000;
123 ## Fit a spline with 4 pieces 123 ## Fit a spline with 4 pieces
124 pp = splinefit (s, xy, 4, "constraints", con); 124 pp = splinefit (s, xy, 4, "constraints", con);
125 ## Plot 125 ## Plot
126 ss = linspace (0, s(end), 400); 126 ss = linspace (0, s(end), 400);
127 xyfit = ppval (pp, ss); 127 xyfit = ppval (pp, ss);
128 xyb = ppval(pp, pp.breaks); 128 xyb = ppval (pp, pp.breaks);
129 plot (x, y, ".", xyfit(1,:), xyfit(2,:), "r", xyb(1,:), xyb(2,:), "ro") 129 plot (x, y, ".", xyfit(1,:), xyfit(2,:), "r", xyb(1,:), xyb(2,:), "ro");
130 legend ({"data", "spline", "breaks"}) 130 legend ({"data", "spline", "breaks"});
131 axis tight 131 axis tight;
132 ylim ([0 0.1]) 132 ylim ([0 0.1]);
133 print ([nm "." typ], d_typ); 133 print ([nm "." typ], d_typ);
134 elseif (strcmp (nm, "splinefit6")) 134 elseif (strcmp (nm, "splinefit6"))
135 ## Data 135 ## Data
136 x = linspace (0, 2*pi, 200); 136 x = linspace (0, 2*pi, 200);
137 y = sin (x) + sin (2 * x) + 0.05 * randn (size (x)); 137 y = sin (x) + sin (2 * x) + 0.05 * randn (size (x));
146 ## Plot 146 ## Plot
147 xx = linspace (0, 2*pi, 400); 147 xx = linspace (0, 2*pi, 400);
148 y1 = ppval (pp1, xx); 148 y1 = ppval (pp1, xx);
149 y2 = ppval (pp2, xx); 149 y2 = ppval (pp2, xx);
150 y3 = ppval (pp3, xx); 150 y3 = ppval (pp3, xx);
151 plot (x, y, ".", xx, [y1; y2; y3]) 151 plot (x, y, ".", xx, [y1; y2; y3]);
152 legend({"data with outliers","robust, beta = 0.25", ... 152 legend ({"data with outliers","robust, beta = 0.25", ...
153 "robust, beta = 0.75", "no robust fitting"}) 153 "robust, beta = 0.75", "no robust fitting"});
154 axis tight 154 axis tight;
155 ylim ([-2 2]) 155 ylim ([-2 2]);
156 print ([nm "." typ], d_typ); 156 print ([nm "." typ], d_typ);
157 endif 157 endif
158 hide_output (); 158 hide_output ();
159 endfunction 159 endfunction
160 160
183 fputs (fid, "| Image unavailable in text mode. |\n"); 183 fputs (fid, "| Image unavailable in text mode. |\n");
184 fputs (fid, "+---------------------------------+\n"); 184 fputs (fid, "+---------------------------------+\n");
185 fclose (fid); 185 fclose (fid);
186 endfunction 186 endfunction
187 187
188
188 %!demo 189 %!demo
189 %! for s = 1:6 190 %! for s = 1:6
190 %! splineimages (sprintf ("splinefit##d", s), "pdf") 191 %! splineimages (sprintf ("splinefit##d", s), "pdf")
191 %! endfor 192 %! endfor
192 193