view examples/code/@polynomial/polynomial.m @ 21059:73ab962bc52d

doc: Use newer coding conventions in examples/code directory. * FIRfilter.m, FIRfilter_aggregation.m, display.m, subsasgn.m, subsref.m, display.m, end.m, get.m, numel.m, plot.m, polynomial.m, polynomial_superiorto.m, polyval.m, roots.m, set.m, subsasgn.m, subsref.m, celldemo.cc, fortrandemo.cc, funcdemo.cc, globaldemo.cc, oct_demo.cc, paramdemo.cc, stringdemo.cc: Use newer coding conventions in examples/code directory.
author Rik <rik@octave.org>
date Wed, 13 Jan 2016 16:21:24 -0800
parents 25d676f9619c
children fd97ed44f2da
line wrap: on
line source

## -*- texinfo -*-
## @deftypefn  {Function File} {} polynomial ()
## @deftypefnx {Function File} {} polynomial (@var{a})
## Create a polynomial object representing the polynomial
##
## @example
## a0 + a1 * x + a2 * x^2 + @dots{} + an * x^n
## @end example
##
## @noindent
## from a vector of coefficients [a0 a1 a2 @dots{} an].
## @end deftypefn

function p = polynomial (a)

  if (nargin > 1)
    print_usage ();
  endif

  if (nargin == 0)
    p.poly = [0];
    p = class (p, "polynomial");
  else
    if (strcmp (class (a), "polynomial"))
      p = a;
    elseif (isvector (a) && isreal (a))
      p.poly = a(:).';  # force row vector
      p = class (p, "polynomial");
    else
      error ("@polynomial: expecting real vector");
    endif
  endif

endfunction