Mercurial > hg > octave-lyh
comparison scripts/plot/fplot.m @ 6699:3f4ccca05612
[project @ 2007-06-12 20:48:02 by jwe]
author | jwe |
---|---|
date | Tue, 12 Jun 2007 20:48:03 +0000 |
parents | 0c3537d2a844 |
children | 3058060c560f |
comparison
equal
deleted
inserted
replaced
6698:6d366791e132 | 6699:3f4ccca05612 |
---|---|
18 ## 02110-1301, USA. | 18 ## 02110-1301, USA. |
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits}) | 21 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits}) |
22 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{n}) | 22 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{n}) |
23 ## Plots a function @var{fn}, within the defined limits. @var{fn} | 23 ## Plot a function @var{fn}, within the defined limits. @var{fn} |
24 ## an be either a string, a function handle or an inline function. | 24 ## an be either a string, a function handle or an inline function. |
25 ## The limits of the plot are given by @var{limits} of the form | 25 ## The limits of the plot are given by @var{limits} of the form |
26 ## @code{[@var{xlo}, @var{xhi}]} or @code{[@var{xlo}, @var{xhi}, | 26 ## @code{[@var{xlo}, @var{xhi}]} or @code{[@var{xlo}, @var{xhi}, |
27 ## @var{ylo}, @var{yhi}]}. @var{n} is the number of points to use and | 27 ## @var{ylo}, @var{yhi}]}. @var{n} is the number of points to use and |
28 ## defaults to 100. | 28 ## defaults to 100. |
29 ## | 29 ## |
30 ## @example | 30 ## @example |
31 ## fplot('cos',[0,2*pi]) | 31 ## fplot ("cos", [0, 2*pi]) |
32 ## fplot('[cos(x),sin(x)]',[0,2*pi]) | 32 ## fplot ("[cos(x), sin(x)]", [0, 2*pi]) |
33 ## @end example | 33 ## @end example |
34 ## @end deftypefn | 34 ## @end deftypefn |
35 | 35 |
36 function fplot (fn, limits, n) | 36 function fplot (fn, limits, n) |
37 if (nargin < 2 || nargin > 3) | 37 if (nargin < 2 || nargin > 3) |
42 n = 100; | 42 n = 100; |
43 endif | 43 endif |
44 | 44 |
45 x = linspace (limits(1), limits(2), n)'; | 45 x = linspace (limits(1), limits(2), n)'; |
46 | 46 |
47 if (isa (fn, "inline function") || isa (fn, "function_handle")) | 47 nam = fn; |
48 if (strcmp (typeinfo (fn), "inline function")) | |
49 fn = vectorize (fn); | |
48 y = fn (x); | 50 y = fn (x); |
51 nam = formula (fn); | |
52 elseif (isa (fn, "function_handle")) | |
53 y = fn (x); | |
54 nam = func2str (fn); | |
49 elseif (all (isalnum (fn))) | 55 elseif (all (isalnum (fn))) |
50 y = feval (fn, x); | 56 y = feval (fn, x); |
51 else | 57 else |
52 finl = inline (fn); | 58 finl = vectorize (inline (fn)); |
53 y = finl (x); | 59 y = finl (x); |
54 endif | 60 endif |
55 | 61 |
56 if (length (limits) > 2) | 62 if (length (limits) > 2) |
57 axis (limits); | 63 axis (limits); |
58 endif | 64 endif |
59 | 65 |
60 plot (x, y, [";", fn, ";"]); | 66 plot (x, y, [";", nam, ";"]); |
61 | 67 |
62 endfunction | 68 endfunction |