comparison scripts/plot/fplot.m @ 17490:bdb237c7507c

doc: Redo fplot docstring. * scripts/plot/fplot.m: Redo fplot docstring.
author Rik <rik@octave.org>
date Wed, 25 Sep 2013 08:26:37 -0700
parents df4c4b7708a4
children
comparison
equal deleted inserted replaced
17489:0ad2f93fd83c 17490:bdb237c7507c
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits}) 20 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits})
21 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{tol}) 21 ## @deftypefnx {Function File} {} fplot (@dots{}, @var{tol})
22 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{n}) 22 ## @deftypefnx {Function File} {} fplot (@dots{}, @var{n})
23 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{fmt}) 23 ## @deftypefnx {Function File} {} fplot (@dots{}, @var{fmt})
24 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{tol}, @var{n}, @var{fmt})
25 ## @deftypefnx {Function File} {[@var{x}, @var{y}] =} fplot (@dots{}) 24 ## @deftypefnx {Function File} {[@var{x}, @var{y}] =} fplot (@dots{})
26 ## Plot a function @var{fn} within the range defined by @var{limits}. 25 ## Plot a function @var{fn} within the range defined by @var{limits}.
27 ## 26 ##
28 ## @var{fn} is a function handle, inline function, or string 27 ## @var{fn} is a function handle, inline function, or string containing the
29 ## containing the name of the function to evaluate. 28 ## name of the function to evaluate.
30 ## The limits of the plot are of the form @code{[@var{xlo}, @var{xhi}]} or 29 ##
31 ## @code{[@var{xlo}, @var{xhi}, @var{ylo}, @var{yhi}]}. 30 ## The limits of the plot are of the form @w{@code{[@var{xlo}, @var{xhi}]}} or
31 ## @w{@code{[@var{xlo}, @var{xhi}, @var{ylo}, @var{yhi}]}}.
32 ##
32 ## The next three arguments are all optional and any number of them may be 33 ## The next three arguments are all optional and any number of them may be
33 ## given in any order. 34 ## given in any order.
35 ##
34 ## @var{tol} is the relative tolerance to use for the plot and defaults 36 ## @var{tol} is the relative tolerance to use for the plot and defaults
35 ## to 2e-3 (.2%). 37 ## to 2e-3 (.2%).
36 ## @var{n} is the minimum number of points to use. When @var{n} is 38 ##
37 ## specified, the maximum stepsize will be 39 ## @var{n} is the minimum number of points to use. When @var{n} is specified,
38 ## @code{@var{xhi} - @var{xlo} / @var{n}}. More than @var{n} points may still 40 ## the maximum stepsize will be @code{@var{xhi} - @var{xlo} / @var{n}}. More
39 ## be used in order to meet the relative tolerance requirement. 41 ## than @var{n} points may still be used in order to meet the relative
42 ## tolerance requirement.
43 ##
40 ## The @var{fmt} argument specifies the linestyle to be used by the plot 44 ## The @var{fmt} argument specifies the linestyle to be used by the plot
41 ## command. 45 ## command.
42 ## 46 ##
43 ## If the first argument @var{hax} is an axes handle, then plot into this axis, 47 ## If the first argument @var{hax} is an axes handle, then plot into this axis,
44 ## rather than the current axes returned by @code{gca}. 48 ## rather than the current axes returned by @code{gca}.
135 err0 = Inf; 139 err0 = Inf;
136 140
137 ## FIXME: This algorithm should really use adaptive scaling as the 141 ## FIXME: This algorithm should really use adaptive scaling as the
138 ## the numerical quadrature algorithms do so that extra points are 142 ## the numerical quadrature algorithms do so that extra points are
139 ## used where they are needed and not spread evenly over the entire 143 ## used where they are needed and not spread evenly over the entire
140 ## x-range. Try any function with a discontinuity such as 144 ## x-range. Try any function with a discontinuity, such as
141 ## fplot (@tan, [-2, 2]) or fplot ("1./x", [-3, 2]) to see the 145 ## fplot (@tan, [-2, 2]) or fplot ("1./x", [-3, 2]), to see the
142 ## problems with the current solution. 146 ## problems with the current solution.
143 147
144 while (n < 2^18) # Something is wrong if we need more than 250K points 148 while (n < 2^18) # Something is wrong if we need more than 250K points
145 yi = interp1 (x0, y0, x, "linear"); 149 yi = interp1 (x0, y0, x, "linear");
146 ## relative error calculation using average of [yi,y] as reference 150 ## relative error calculation using average of [yi,y] as reference