annotate scripts/plot/draw/peaks.m @ 32632:2e484f9f1f18 stable

maint: update Octave Project Developers copyright for the new year
author John W. Eaton <jwe@octave.org>
date Fri, 22 Dec 2023 12:08:17 -0500
parents 597f3ee61a48
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2007-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
7 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
14 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
19 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
20 ## 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: 7001
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
25
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
27 ## @deftypefn {} {} peaks ()
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
28 ## @deftypefnx {} {} peaks (@var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ## @deftypefnx {} {} peaks (@var{x}, @var{y})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
30 ## @deftypefnx {} {@var{z} =} peaks (@dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ## @deftypefnx {} {[@var{x}, @var{y}, @var{z}] =} peaks (@dots{})
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
32 ## Plot a function with lots of local maxima and minima.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
33 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
34 ## The function has the form
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
35 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
36 ## @tex
18679
a142f35f3cb6 doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## $$f(x,y) = 3 (1 - x) ^ 2 e ^ {\left(-x^2 - (y+1)^2\right)} - 10 \left({x \over 5} - x^3 - y^5\right) - {1 \over 3} e^{\left(-(x+1)^2 - y^2\right)}$$
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
38 ## @end tex
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
39 ## @ifnottex
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
40 ## @verbatim
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
41 ## f(x,y) = 3*(1-x)^2*exp(-x^2 - (y+1)^2) ...
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
42 ## - 10*(x/5 - x^3 - y^5)*exp(-x^2-y^2) ...
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
43 ## - 1/3*exp(-(x+1)^2 - y^2)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
44 ## @end verbatim
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
45 ## @end ifnottex
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
46 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
47 ## Called without a return argument, @code{peaks} plots the surface of the
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
48 ## above function using @code{surf}.
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
49 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
50 ## If @var{n} is a scalar, @code{peaks} plots the value of the above
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
51 ## function on an @var{n}-by-@var{n} mesh over the range [-3,3]. The
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
52 ## default value for @var{n} is 49.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
53 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
54 ## If @var{n} is a vector, then it represents the grid values over which
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
55 ## to calculate the function. If @var{x} and @var{y} are specified then
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
56 ## the function value is calculated over the specified grid of vertices.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
57 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
58 ## When called with output arguments, return the data for the function
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
59 ## evaluated over the meshgrid. This can subsequently be plotted with
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
60 ## @code{surf (@var{x}, @var{y}, @var{z})}.
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
61 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
62 ## @seealso{sombrero, meshgrid, mesh, surf}
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
63 ## @end deftypefn
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
64
27984
b09432b20a84 maint: Remove special cases of old version control keywords in code base.
Rik <rik@octave.org>
parents: 27923
diff changeset
65 ## Reference: Expression for peaks function was taken from the following paper:
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6788
diff changeset
66 ## http://www.control.hut.fi/Kurssit/AS-74.115/Material/GENALGgoga.pdf
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6788
diff changeset
67
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
68 function [X_out, Y_out, Z_out] = peaks (x, y)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
69
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7017
diff changeset
70 if (nargin == 0)
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7017
diff changeset
71 x = y = linspace (-3, 3, 49);
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7017
diff changeset
72 elseif (nargin == 1)
14552
86854d032a37 maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
73 if (length (x) > 1)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
74 y = x;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
75 else
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7017
diff changeset
76 x = y = linspace (-3, 3, x);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
77 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
78 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
79
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7017
diff changeset
80 if (isvector (x) && isvector (y))
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
81 [X, Y] = meshgrid (x, y);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
82 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
83 X = x;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
84 Y = y;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
85 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
86
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
87 Z = 3 * (1 - X) .^ 2 .* exp (- X .^ 2 - (Y + 1) .^ 2) ...
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
88 - 10 * (X / 5 - X .^ 3 - Y .^ 5) .* exp (- X .^ 2 - Y .^ 2) ...
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14552
diff changeset
89 - 1 / 3 * exp (- (X + 1) .^ 2 - Y .^ 2);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
90
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7017
diff changeset
91 if (nargout == 0)
7282
30100a15625c [project @ 2007-12-10 21:42:11 by jwe]
jwe
parents: 7216
diff changeset
92 surf (x, y, Z);
19081
d59d052c9858 rotate.m: new function
John W. Eaton <jwe@octave.org>
parents: 18679
diff changeset
93 Z_max = max (Z(:));
d59d052c9858 rotate.m: new function
John W. Eaton <jwe@octave.org>
parents: 18679
diff changeset
94 Z_min = min (Z(:));
d59d052c9858 rotate.m: new function
John W. Eaton <jwe@octave.org>
parents: 18679
diff changeset
95 axis ([-3, 3, -3, 3, Z_min, Z_max]);
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7017
diff changeset
96 elseif (nargout == 1)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
97 X_out = Z;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
98 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
99 X_out = X;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
100 Y_out = Y;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
101 Z_out = Z;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
102 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
103
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
104 endfunction