home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / POLYFUN.DI$ / POLYVAL.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  831 b   |  31 lines

  1. function y = polyval(c,x)
  2. %POLYVAL Polynomial evaluation.
  3. %    If V is a vector whose elements are the coefficients of a
  4. %    polynomial, then POLYVAL(V,s) is the value of the
  5. %    polynomial evaluated at s.  If S is a matrix or vector,
  6. %    the polynomial is evaluated at all points in S.
  7. %    See POLYVALM for evaluation in a matrix sense.
  8.  
  9. %    Polynomial evaluation c(x) using Horner's method 
  10.  
  11. %    J.N. Little 4-26-86
  12. %     Revised 3-9-88 JNL
  13. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  14.  
  15. [m,n] = size(x);
  16. nc = max(size(c));
  17.  
  18. if (m+n) == 2
  19.     % Make it scream for scalar X.  Polynomial evaluation can be
  20.     % implemented as a recursive digital filter.
  21.     y = filter(1,[1 -x],c);
  22.     y = y(nc);
  23.     return
  24. end
  25.  
  26. % Do general case where X is an array
  27. y = zeros(m,n);
  28. for i=1:nc
  29.     y = x .* y + c(i) * ones(m,n);
  30. end
  31.