diff 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
line wrap: on
line diff
--- a/scripts/plot/fplot.m
+++ b/scripts/plot/fplot.m
@@ -20,7 +20,7 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits})
 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{n})
-## Plots a function @var{fn}, within the defined limits. @var{fn}
+## Plot a function @var{fn}, within the defined limits.  @var{fn}
 ## an be either a string, a function handle or an inline function.
 ## The limits of the plot are given by @var{limits} of the form
 ## @code{[@var{xlo}, @var{xhi}]} or @code{[@var{xlo}, @var{xhi},
@@ -28,8 +28,8 @@
 ## defaults to 100. 
 ##
 ## @example
-##    fplot('cos',[0,2*pi])
-##    fplot('[cos(x),sin(x)]',[0,2*pi])
+##    fplot ("cos", [0, 2*pi])
+##    fplot ("[cos(x), sin(x)]", [0, 2*pi])
 ## @end example
 ## @end deftypefn
 
@@ -44,12 +44,18 @@
 
   x = linspace (limits(1), limits(2), n)';
 
-  if (isa (fn, "inline function") || isa (fn, "function_handle"))
+  nam = fn;
+  if (strcmp (typeinfo (fn), "inline function"))
+    fn = vectorize (fn);
     y = fn (x);
+    nam = formula (fn);
+  elseif (isa (fn, "function_handle"))
+    y = fn (x);
+    nam = func2str (fn);
   elseif (all (isalnum (fn)))
     y = feval (fn, x);
   else
-    finl = inline (fn);
+    finl = vectorize (inline (fn));
     y = finl (x);
   endif
 
@@ -57,6 +63,6 @@
     axis (limits);
   endif
 
-  plot (x, y, [";", fn, ";"]);
+  plot (x, y, [";", nam, ";"]);
 
 endfunction