annotate scripts/plot/draw/sombrero.m @ 20737:2d9ec16fa960

Print error, rather than aborting, if mex function mxIsFromGlobalWS is used (bug #46070). * mex.cc (mxIsFromGlobalWS): Call mexErrMsgTxt rather than abort() in function.
author Rik <rik@octave.org>
date Tue, 29 Sep 2015 12:00:11 -0700
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19790
diff changeset
1 ## Copyright (C) 1993-2015 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
17 ## <http://www.gnu.org/licenses/>.
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
18
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 2847
diff changeset
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})
17120
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
22 ## @deftypefnx {Function File} {@var{z} =} sombrero (@dots{})
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
23 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} sombrero (@dots{})
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
24 ## Plot the familiar 3-D sombrero function.
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6278
diff changeset
25 ##
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6278
diff changeset
26 ## The function plotted is
17120
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
27 ## @tex
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
28 ## $$z = { \rm{sin} (\sqrt {(x^2 + y^2)}) \over \sqrt {(x^2 + y^2)} }$$
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
29 ## @end tex
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
30 ## @ifnottex
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
31 ##
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 2847
diff changeset
32 ## @example
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6278
diff changeset
33 ## z = sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2))
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 2847
diff changeset
34 ## @end example
17120
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
35 ##
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
36 ## @end ifnottex
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
37 ## Called without a return argument, @code{sombrero} plots the surface of the
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
38 ## above function over the meshgrid [-8,8] using @code{surf}.
19790
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
39 ##
17120
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
40 ## If @var{n} is a scalar the plot is made with @var{n} grid lines.
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
41 ## The default value for @var{n} is 41.
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
42 ##
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
43 ## When called with output arguments, return the data for the function
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
44 ## evaluated over the meshgrid. This can subsequently be plotted with
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
45 ## @code{surf (@var{x}, @var{y}, @var{z})}.
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
46 ##
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
47 ## @seealso{peaks, meshgrid, mesh, surf}
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 2847
diff changeset
48 ## @end deftypefn
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
49
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
50 ## Author: jwe
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
51
15176
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
52 function [x, y, z] = sombrero (n = 41)
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
53
15176
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
54 if (nargin > 2)
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
55 print_usage ();
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
56 elseif (n <= 1)
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
57 error ("sombrero: number of grid lines N must be greater than 1");
5381
75f308189a05 [project @ 2005-06-05 13:19:20 by jwe]
jwe
parents: 5307
diff changeset
58 endif
75f308189a05 [project @ 2005-06-05 13:19:20 by jwe]
jwe
parents: 5307
diff changeset
59
17493
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
60 [xx, yy] = meshgrid (linspace (-8, 8, n));
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
61 r = sqrt (xx.^2 + yy.^2) + eps; # eps prevents div/0 errors
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
62 zz = sin (r) ./ r;
17120
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
63
15176
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
64 if (nargout == 0)
17493
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
65 surf (xx, yy, zz);
17120
a639221f9863 sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents: 16814
diff changeset
66 elseif (nargout == 1)
17493
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
67 x = zz;
5381
75f308189a05 [project @ 2005-06-05 13:19:20 by jwe]
jwe
parents: 5307
diff changeset
68 else
17493
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
69 x = xx;
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
70 y = yy;
89ffc9c786e5 sombrero.m: Return meshgridded x,y rather than vectors.
Rik <rik@octave.org>
parents: 17190
diff changeset
71 z = zz;
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
72 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
73
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
74 endfunction
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
75
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
76
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
77 %!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
78 %! 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
79 %! colormap ('default');
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
80 %! sombrero ();
17190
df4c4b7708a4 Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents: 17124
diff changeset
81 %! title ('sombrero() function');
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
82
15176
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
83 ## Test input validation
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
84 %!error sombrero (1,2,3)
befb99c0c72f sombrero.m: Put input validation first and add %!tests.
Rik <rik@octave.org>
parents: 14247
diff changeset
85 %!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
86