Mercurial > hg > octave-nkf
annotate scripts/plot/sombrero.m @ 16814:64e7bb01fce2
doc: Improve documentation for 2-D plot functions
* doc/interpreter/plot.txi: Rewrite documentation around get/set.
* libinterp/interpfcn/graphics.cc(Fget, Fset): Add seealso links. Add
additional calling forms for get().
* scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/comet.m,
scripts/plot/comet3.m, scripts/plot/contour.m, scripts/plot/contour3.m,
scripts/plot/contourc.m, scripts/plot/contourf.m, scripts/plot/errorbar.m,
scripts/plot/gca.m, scripts/plot/gcf.m, scripts/plot/gco.m,
scripts/plot/ishghandle.m, scripts/plot/loglogerr.m, scripts/plot/pareto.m,
scripts/plot/pcolor.m, scripts/plot/pie.m, scripts/plot/pie3.m,
scripts/plot/plotmatrix.m, scripts/plot/plotyy.m, scripts/plot/polar.m,
scripts/plot/quiver.m, scripts/plot/quiver3.m, scripts/plot/rose.m,
scripts/plot/scatter.m, scripts/plot/semilogxerr.m, scripts/plot/semilogyerr.m,
scripts/plot/sombrero.m, scripts/plot/stairs.m, scripts/plot/stem.m,
scripts/plot/stem3.m: Improve docstrings.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 22 Jun 2013 17:40:52 -0700 |
parents | befb99c0c72f |
children | a639221f9863 |
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 -*- |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
15176
diff
changeset
|
20 ## @deftypefn {Function File} {} sombrero () |
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
15176
diff
changeset
|
21 ## @deftypefnx {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 | |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
35 function [x, y, z] = sombrero (n = 41) |
4 | 36 |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
37 if (nargin > 2) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
38 print_usage (); |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
39 elseif (n <= 1) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
40 error ("sombrero: number of grid lines N must be greater than 1"); |
5381 | 41 endif |
42 | |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
43 tx = linspace (-8, 8, n)'; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
44 ty = tx; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
45 [xx, yy] = meshgrid (tx, ty); |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
46 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
|
47 tz = sin (r) ./ r; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
48 if (nargout == 0) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
49 surf (tx, ty, tz); |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
50 box ("off"); |
5381 | 51 else |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
52 x = tx; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
53 y = ty; |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
54 z = tz; |
4 | 55 endif |
56 | |
57 endfunction | |
7245 | 58 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 |
7245 | 60 %!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
|
61 %! 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
|
62 %! colormap ('default'); |
7245 | 63 %! 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
|
64 |
15176
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
65 ## Test input validation |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
66 %!error sombrero (1,2,3) |
befb99c0c72f
sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents:
14247
diff
changeset
|
67 %!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
|
68 |