annotate scripts/plot/draw/fplot.m @ 27923:bd51beb6205e

update formatting of copyright notices * Use <https://octave.org/copyright/> instead of <https://octave.org/COPYRIGHT.html/>. * For consistency with other comments in the Octave sources, use C++-style comments for copyright blocks in C and C++ files. * Use delimiters above and below copyright blocks that are appropriate for the language used in the file. * Eliminate extra spacing inside copyright blocks. * lex.ll (looks_like_copyright): Also allow newlines and carriage returns before the word "Copyright". * scripts/mk-doc.pl (gethelp): Also skip empty comment lines. * bp-table.cc, type.m: Adjust tests.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Jan 2020 11:59:41 -0500
parents 1891570abac8
children 7a8c69c4eb55
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 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 2005-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26617
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/>.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
7 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24494
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
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: 24494
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.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
14 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
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.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
19 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
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: 6895
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: 24494
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 ########################################################################
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
25
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
27 ## @deftypefn {} {} fplot (@var{fn})
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
28 ## @deftypefnx {} {} fplot (@var{fn}, @var{limits})
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20715
diff changeset
29 ## @deftypefnx {} {} fplot (@dots{}, @var{tol})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20715
diff changeset
30 ## @deftypefnx {} {} fplot (@dots{}, @var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20715
diff changeset
31 ## @deftypefnx {} {} fplot (@dots{}, @var{fmt})
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
32 ## @deftypefnx {} {} fplot (@dots{}, @var{property}, @var{value}, @dots{})
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
33 ## @deftypefnx {} {} fplot (@var{hax}, @dots{})
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20715
diff changeset
34 ## @deftypefnx {} {[@var{x}, @var{y}] =} fplot (@dots{})
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
35 ## Plot a function @var{fn} within the range defined by @var{limits}.
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
36 ##
17479
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
37 ## @var{fn} is a function handle, inline function, or string containing the
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
38 ## name of the function to evaluate.
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
39 ##
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
40 ## The limits of the plot are of the form @w{@code{[@var{xlo}, @var{xhi}]}} or
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
41 ## @w{@code{[@var{xlo}, @var{xhi}, @var{ylo}, @var{yhi}]}}. If no limits
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
42 ## are specified the default is @code{[-5, 5]}.
17479
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
43 ##
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
44 ## The next three arguments are all optional and any number of them may be
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
45 ## given in any order.
17479
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
46 ##
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
47 ## @var{tol} is the relative tolerance to use for the plot and defaults
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
48 ## to 2e-3 (.2%).
17479
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
49 ##
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
50 ## @var{n} is the minimum number of points to use. When @var{n} is specified,
24493
dc6404ab6947 doc: Small tweaks to fplot and surfnorm docstrings (bug #52761).
Rik <rik@octave.org>
parents: 24431
diff changeset
51 ## the maximum stepsize will be @code{(@var{xhi} - @var{xlo}) / @var{n}}. More
17479
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
52 ## than @var{n} points may still be used in order to meet the relative
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
53 ## tolerance requirement.
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
54 ##
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
55 ## The @var{fmt} argument specifies the linestyle to be used by the plot
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
56 ## command.
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
57 ##
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
58 ## Multiple property-value pairs may also be specified, but they must appear
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
59 ## in pairs. These arguments are applied to the line objects drawn by
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
60 ## @code{plot}.
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
61 ##
24431
0c6cedafc71e doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents: 23219
diff changeset
62 ## If the first argument @var{hax} is an axes handle, then plot into this axes,
17159
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
63 ## rather than the current axes returned by @code{gca}.
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
64 ##
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
65 ## With no output arguments, the results are immediately plotted. With two
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
66 ## output arguments, the 2-D plot data is returned. The data can subsequently
16951
a7c9be4a2c0f fplot.m: Fix bad texinfo in docstring for changeset b34202b24212.
Rik <rik@octave.org>
parents: 16950
diff changeset
67 ## be plotted manually with @code{plot (@var{x}, @var{y})}.
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
68 ##
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
69 ## Example:
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
70 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
71 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
72 ## @group
16951
a7c9be4a2c0f fplot.m: Fix bad texinfo in docstring for changeset b34202b24212.
Rik <rik@octave.org>
parents: 16950
diff changeset
73 ## fplot (@@cos, [0, 2*pi])
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
74 ## fplot ("[cos(x), sin(x)]", [0, 2*pi])
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
75 ## @end group
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
76 ## @end example
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
77 ##
20205
59911f536b07 fplot.m: Document requirement of accepting vector inputs (bug #42050).
Rik <rik@octave.org>
parents: 19833
diff changeset
78 ## Programming Notes:
59911f536b07 fplot.m: Document requirement of accepting vector inputs (bug #42050).
Rik <rik@octave.org>
parents: 19833
diff changeset
79 ##
59911f536b07 fplot.m: Document requirement of accepting vector inputs (bug #42050).
Rik <rik@octave.org>
parents: 19833
diff changeset
80 ## @code{fplot} works best with continuous functions. Functions with
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17026
diff changeset
81 ## discontinuities are unlikely to plot well. This restriction may be removed
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 17026
diff changeset
82 ## in the future.
20205
59911f536b07 fplot.m: Document requirement of accepting vector inputs (bug #42050).
Rik <rik@octave.org>
parents: 19833
diff changeset
83 ##
24415
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
84 ## @code{fplot} performance is better when the function accepts and returns a
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
85 ## vector argument. Consider this when writing user-defined functions and use
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
86 ## element-by-element operators such as @code{.*}, @code{./}, etc. See the
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
87 ## function @code{vectorize} for potentially converting inline or anonymous
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
88 ## functions to vectorized versions.
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20205
diff changeset
89 ##
20205
59911f536b07 fplot.m: Document requirement of accepting vector inputs (bug #42050).
Rik <rik@octave.org>
parents: 19833
diff changeset
90 ## @seealso{ezplot, plot, vectorize}
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
91 ## @end deftypefn
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
92
17159
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
93 function [X, Y] = fplot (varargin)
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
94
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
95 [hax, varargin, nargin] = __plt_get_axis_arg__ ("fplot", varargin{:});
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
96
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
97 if (nargin < 1 || nargin > 5)
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
98 print_usage ();
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
99 endif
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
100
17159
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
101 fn = varargin{1};
6699
3f4ccca05612 [project @ 2007-06-12 20:48:02 by jwe]
jwe
parents: 6220
diff changeset
102 if (strcmp (typeinfo (fn), "inline function"))
3f4ccca05612 [project @ 2007-06-12 20:48:02 by jwe]
jwe
parents: 6220
diff changeset
103 fn = vectorize (fn);
3f4ccca05612 [project @ 2007-06-12 20:48:02 by jwe]
jwe
parents: 6220
diff changeset
104 nam = formula (fn);
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
105 elseif (is_function_handle (fn))
6699
3f4ccca05612 [project @ 2007-06-12 20:48:02 by jwe]
jwe
parents: 6220
diff changeset
106 nam = func2str (fn);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
107 elseif (all (isalnum (fn)))
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
108 nam = fn;
10400
b14fd5116c29 Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents: 9051
diff changeset
109 elseif (ischar (fn))
16338
8aeb5d5c3747 fplot.m: Overhaul code to use modern coding practices.
Rik <rik@octave.org>
parents: 14868
diff changeset
110 fn = vectorize (inline (fn));
8aeb5d5c3747 fplot.m: Overhaul code to use modern coding practices.
Rik <rik@octave.org>
parents: 14868
diff changeset
111 nam = formula (fn);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
112 else
16338
8aeb5d5c3747 fplot.m: Overhaul code to use modern coding practices.
Rik <rik@octave.org>
parents: 14868
diff changeset
113 error ("fplot: FN must be a function handle, inline function, or string");
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
114 endif
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
115
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
116 if (nargin > 1 && isnumeric (varargin{2}))
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
117 limits = varargin{2};
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
118 if (iscomplex (limits) || (numel (limits) != 2 && numel (limits) != 4))
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
119 error ("fplot: LIMITS must be a real vector with 2 or 4 elements");
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
120 endif
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
121 i = 3;
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
122 else
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
123 limits = [-5, 5];
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
124 i = 2;
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
125 endif
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
126
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
127 n = 5;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
128 tol = 2e-3;
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
129 fmt = {};
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
130 while (i <= numel (varargin))
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
131 arg = varargin{i};
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
132 if (ischar (arg))
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
133 [~, valid_fmt] = __pltopt__ ("fplot", arg, false);
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
134 if (valid_fmt)
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
135 fmt(end+1) = arg;
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
136 else
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
137 if (i == numel (varargin))
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
138 error ("fplot: bad input in position %d", i);
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
139 endif
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
140 fmt(end+(1:2)) = varargin([i, i+1]);
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
141 i++; # Skip PROPERTY.
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
142 endif
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
143 elseif (isnumeric (arg) && isscalar (arg) && arg > 0)
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
144 if (arg == fix (arg))
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
145 n = arg;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
146 else
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
147 tol = arg;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
148 endif
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
149 else
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
150 error ("fplot: bad input in position %d", i);
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
151 endif
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
152 i++;
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
153 endwhile
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
154
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18629
diff changeset
155 if (n != 5)
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18629
diff changeset
156 ## n was specified
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
157 x0 = linspace (limits(1), limits(2), n/2 + 1)';
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
158 else
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
159 x0 = linspace (limits(1), limits(2), 5)';
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
160 n = 8;
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
161 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
162
26150
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
163 try
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
164 y0 = feval (fn, x0);
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
165 if (isscalar (y0))
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
166 warning ("fplot: FN is not a vectorized function which reduces performance");
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
167 fn = @(x) arrayfun (fn, x); # Create a new fn that accepts vectors
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
168 y0 = feval (fn, x0);
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
169 endif
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
170 catch
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
171 ## feval failed, maybe it is because the function is not vectorized?
24415
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
172 fn = @(x) arrayfun (fn, x); # Create a new fn that accepts vectors
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
173 y0 = feval (fn, x0);
26150
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
174 warning ("fplot: FN is not a vectorized function which reduces performance");
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
175 end_try_catch
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
176
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
177 x = linspace (limits(1), limits(2), n)';
46757ec0bac2 fplot.m: Use try/catch to avoid errors with non-vectorized functions (bug #55134).
Rik <rik@octave.org>
parents: 25803
diff changeset
178 y = feval (fn, x);
24415
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
179
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
180 if (rows (x0) == rows (y0))
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
181 fcn_transpose = false;
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
182 elseif (rows (x0) == columns (y0))
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
183 fcn_transpose = true;
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
184 y0 = y0.';
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
185 y = y.';
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
186 else
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
187 error ("fplot: invalid function FN (# of outputs not equal to inputs)");
8145
7ef5b1b4e029 fplot.m: call axis after plot
John W. Eaton <jwe@octave.org>
parents: 7280
diff changeset
188 endif
7ef5b1b4e029 fplot.m: call axis after plot
John W. Eaton <jwe@octave.org>
parents: 7280
diff changeset
189
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
190 err0 = Inf;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
191
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
192 ## FIXME: This algorithm should really use adaptive scaling as
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
193 ## the numerical quadrature algorithms do so that extra points are
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
194 ## used where they are needed and not spread evenly over the entire
17479
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
195 ## x-range. Try any function with a discontinuity, such as
bdb237c7507c doc: Redo fplot docstring.
Rik <rik@octave.org>
parents: 17190
diff changeset
196 ## fplot (@tan, [-2, 2]) or fplot ("1./x", [-3, 2]), to see the
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
197 ## problems with the current solution.
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
198
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
199 while (n < 2^18) # Something is wrong if we need more than 250K points
18629
6fdd3ab55b78 undo unintended changes to fplot in changeset 37c300acfcfd
John W. Eaton <jwe@octave.org>
parents: 18627
diff changeset
200 yi = interp1 (x0, y0, x, "linear");
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
201 ## relative error calculation using average of [yi,y] as reference
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
202 ## since neither estimate is known a priori to be better than the other.
24415
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
203 err = 0.5 * max (abs ((yi - y) ./ (yi + y + eps))(:));
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
204 if (err < tol || abs (err - err0) < tol/2)
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
205 ## Either relative tolerance has been met OR
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
206 ## algorithm has stopped making any reasonable progress per iteration.
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
207 break;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
208 endif
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
209 x0 = x;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
210 y0 = y;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
211 err0 = err;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
212 n = 2 * (n - 1) + 1;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
213 x = linspace (limits(1), limits(2), n)';
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
214 y = feval (fn, x);
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
215 if (fcn_transpose)
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
216 y = y.';
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
217 endif
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
218 endwhile
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
219
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
220 if (nargout == 2)
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
221 X = x;
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
222 Y = y;
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
223 else
17159
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
224 if (isempty (hax))
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
225 hax = gca ();
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
226 endif
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
227 plot (hax, x, y, fmt{:});
17159
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
228 axis (hax, limits);
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
229 ## FIXME: If hold is on, then this erases the existing legend rather than
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
230 ## adding to it.
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
231 if (isvector (y))
17159
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
232 legend (hax, nam);
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
233 else
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
234 for i = 1:columns (y)
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
235 nams{i} = sprintf ("%s(:,%i)", nam, i);
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
236 endfor
17159
d74e2b5bdeb5 fplot.m: Accept an axis handle as first input.
Rik <rik@octave.org>
parents: 17122
diff changeset
237 legend (hax, nams{:});
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
238 endif
6781
3058060c560f [project @ 2007-07-19 08:07:31 by dbateman]
dbateman
parents: 6699
diff changeset
239 endif
16338
8aeb5d5c3747 fplot.m: Overhaul code to use modern coding practices.
Rik <rik@octave.org>
parents: 14868
diff changeset
240
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
241 endfunction
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
242
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
243
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
244 %!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
245 %! clf;
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
246 %! fplot (@cos, [0, 2*pi]);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21831
diff changeset
247 %! title ("fplot() single 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
248
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
249 %!demo
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
250 %! clf;
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21831
diff changeset
251 %! fplot ("[cos(x), sin(x)]", [0, 2*pi]);
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21831
diff changeset
252 %! title ("fplot() multiple functions");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
253
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
254 %!demo
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
255 %! clf;
17026
be52288f827b Tweak some plotting demos for messages and spelling.
Rik <rik@octave.org>
parents: 16951
diff changeset
256 %! fh = @(x) sin (pi*x) ./ (pi*x);
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
257 %! fplot (fh, [-5, 5]);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21831
diff changeset
258 %! title ("fplot() sinc function (possible division by 0, near 0)");
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
259
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
260 %!test
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
261 %! ## Multi-valued function
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
262 %! [x, y] = fplot ("[cos(x), sin(x)]", [0, 2*pi]);
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
263 %! assert (columns (y) == 2);
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
264 %! assert (rows (x) == rows (y));
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
265 %! assert (y, [cos(x), sin(x)], -2e-3);
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
266
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
267 %!test
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
268 %! ## Function requiring transpose
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
269 %! fn = @(x) 2 * x(:).';
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
270 %! [x, y] = fplot (fn, [-1, 1]);
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
271 %! assert (columns (y) == 1);
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
272 %! assert (rows (x) == rows (y));
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
273 %! assert (y, 2*x);
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
274
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
275 %!test
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
276 %! ## Constant value function
24415
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
277 %! fn = @(x) 0;
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
278 %! [x, y] = fplot (fn, [-1, 1]);
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
279 %! assert (columns (y) == 1);
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
280 %! assert (rows (x) == rows (y));
24415
3cd47be4fcbe fplot.m: Fix handling of non-vectorized input functions (bug #52673).
Rik <rik@octave.org>
parents: 23220
diff changeset
281 %! assert (y, repmat ([0], size (x)));
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
282
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
283 ## Test input validation
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
284 %!error fplot ()
16950
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
285 %!error fplot (1,2,3,4,5,6)
b34202b24212 fplot.m: Overhaul function for Matlab compatibility and performance (bug #38961).
Rik <rik@octave.org>
parents: 16775
diff changeset
286 %!error <FN must be a function handle> fplot (1, [0 1])
16775
5ec3f4aea91c fplot.m: Fix bug when FN is a constant function (bug #39287)
Rik <rik@octave.org>
parents: 16338
diff changeset
287 %!error <LIMITS must be a real vector> fplot (@cos, [i, 2*i])
5ec3f4aea91c fplot.m: Fix bug when FN is a constant function (bug #39287)
Rik <rik@octave.org>
parents: 16338
diff changeset
288 %!error <LIMITS must be a real vector with 2 or 4> fplot (@cos, [1])
5ec3f4aea91c fplot.m: Fix bug when FN is a constant function (bug #39287)
Rik <rik@octave.org>
parents: 16338
diff changeset
289 %!error <LIMITS must be a real vector with 2 or 4> fplot (@cos, [1 2 3])
26154
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
290 %!error <bad input in position 2> fplot (@cos, "linewidth")
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
291 %!error <bad input in position 3> fplot (@cos, [-1,1], {1})
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
292 %!warning <FN is not a vectorized function>
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
293 %! fn = @(x) 0;
af655eb15cdc fplot.m: Add 1-input calling form, support for specifying PROP/VAL pairs.
Rik <rik@octave.org>
parents: 26150
diff changeset
294 %! [x,y] = fplot (fn, [-1,1]);
21831
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
295 %!error <invalid function FN>
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
296 %! fn = @(x) [x;x];
1077f09a0cfd fplot.m: Handle input functions which do not respect input data orientation (bug #48034).
Rik <rik@octave.org>
parents: 20852
diff changeset
297 %! fplot (fn, [-1,1]);