home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / polynom / polyval.m < prev    next >
Text File  |  1999-12-24  |  2KB  |  65 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} polyval (@var{c}, @var{x})
  22. ## Evaluate a polynom.
  23. ## 
  24. ## @code{polyval (@var{c}, @var{x})} will evaluate the polynom at the
  25. ## specified value of @var{x}.
  26. ## 
  27. ## If @var{x} is a vector or matrix, the polynom is evaluated at each of
  28. ## the elements of @var{x}.
  29. ## @end deftypefn
  30.  
  31. ## SEE ALSO: polyvalm, poly, roots, conv, deconv, residue, filter,
  32. ##           polyderv, polyintg
  33.  
  34. ## Author: Tony Richardson <arichard@stark.cc.oh.us>
  35. ## Created: June 1994
  36. ## Adapted-By: jwe
  37.  
  38. function y = polyval (c, x)
  39.  
  40.   if (nargin != 2)
  41.     usage ("polyval (c, x)");
  42.   endif
  43.  
  44.   if (! (is_vec (c) || isempty (c)))
  45.     error ("polyval: first argument must be a vector.");
  46.   endif
  47.  
  48.   if (isempty (x))
  49.     y = [];
  50.     return;
  51.   endif
  52.  
  53.   if (length (c) == 0)
  54.     y = c;
  55.     return;
  56.   endif
  57.  
  58.   n = length (c);
  59.   y = c (1) * ones (rows (x), columns (x));
  60.   for index = 2:n
  61.     y = c (index) + x .* y;
  62.   endfor
  63.  
  64. endfunction
  65.