comparison scripts/plot/fplot.m @ 5820:27c966e4b2dc

[project @ 2006-05-17 21:00:54 by jwe]
author jwe
date Wed, 17 May 2006 21:00:54 +0000
parents
children 34f96dd5441b
comparison
equal deleted inserted replaced
5819:e54c11df0524 5820:27c966e4b2dc
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)
38 usage ("fplot (fn, limits, n)");
39 endif
40
41 if (nargin < 3)
42 n = 100;
43 endif
44
45 x = linspace (limits(1), limits(2), n)';
46
47 if (strcmp (class (fn), "inline function")
48 || strcmp (class (fn), "function handle"))
49 y = fn (x);
50 elseif (all (isalnum (fn)))
51 y = feval (fn, x);
52 else
53 finl = inline (fn);
54 y = finl (x);
55 endif
56
57 if (length (limits) > 2)
58 axis (limits);
59 endif
60
61 plot (x, y, [";", fn, ";"]);
62
63 endfunction