Mercurial > hg > octave-lyh
annotate scripts/plot/peaks.m @ 14552:86854d032a37
maint: miscellaneous style fixes for .m files
* audio/mu2lin.m, deprecated/cut.m, general/cplxpair.m,
general/genvarname.m, geometry/rectint.m, help/gen_doc_cache.m,
image/hsv2rgb.m, image/rainbow.m, io/textscan.m,
miscellaneous/bzip2.m, miscellaneous/compare_versions.m,
miscellaneous/fact.m, miscellaneous/menu.m, optimization/fminbnd.m,
optimization/fminunc.m, optimization/fzero.m, optimization/sqp.m,
plot/__gnuplot_drawnow__.m, plot/axis.m, plot/findobj.m,
plot/legend.m, plot/peaks.m, plot/private/__errplot__.m,
plot/private/__fltk_print__.m, plot/private/__go_draw_axes__.m,
plot/private/__patch__.m, polynomial/pchip.m, polynomial/residue.m,
signal/periodogram.m, sparse/sprandsym.m, statistics/base/moment.m,
statistics/distributions/expcdf.m, statistics/distributions/expinv.m,
statistics/distributions/exppdf.m, statistics/tests/prop_test_2.m,
statistics/tests/sign_test.m, statistics/tests/t_test.m,
statistics/tests/t_test_2.m, statistics/tests/t_test_regression.m,
strings/regexptranslate.m, time/datetick.m:
Style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Apr 2012 22:07:00 -0400 |
parents | 72c96de7a403 |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 2007-2012 Paul Kienzle |
6788 | 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. | |
6788 | 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/>. | |
6788 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
20 ## @deftypefn {Function File} {} peaks () |
6788 | 21 ## @deftypefnx {Function File} {} peaks (@var{n}) |
22 ## @deftypefnx {Function File} {} peaks (@var{x}, @var{y}) | |
23 ## @deftypefnx {Function File} {@var{z} =} peaks (@dots{}) | |
24 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} peaks (@dots{}) | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
7282
diff
changeset
|
25 ## Generate a function with lots of local maxima and minima. The function |
6788 | 26 ## has the form |
27 ## | |
28 ## @tex | |
29 ## $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)}$ | |
30 ## @end tex | |
31 ## @ifnottex | |
32 ## @verbatim | |
33 ## f(x,y) = 3*(1-x)^2*exp(-x^2 - (y+1)^2) ... | |
34 ## - 10*(x/5 - x^3 - y^5)*exp(-x^2-y^2) ... | |
35 ## - 1/3*exp(-(x+1)^2 - y^2) | |
36 ## @end verbatim | |
37 ## @end ifnottex | |
38 ## | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
39 ## Called without a return argument, @code{peaks} plots the surface of the |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
7282
diff
changeset
|
40 ## above function using @code{mesh}. If @var{n} is a scalar, the @code{peaks} |
7001 | 41 ## returns the values of the above function on a @var{n}-by-@var{n} mesh over |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
7282
diff
changeset
|
42 ## the range @code{[-3,3]}. The default value for @var{n} is 49. |
6788 | 43 ## |
44 ## If @var{n} is a vector, then it represents the @var{x} and @var{y} values | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
45 ## of the grid on which to calculate the above function. The @var{x} and |
6788 | 46 ## @var{y} values can be specified separately. |
7282 | 47 ## @seealso{surf, mesh, meshgrid} |
6788 | 48 ## @end deftypefn |
49 | |
6895 | 50 ## Expression for the peaks function was taken from the following paper: |
51 ## http://www.control.hut.fi/Kurssit/AS-74.115/Material/GENALGgoga.pdf | |
52 | |
6788 | 53 function [X_out, Y_out, Z_out] = peaks (x, y) |
54 | |
7216 | 55 if (nargin == 0) |
56 x = y = linspace (-3, 3, 49); | |
57 elseif (nargin == 1) | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
58 if (length (x) > 1) |
6788 | 59 y = x; |
60 else | |
7216 | 61 x = y = linspace (-3, 3, x); |
6788 | 62 endif |
63 endif | |
64 | |
7216 | 65 if (isvector (x) && isvector (y)) |
6788 | 66 [X, Y] = meshgrid (x, y); |
67 else | |
68 X = x; | |
69 Y = y; | |
70 endif | |
71 | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
72 Z = 3 * (1 - X) .^ 2 .* exp(- X .^ 2 - (Y + 1) .^ 2) ... |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
73 - 10 * (X / 5 - X .^ 3 - Y .^ 5) .* exp(- X .^ 2 - Y .^ 2) ... |
6788 | 74 - 1 / 3 * exp(- (X + 1) .^ 2 - Y .^ 2); |
75 | |
7216 | 76 if (nargout == 0) |
7282 | 77 surf (x, y, Z); |
7216 | 78 elseif (nargout == 1) |
6788 | 79 X_out = Z; |
80 else | |
81 X_out = X; | |
82 Y_out = Y; | |
83 Z_out = Z; | |
84 endif | |
85 | |
86 endfunction |