]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/sombrero.m
update packages
[CreaPhase.git] / octave_packages / m / plot / sombrero.m
1 ## Copyright (C) 1993-2012 John W. Eaton
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
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} sombrero (@var{n})
21 ## Produce the familiar three-dimensional sombrero plot using @var{n}
22 ## grid lines.  If @var{n} is omitted, a value of 41 is assumed.
23 ##
24 ## The function plotted is
25 ##
26 ## @example
27 ## z = sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2))
28 ## @end example
29 ## @seealso{surf, meshgrid, mesh}
30 ## @end deftypefn
31
32 ## Author: jwe
33
34 function [x, y, z] = sombrero (n)
35
36   if (nargin == 0)
37     n = 41;
38   endif
39
40   if (nargin < 2)
41     if (n > 1)
42       tx = linspace (-8, 8, n)';
43       ty = tx;
44       [xx, yy] = meshgrid (tx, ty);
45       r = sqrt (xx .^ 2 + yy .^ 2) + eps;
46       tz = sin (r) ./ r;
47       if (nargout == 0)
48         surf (tx, ty, tz);
49         box ("off");
50       else
51         x = tx;
52         y = ty;
53         z = tz;
54       endif
55     else
56       error ("sombrero: number of grid lines must be greater than 1");
57     endif
58   else
59     print_usage ();
60   endif
61
62 endfunction
63
64 %!demo
65 %! clf
66 %! sombrero ();