view examples/code/@polynomial/polynomial.m @ 23411:98bf881fafd1

doc: improve @polynomial example class constructor * examples/code/@polynomial/polynomial.m: Avoid meaningless brackets and prefer isa() function to string comparision.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Wed, 19 Apr 2017 01:30:09 +0200
parents fd97ed44f2da
children 28de41192f3c
line wrap: on
line source

## -*- texinfo -*-
## @deftypefn  {} {} polynomial ()
## @deftypefnx {} {} 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 (isa (a, "polynomial"))
      p = a;
    elseif (isreal (a) && isvector (a))
      p.poly = a(:).';  # force row vector
      p = class (p, "polynomial");
    else
      error ("@polynomial: A must be a real vector");
    endif
  endif

endfunction