2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
245
|
18 |
3446
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} sombrero (@var{n}) |
6895
|
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 |
2311
|
25 ## |
3446
|
26 ## @example |
6895
|
27 ## z = sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2)) |
3446
|
28 ## @end example |
6076
|
29 ## @seealso{mesh, meshgrid} |
3446
|
30 ## @end deftypefn |
4
|
31 |
2314
|
32 ## Author: jwe |
|
33 |
6049
|
34 function [x, y, z] = sombrero (n) |
4
|
35 |
5381
|
36 if (nargin == 0) |
|
37 n = 41; |
|
38 endif |
|
39 |
|
40 if (nargin < 2) |
|
41 if (n > 1) |
6076
|
42 tx = ty = linspace (-8, 8, n)'; |
|
43 [xx, yy] = meshgrid (tx, ty); |
5381
|
44 r = sqrt (xx .^ 2 + yy .^ 2) + eps; |
6076
|
45 tz = sin (r) ./ r; |
6049
|
46 if (nargout == 0) |
6076
|
47 mesh (tx, ty, tz); |
6278
|
48 box ("off"); |
6076
|
49 else |
|
50 x = tx; |
|
51 y = ty; |
|
52 z = tz; |
|
53 endif |
5381
|
54 else |
|
55 error ("sombrero: number of grid lines must be greater than 1"); |
|
56 endif |
|
57 else |
6046
|
58 print_usage (); |
4
|
59 endif |
|
60 |
|
61 endfunction |