5820
|
1 ## Copyright (C) 2005 Paul Kienzle <pkienzle@users.sf.net> |
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits}) |
|
22 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{n}) |
|
23 ## Plots a function @var{fn}, within the defined limits. @var{fn} |
|
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 |
|
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 |
|
28 ## defaults to 100. |
|
29 ## |
|
30 ## @example |
|
31 ## fplot('cos',[0,2*pi]) |
|
32 ## fplot('[cos(x),sin(x)]',[0,2*pi]) |
|
33 ## @end example |
|
34 ## @end deftypefn |
|
35 |
|
36 function fplot (fn, limits, n) |
|
37 if (nargin < 2 || nargin > 3) |
6046
|
38 print_usage (); |
5820
|
39 endif |
|
40 |
|
41 if (nargin < 3) |
|
42 n = 100; |
|
43 endif |
|
44 |
|
45 x = linspace (limits(1), limits(2), n)'; |
|
46 |
6220
|
47 if (isa (fn, "inline function") || isa (fn, "function_handle")) |
5820
|
48 y = fn (x); |
|
49 elseif (all (isalnum (fn))) |
|
50 y = feval (fn, x); |
|
51 else |
|
52 finl = inline (fn); |
|
53 y = finl (x); |
|
54 endif |
|
55 |
|
56 if (length (limits) > 2) |
|
57 axis (limits); |
|
58 endif |
|
59 |
|
60 plot (x, y, [";", fn, ";"]); |
|
61 |
|
62 endfunction |