changeset 17120:a639221f9863

sombrero.m: Overhaul documentation and make calling forms equivalent to peaks() * scripts/plot/sombrero.m: Overhaul documentation. Return only Z argument if nargout == 1. * scripts/plot/ribbon.m, scripts/plot/surf.m, scripts/plot/surfc.m: Rephrase %!tests to take advantage of new calling form for sombrero.
author Rik <rik@octave.org>
date Wed, 31 Jul 2013 13:43:44 -0700
parents bd50e0660545
children d4549655b92e
files scripts/plot/ribbon.m scripts/plot/sombrero.m scripts/plot/surf.m scripts/plot/surfc.m
diffstat 4 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/ribbon.m	Wed Jul 31 13:31:01 2013 -0700
+++ b/scripts/plot/ribbon.m	Wed Jul 31 13:43:44 2013 -0700
@@ -113,7 +113,7 @@
 %! clf;
 %! colormap ('default');
 %! [x, y, z] = sombrero ();
-%! [x, y] = meshgrid (x, y);
+%! [~, y] = meshgrid (x, y);
 %! ribbon (y, z);
 
 %!FIXME: Could have some input validation tests here
--- a/scripts/plot/sombrero.m	Wed Jul 31 13:31:01 2013 -0700
+++ b/scripts/plot/sombrero.m	Wed Jul 31 13:43:44 2013 -0700
@@ -19,15 +19,32 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} sombrero ()
 ## @deftypefnx {Function File} {} sombrero (@var{n})
-## Produce the familiar three-dimensional sombrero plot using @var{n}
-## grid lines.  If @var{n} is omitted, a value of 41 is assumed.
+## @deftypefnx {Function File} {@var{z} =} sombrero (@dots{})
+## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} sombrero (@dots{})
+## Plot the familiar 3-D sombrero function.
 ##
 ## The function plotted is
+## @tex
+## $$z = { \rm{sin} (\sqrt {(x^2 + y^2)}) \over \sqrt {(x^2 + y^2)} }$$
+## @end tex
+## @ifnottex
 ##
 ## @example
 ## z = sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2))
 ## @end example
-## @seealso{surf, meshgrid, mesh}
+##
+## @end ifnottex
+## Called without a return argument, @code{sombrero} plots the surface of the
+## above function over the meshgrid [-8,8] using @code{surf}.
+## 
+## If @var{n} is a scalar the plot is made with @var{n} grid lines.
+## The default value for @var{n} is 41.
+##
+## When called with output arguments, return the data for the function
+## evaluated over the meshgrid.  This can subsequently be plotted with
+## @code{surf (@var{x}, @var{y}, @var{z})}.
+##
+## @seealso{peaks, meshgrid, mesh, surf}
 ## @end deftypefn
 
 ## Author: jwe
@@ -43,11 +60,13 @@
   tx = linspace (-8, 8, n)';
   ty = tx;
   [xx, yy] = meshgrid (tx, ty);
-  r = sqrt (xx .^ 2 + yy .^ 2) + eps;
+  r = sqrt (xx .^ 2 + yy .^ 2) + eps;  # eps prevents div/0 errors
   tz = sin (r) ./ r;
+
   if (nargout == 0)
     surf (tx, ty, tz);
-    box ("off");
+  elseif (nargout == 1)
+    z = tz;
   else
     x = tx;
     y = ty;
--- a/scripts/plot/surf.m	Wed Jul 31 13:31:01 2013 -0700
+++ b/scripts/plot/surf.m	Wed Jul 31 13:43:44 2013 -0700
@@ -76,7 +76,7 @@
 %!demo
 %! clf;
 %! colormap ('default');
-%! [~,~,Z] = sombrero ();
+%! Z = sombrero ();
 %! [Fx,Fy] = gradient (Z);
 %! surf (Z, Fx+Fy);
 %! shading interp;
--- a/scripts/plot/surfc.m	Wed Jul 31 13:31:01 2013 -0700
+++ b/scripts/plot/surfc.m	Wed Jul 31 13:43:44 2013 -0700
@@ -90,7 +90,7 @@
 %!demo
 %! clf;
 %! colormap ('default');
-%! [~,~,Z] = sombrero ();
+%! Z = sombrero ();
 %! [Fx,Fy] = gradient (Z);
 %! surfc (Z, Fx+Fy);
 %! shading interp;