Mercurial > hg > octave-nkf
annotate scripts/plot/draw/sombrero.m @ 17610:3f8b3588a9f0
fill.m: Properly color faces based on orientation of cdata vector.
* scripts/plot/draw/fill.m: Test for row vector and set "facecolor" to "flat"
if found.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 08 Oct 2013 15:50:38 -0700 |
parents | 7bb76a22cde1 |
children | d63878346099 |
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}) |
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 | 25 ## |
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 | 31 ## |
3446 | 32 ## @example |
6895 | 33 ## z = sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2)) |
3446 | 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}. |
a639221f9863
sombrero.m: Overhaul documentation and make calling forms equivalent to peaks()
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
39 ## |
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 | 48 ## @end deftypefn |
4 | 49 |
2314 | 50 ## Author: jwe |
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 | 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 | 58 endif |
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 | 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 | 72 endif |
73 | |
74 endfunction | |
7245 | 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 | 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 | 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 |