7017
|
1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2005, 2006, 2007 |
|
2 ## John W. Eaton |
2313
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
245
|
19 |
3446
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} sombrero (@var{n}) |
6895
|
22 ## Produce the familiar three-dimensional sombrero plot using @var{n} |
|
23 ## grid lines. If @var{n} is omitted, a value of 41 is assumed. |
|
24 ## |
|
25 ## The function plotted is |
2311
|
26 ## |
3446
|
27 ## @example |
6895
|
28 ## z = sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2)) |
3446
|
29 ## @end example |
7282
|
30 ## @seealso{surf, meshgrid, mesh} |
3446
|
31 ## @end deftypefn |
4
|
32 |
2314
|
33 ## Author: jwe |
|
34 |
6049
|
35 function [x, y, z] = sombrero (n) |
4
|
36 |
5381
|
37 if (nargin == 0) |
|
38 n = 41; |
|
39 endif |
|
40 |
|
41 if (nargin < 2) |
|
42 if (n > 1) |
6076
|
43 tx = ty = linspace (-8, 8, n)'; |
|
44 [xx, yy] = meshgrid (tx, ty); |
5381
|
45 r = sqrt (xx .^ 2 + yy .^ 2) + eps; |
6076
|
46 tz = sin (r) ./ r; |
6049
|
47 if (nargout == 0) |
7282
|
48 surf (tx, ty, tz); |
6278
|
49 box ("off"); |
6076
|
50 else |
|
51 x = tx; |
|
52 y = ty; |
|
53 z = tz; |
|
54 endif |
5381
|
55 else |
|
56 error ("sombrero: number of grid lines must be greater than 1"); |
|
57 endif |
|
58 else |
6046
|
59 print_usage (); |
4
|
60 endif |
|
61 |
|
62 endfunction |
7245
|
63 |
|
64 %!demo |
|
65 %! sombrero (); |