Mercurial > hg > octave-nkf
annotate scripts/plot/sombrero.m @ 16491:b10a23fe80bb
doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
* scripts/audio/wavread.m, scripts/miscellaneous/getappdata.m,
scripts/miscellaneous/license.m, scripts/miscellaneous/ver.m,
scripts/plot/daspect.m, scripts/plot/graphics_toolkit.m,
scripts/plot/pbaspect.m, scripts/polynomial/splinefit.m, scripts/set/union.m,
scripts/signal/freqz.m: Improve docstring wording.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 10 Apr 2013 22:43:30 -0700 |
parents | befb99c0c72f |
children | 64e7bb01fce2 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 1993-2012 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 |
7282 | 29 ## @seealso{surf, meshgrid, mesh} |
3446 | 30 ## @end deftypefn |
4 | 31 |
2314 | 32 ## Author: jwe |
33 | |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
34 function [x, y, z] = sombrero (n = 41) |
4 | 35 |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
36 if (nargin > 2) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
37 print_usage (); |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
38 elseif (n <= 1) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
39 error ("sombrero: number of grid lines N must be greater than 1"); |
5381 | 40 endif |
41 | |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
42 tx = linspace (-8, 8, n)'; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
43 ty = tx; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
44 [xx, yy] = meshgrid (tx, ty); |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
45 r = sqrt (xx .^ 2 + yy .^ 2) + eps; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
46 tz = sin (r) ./ r; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
47 if (nargout == 0) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
48 surf (tx, ty, tz); |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
49 box ("off"); |
5381 | 50 else |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
51 x = tx; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
52 y = ty; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
53 z = tz; |
4 | 54 endif |
55 | |
56 endfunction | |
7245 | 57 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 |
7245 | 59 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
60 %! clf; |
14247
c4fa5e0b6193
test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
61 %! colormap ('default'); |
7245 | 62 %! sombrero (); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
63 |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
64 ## Test input validation |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
65 %!error sombrero (1,2,3) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
66 %!error <N must be greater than 1> sombrero (1) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
67 |