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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## 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, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
245
|
19 |
3446
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} sombrero (@var{n}) |
|
22 ## Draw a `sombrero' in three dimensions using @var{n} grid lines. The |
2311
|
23 ## function plotted is |
|
24 ## |
3446
|
25 ## @example |
2613
|
26 ## z = sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2)) |
3446
|
27 ## @end example |
6076
|
28 ## @seealso{mesh, meshgrid} |
3446
|
29 ## @end deftypefn |
4
|
30 |
2314
|
31 ## Author: jwe |
|
32 |
6049
|
33 function [x, y, z] = sombrero (n) |
4
|
34 |
5381
|
35 if (nargin == 0) |
|
36 n = 41; |
|
37 endif |
|
38 |
|
39 if (nargin < 2) |
|
40 if (n > 1) |
6076
|
41 tx = ty = linspace (-8, 8, n)'; |
|
42 [xx, yy] = meshgrid (tx, ty); |
5381
|
43 r = sqrt (xx .^ 2 + yy .^ 2) + eps; |
6076
|
44 tz = sin (r) ./ r; |
6049
|
45 if (nargout == 0) |
6076
|
46 mesh (tx, ty, tz); |
6278
|
47 box ("off"); |
6076
|
48 else |
|
49 x = tx; |
|
50 y = ty; |
|
51 z = tz; |
|
52 endif |
5381
|
53 else |
|
54 error ("sombrero: number of grid lines must be greater than 1"); |
|
55 endif |
|
56 else |
6046
|
57 print_usage (); |
4
|
58 endif |
|
59 |
|
60 endfunction |