changeset 1100:3b6f6c5217e7

[project @ 1995-02-14 01:45:09 by jwe]
author jwe
date Tue, 14 Feb 1995 01:45:09 +0000
parents 8a5b0b2caf44
children 38dabbe2feb5
files src/data.cc
diffstat 1 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/data.cc	Tue Feb 14 01:39:08 1995 +0000
+++ b/src/data.cc	Tue Feb 14 01:45:09 1995 +0000
@@ -958,6 +958,75 @@
   return retval;
 }
 
+DEFUN ("linspace", Flinspace, Slinspace, 2, 1,
+  "usage: linspace (x1, x2, n)\n\
+\n\
+Return a vector of n equally spaced points between x1 and x2\n\
+inclusive.\n\
+\n\
+If the final argument is omitted, n = 100 is assumed.\n\
+\n\
+All three arguments must be scalars.\n\
+\n\
+See also: logspace")
+{
+  Octave_object retval;
+
+  int nargin = args.length ();
+
+  int npoints = 100;
+
+  if (nargin == 3)
+    {
+      double n = args(2).double_value ();
+
+      if (! error_state)
+	npoints = NINT (n);
+    }
+  else
+    print_usage ("linspace");
+
+  if (! error_state)
+    {
+      if (npoints > 1)
+	{
+	  tree_constant arg_1 = args(0);
+	  tree_constant arg_2 = args(1);
+
+	  if (arg_1.is_complex_type () || arg_2.is_complex_type ())
+	    {
+	      Complex x1 = arg_1.complex_value ();
+	      Complex x2 = arg_2.complex_value ();
+
+	      if (! error_state)
+		{
+		  ComplexRowVector rv = linspace (x1, x2, npoints);
+
+		  if (! error_state)
+		    retval (0) = tree_constant (rv, 0);
+		}
+	    }
+	  else
+	    {
+	      double x1 = arg_1.double_value ();
+	      double x2 = arg_2.double_value ();
+
+	      if (! error_state)
+		{
+		  RowVector rv = linspace (x1, x2, npoints);
+
+		  if (! error_state)
+		    retval (0) = tree_constant (rv, 0);
+		}
+	    }
+	}
+      else
+	error ("linspace: npoints must be greater than 2");
+    }
+
+  return retval;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***