diff examples/polynomial/polynomial.m @ 8223:0c91b9a17dcf

Commit missing files from previous change
author David Bateman <dbateman@free.fr>
date Thu, 16 Oct 2008 09:20:58 +0100
parents
children
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/examples/polynomial/polynomial.m
@@ -0,0 +1,28 @@
+## -*- texinfo -*-
+## @deftypefn {Function File} {} polynomial ()
+## @deftypefnx {Function File} {} polynomial (@var{a})
+## Creates a polynomial object representing the polynomial
+##
+## @example
+## a0 + a1 * x + a2 * x^2 + @dots{} + an * x^n
+## @end example
+## @end deftypefn
+
+function p = polynomial (a)
+  if (nargin == 0)
+    p.poly = [];
+    p = class (p, "polynomial");
+  elseif (nargin == 1)
+    if (strcmp (class (a), "polynomial"))
+      p = a;
+    elseif (isvector (a) && isreal (a))
+      p.poly = a(:)';
+      p = class (p, "polynomial");
+    else
+      error ("polynomial: expecting real or complex vector")
+    endif
+  else
+    print_usage ();
+  endif
+  superiorto ("double");
+endfunction