changeset 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 d99785217634
children 3dcd7fb9945d
files doc/interpreter/geometryimages.m doc/interpreter/interpimages.m doc/interpreter/sparseimages.m doc/interpreter/splineimages.m
diffstat 4 files changed, 88 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/geometryimages.m	Thu Sep 26 22:26:42 2013 -0700
+++ b/doc/interpreter/geometryimages.m	Fri Sep 27 09:39:33 2013 -0700
@@ -30,16 +30,15 @@
   endif
 
   if (! __have_feature__ ("QHULL")
-      && (strcmp (nm, "voronoi") || strcmp (nm, "griddata")
-          || strcmp (nm, "convhull") || strcmp (nm, "delaunay")
-          || strcmp (nm, "triplot")))
-    sombreroimage (nm, typ);
+      && any (strcmp (nm, {"voronoi", "griddata", "convhull", "delaunay", ...
+                           "triplot"})))
+    sombreroimage (nm, typ, d_typ);
   elseif (strcmp (typ, "txt"))
     image_as_txt (nm);
   elseif (strcmp (nm, "voronoi"))
-    rand("state",9);
-    x = rand(10,1);
-    y = rand(10,1);
+    rand ("state", 9);
+    x = rand (10, 1);
+    y = rand (10, 1);
     tri = delaunay (x, y);
     [vx, vy] = voronoi (x, y, tri);
     triplot (tri, x, y, "b");
@@ -47,8 +46,8 @@
     plot (vx, vy, "r");
     [r, c] = tri2circ (tri(end,:), x, y);
     pc = [-1:0.01:1];
-    xc = r * sin(pi*pc) + c(1);
-    yc = r * cos(pi*pc) + c(2);
+    xc = r * sin (pi*pc) + c(1);
+    yc = r * cos (pi*pc) + c(2);
     plot (xc, yc, "g-", "LineWidth", 3);
     axis([0, 1, 0, 1]);
     legend ("Delaunay Triangulation", "Voronoi Diagram");
@@ -61,18 +60,18 @@
     triplot (tri, x, y);
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "griddata"))
-    rand("state",1);
-    x=2*rand(1000,1)-1;
-    y=2*rand(size(x))-1;
-    z=sin(2*(x.^2+y.^2));
-    [xx,yy]=meshgrid(linspace(-1,1,32));
-    griddata(x,y,z,xx,yy);
+    rand ("state", 1);
+    x = 2 * rand (1000,1) - 1;
+    y = 2 * rand (size (x)) - 1;
+    z = sin (2 * (x.^2 + y.^2));
+    [xx,yy] = meshgrid (linspace (-1,1,32));
+    griddata (x,y,z,xx,yy);
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "convhull"))
     x = -3:0.05:3;
     y = abs (sin (x));
     k = convhull (x, y);
-    plot (x(k),y(k),'r-',x,y,'b+');
+    plot (x(k),y(k),'r-', x,y,'b+');
     axis ([-3.05, 3.05, -0.05, 1.05]);
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "delaunay"))
@@ -83,7 +82,7 @@
     X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ];
     Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ];
     axis ([0, 1, 0, 1]);
-    plot(X, Y, "b", x, y, "r*");
+    plot (X,Y,"b", x,y,"r*");
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "inpolygon"))
     randn ("state", 2);
@@ -92,7 +91,7 @@
     vx = cos (pi * [-1 : 0.1: 1]);
     vy = sin (pi * [-1 : 0.1 : 1]);
     in = inpolygon (x, y, vx, vy);
-    plot(vx, vy, x(in), y(in), "r+", x(!in), y(!in), "bo");
+    plot (vx, vy, x(in), y(in), "r+", x(!in), y(!in), "bo");
     axis ([-2, 2, -2, 2]);
     print ([nm "." typ], d_typ);
   else
@@ -129,7 +128,7 @@
   set (f, "visible", "off");
 endfunction
 
-function sombreroimage (nm, typ)
+function sombreroimage (nm, typ, d_typ)
   if (strcmp (typ, "txt"))
     fid = fopen (sprintf ("%s.txt", nm), "wt");
     fputs (fid, "+-----------------------------+\n");
@@ -141,16 +140,8 @@
   else ## if (!strcmp (typ, "txt"))
 
     hide_output ();
-    if (strcmp (typ, "eps"))
-      d_typ = "-depsc2";
-    else
-      d_typ = ["-d" typ];
-    endif
 
-    x = y = linspace (-8, 8, 41)';
-    [xx, yy] = meshgrid (x, y);
-    r = sqrt (xx .^ 2 + yy .^ 2) + eps;
-    z = sin (r) ./ r;
+    [x, y, z] = sombrero ();
     unwind_protect
       mesh (x, y, z);
       title ("Sorry, graphics not available because octave was\\ncompiled without the QHULL library.");
@@ -162,7 +153,7 @@
 endfunction
 
 ## generate something for the texinfo @image command to process
-function image_as_txt(nm)
+function image_as_txt (nm)
   fid = fopen (sprintf ("%s.txt", nm), "wt");
   fputs (fid, "\n");
   fputs (fid, "+---------------------------------+\n");
@@ -170,3 +161,4 @@
   fputs (fid, "+---------------------------------+\n");
   fclose (fid);
 endfunction
+
--- a/doc/interpreter/interpimages.m	Thu Sep 26 22:26:42 2013 -0700
+++ b/doc/interpreter/interpimages.m	Fri Sep 27 09:39:33 2013 -0700
@@ -37,9 +37,9 @@
     ti = t(1) + [0 : k-1]*dt*n/k;
     y = sin (4*t + 0.3) .* cos (3*t - 0.1);
     yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1);
-    plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ...
-          ti, interpft (y, k), 'c', t, y, 'r+');
-    legend ('sin(4t+0.3)cos(3t-0.1)','spline','interpft','data');
+    plot (ti, yp, "g", ti, interp1 (t, y, ti, "spline"), "b", ...
+          ti, interpft (y, k), "c", t, y, "r+");
+    legend ("sin(4t+0.3)cos(3t-0.1)", "spline", "interpft", "data");
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "interpn"))
     x = y = z = -1:1;
@@ -48,7 +48,7 @@
     v = f (xx,yy,zz);
     xi = yi = zi = -1:0.1:1;
     [xxi, yyi, zzi] = ndgrid (xi, yi, zi);
-    vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline');
+    vi = interpn (x, y, z, v, xxi, yyi, zzi, "spline");
     mesh (zi, yi, squeeze (vi(1,:,:)));
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "interpderiv1"))
@@ -56,22 +56,22 @@
     dt = 1;
     ti =-2:0.025:2;
     dti = 0.025;
-    y = sign(t);
-    ys = interp1(t,y,ti,'spline');
-    yp = interp1(t,y,ti,'pchip');
-    plot (ti, ys,'r-', ti, yp,'g-');
-    legend('spline','pchip', 4);
+    y = sign (t);
+    ys = interp1 (t,y,ti,"spline");
+    yp = interp1 (t,y,ti,"pchip");
+    plot (ti, ys,"r-", ti, yp,"g-");
+    legend ("spline","pchip", 4);
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "interpderiv2"))
     t = -2:2;
     dt = 1;
     ti =-2:0.025:2;
     dti = 0.025;
-    y = sign(t);
-    ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti;
-    ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti;
-    plot (ti(2:end-1),ddys,'r*', ti(2:end-1),ddyp,'g+');
-    legend('spline','pchip');
+    y = sign (t);
+    ddys = diff (diff (interp1 (t,y,ti,"spline"))./dti)./dti;
+    ddyp = diff (diff (interp1 (t,y,ti,"pchip"))./dti)./dti;
+    plot (ti(2:end-1),ddys,"r*", ti(2:end-1),ddyp,"g+");
+    legend ("spline", "pchip");
     print ([nm "." typ], d_typ);
   endif
   hide_output ();  
@@ -103,3 +103,4 @@
   fputs (fid, "+---------------------------------+\n");
   fclose (fid);
 endfunction
+
--- a/doc/interpreter/sparseimages.m	Thu Sep 26 22:26:42 2013 -0700
+++ b/doc/interpreter/sparseimages.m	Fri Sep 27 09:39:33 2013 -0700
@@ -73,9 +73,9 @@
   hide_output ();
 endfunction
 
-function txtimages(nm, n, typ)
-  a = 10*speye(n) + sparse(1:n,ceil([1:n]/2),1,n,n) + ...
-      sparse(ceil([1:n]/2),1:n,1,n,n);
+function txtimages (nm, n, typ)
+  a = 10*speye (n) + sparse (1:n,ceil([1:n]/2),1,n,n) + ...
+      sparse (ceil ([1:n]/2),1:n,1,n,n);
   if (strcmp (nm, "gplot") || strcmp (nm, "grid"))
     fid = fopen (sprintf ("%s.txt", nm), "wt");
     fputs (fid, "\n");
@@ -86,8 +86,7 @@
   elseif (strcmp (nm, "spmatrix"))
     printsparse (a, ["spmatrix." typ]);
   else
-    if (__have_feature__ ("COLAMD")
-        && __have_feature__ ("CHOLMOD"))
+    if (__have_feature__ ("COLAMD") && __have_feature__ ("CHOLMOD"))
       if (strcmp (nm, "spchol"))
         r1 = chol (a);
         printsparse (r1, ["spchol." typ]);
@@ -100,7 +99,7 @@
   endif
 endfunction
 
-function otherimages(nm, n, typ)
+function otherimages (nm, n, typ)
   hide_output ();
   if (strcmp (typ, "eps"))
     d_typ = "-depsc2";
@@ -108,16 +107,15 @@
     d_typ = ["-d" typ];
   endif
 
-  a = 10*speye(n) + sparse(1:n,ceil([1:n]/2),1,n,n) + ...
-      sparse(ceil([1:n]/2),1:n,1,n,n);
+  a = 10*speye (n) + sparse (1:n,ceil([1:n]/2),1,n,n) + ...
+      sparse (ceil ([1:n]/2),1:n,1,n,n);
   if (strcmp (nm, "spmatrix"))
     spy (a);
     axis ("ij");
     print (["spmatrix." typ], d_typ);
     hide_output ();
   else
-    if (__have_feature__ ("COLAMD")
-        && __have_feature__ ("CHOLMOD"))
+    if (__have_feature__ ("COLAMD") && __have_feature__ ("CHOLMOD"))
       if (strcmp (nm, "spchol"))
         r1 = chol (a);
         spy (r1);
@@ -155,7 +153,7 @@
     fprintf (fid,"\n");
   endfor
   fprintf (fid,"            |-");
-  for j=1:columns (a)
+  for j = 1:columns (a)
     if (rem (j,5) == 0)
       fprintf (fid,"-|");
     else
@@ -164,7 +162,7 @@
   endfor
   fprintf (fid,"\n");
   fprintf (fid,"              ");
-  for j=1:columns (a)
+  for j = 1:columns (a)
     if (rem (j,5) == 0)
       fprintf (fid,"%2d",j);
     else
@@ -186,21 +184,21 @@
       && __have_feature__ ("CHOLMOD")
       && __have_feature__ ("UMFPACK"))
     ## build a rectangle
-    node_y = [1;1.2;1.5;1.8;2]*ones(1,11);
-    node_x = ones(5,1)*[1,1.05,1.1,1.2,1.3,1.5,1.7,1.8,1.9,1.95,2];
+    node_y = [1;1.2;1.5;1.8;2] * ones (1,11);
+    node_x = ones (5,1) * [1,1.05,1.1,1.2,1.3,1.5,1.7,1.8,1.9,1.95,2];
     nodes = [node_x(:), node_y(:)];
 
     [h,w] = size (node_x);
     elems = [];
-    for idx = 1:w-1
+    for idx = 1 : w-1
       widx = (idx-1)*h;
       elems = [elems; widx+[(1:h-1);(2:h);h+(1:h-1)]']; 
       elems = [elems; widx+[(2:h);h+(2:h);h+(1:h-1)]']; 
     endfor
 
-    E = size (elems,1);  #No. of elements
-    N = size (nodes,1);  #No. of elements
-    D = size (elems,2);  #dimensions+1
+    E = size (elems,1);  # No. of elements
+    N = size (nodes,1);  # No. of elements
+    D = size (elems,2);  # dimensions+1
 
     ## Plot FEM Geometry
     elemx = elems(:,[1,2,3,1])';
@@ -208,7 +206,7 @@
     yelems = reshape (nodes(elemx, 2), 4, E);
 
     ## Set element conductivity
-    conductivity = [1*ones(1,16),2*ones(1,48),1*ones(1,16)];
+    conductivity = [1*ones(1,16), 2*ones(1,48), 1*ones(1,16)];
 
     ## Dirichlet boundary conditions
     D_nodes = [1:5, 51:55]; 
@@ -224,14 +222,14 @@
     C = sparse ((1:D*E), reshape (elems',D*E,1),1, D*E, N);
 
     ## Calculate stiffness matrix
-    Siidx = floor ([0:D*E-1]'/D)*D*ones(1,D) + ones(D*E,1)*(1:D) ;
+    Siidx = floor ([0:D*E-1]'/D)*D*ones(1,D) + ones(D*E,1)*(1:D);
     Sjidx = [1:D*E]'*ones (1,D);
     Sdata = zeros (D*E,D);
     dfact = prod (2:(D-1));
     for j = 1:E
       a = inv ([ ones(D,1), nodes( elems(j,:), : ) ]);
-      const = conductivity(j)*2/dfact/abs(det(a));
-      Sdata(D*(j-1)+(1:D),:)= const * a(2:D,:)'*a(2:D,:);
+      const = conductivity(j)*2/dfact/abs (det (a));
+      Sdata(D*(j-1)+(1:D),:) = const * a(2:D,:)'*a(2:D,:);
     endfor
 
     ## Element-wise system matrix
@@ -249,11 +247,9 @@
     Q = zeros (N,1);
     Q(N_nodes) = N_value; # FIXME
 
-    V(idx) = S(idx,idx)\( Q(idx) - S(idx,D_nodes)*V(D_nodes) );
+    V(idx) = S(idx,idx) \ ( Q(idx) - S(idx,D_nodes)*V(D_nodes) );
 
-    velems = reshape ( V(elemx), 4, E);
-
-    sz = size (xelems,2);
+    velems = reshape (V(elemx), 4, E);
 
     plot3 (xelems, yelems, velems);
     view (10, 10);
@@ -284,10 +280,7 @@
       d_typ = ["-d" typ];
     endif
 
-    x = y = linspace (-8, 8, 41)';
-    [xx, yy] = meshgrid (x, y);
-    r = sqrt (xx .^ 2 + yy .^ 2) + eps;
-    z = sin (r) ./ r;
+    [x, y, z] = sombrero ();
     unwind_protect
       mesh (x, y, z);
       title ("Sorry, graphics are unavailable because Octave was\ncompiled without a sparse matrix implementation.");
@@ -299,7 +292,7 @@
 endfunction
 
 ## generate something for the texinfo @image command to process
-function image_as_txt(nm)
+function image_as_txt (nm)
   fid = fopen (sprintf ("%s.txt", nm), "wt");
   fputs (fid, "\n");
   fputs (fid, "+---------------------------------+\n");
@@ -307,3 +300,4 @@
   fputs (fid, "+---------------------------------+\n");
   fclose (fid);
 endfunction
+
--- a/doc/interpreter/splineimages.m	Thu Sep 26 22:26:42 2013 -0700
+++ b/doc/interpreter/splineimages.m	Fri Sep 27 09:39:33 2013 -0700
@@ -43,10 +43,10 @@
     xx = linspace (0, 2 * pi, 400);
     y1 = ppval (pp1, xx);
     y2 = ppval (pp2, xx);
-    plot (x, y, ".", xx, [y1; y2])
-    axis tight
-    ylim ([-2.5 2.5])
-    legend ("data", "41 breaks, 40 pieces", "11 breaks, 10 pieces")
+    plot (x, y, ".", xx, [y1; y2]);
+    axis tight;
+    ylim ([-2.5 2.5]);
+    legend ("data", "41 breaks, 40 pieces", "11 breaks, 10 pieces");
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "splinefit2")) ## Spline orders
     ## Data (200 points)
@@ -65,10 +65,10 @@
     y3 = ppval (pp3, xx);
     y4 = ppval (pp4, xx);
     y5 = ppval (pp5, xx);
-    plot (x, y, ".", xx, [y1; y2; y3; y4; y5])
-    axis tight
-    ylim ([-2.5 2.5])
-    legend ({"data", "order 0", "order 1", "order 2", "order 3", "order 4"})
+    plot (x, y, ".", xx, [y1; y2; y3; y4; y5]);
+    axis tight;
+    ylim ([-2.5 2.5]);
+    legend ({"data", "order 0", "order 1", "order 2", "order 3", "order 4"});
     print ([nm, "." typ], d_typ);
   elseif (strcmp (nm, "splinefit3"))
     ## Data (100 points)
@@ -82,10 +82,10 @@
     xx = linspace (0, 2 * pi, 400);
     y1 = ppval (pp1, xx);
     y2 = ppval (pp2, xx);
-    plot (x, y, ".", xx, [y1; y2])
-    axis tight
-    ylim ([-2 3])
-    legend ({"data", "no constraints", "periodic"})
+    plot (x, y, ".", xx, [y1; y2]);
+    axis tight;
+    ylim ([-2 3]);
+    legend ({"data", "no constraints", "periodic"});
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "splinefit4"))
     ## Data (200 points)
@@ -105,10 +105,10 @@
     xx = linspace (0, 2 * pi, 400);
     y1 = ppval (pp1, xx);
     y2 = ppval (pp2, xx);
-    plot (x, y, ".", xx, [y1; y2])
-    axis tight
-    ylim ([-1.5 1.5])
-    legend({"data", "clamped", "hinged periodic"})
+    plot (x, y, ".", xx, [y1; y2]);
+    axis tight;
+    ylim ([-1.5 1.5]);
+    legend({"data", "clamped", "hinged periodic"});
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "splinefit5"))
     ## Truncated data
@@ -125,11 +125,11 @@
     ## Plot
     ss = linspace (0, s(end), 400);
     xyfit = ppval (pp, ss);
-    xyb = ppval(pp, pp.breaks);
-    plot (x, y, ".", xyfit(1,:), xyfit(2,:), "r", xyb(1,:), xyb(2,:), "ro")
-    legend ({"data", "spline", "breaks"})
-    axis tight
-    ylim ([0 0.1])
+    xyb = ppval (pp, pp.breaks);
+    plot (x, y, ".", xyfit(1,:), xyfit(2,:), "r", xyb(1,:), xyb(2,:), "ro");
+    legend ({"data", "spline", "breaks"});
+    axis tight;
+    ylim ([0 0.1]);
     print ([nm "." typ], d_typ);
   elseif (strcmp (nm, "splinefit6"))
     ## Data
@@ -148,11 +148,11 @@
     y1 = ppval (pp1, xx);
     y2 = ppval (pp2, xx);
     y3 = ppval (pp3, xx);
-    plot (x, y, ".", xx, [y1; y2; y3])
-    legend({"data with outliers","robust, beta = 0.25", ...
-            "robust, beta = 0.75", "no robust fitting"})
-    axis tight
-    ylim ([-2 2])
+    plot (x, y, ".", xx, [y1; y2; y3]);
+    legend ({"data with outliers","robust, beta = 0.25", ...
+             "robust, beta = 0.75", "no robust fitting"});
+    axis tight;
+    ylim ([-2 2]);
     print ([nm "." typ], d_typ);
   endif
   hide_output ();  
@@ -185,6 +185,7 @@
   fclose (fid);
 endfunction
 
+
 %!demo
 %! for s = 1:6
 %!   splineimages (sprintf ("splinefit##d", s), "pdf")