/*
** horner.src
** Author: Alan G. Isaac
**         mailto:aisaac@american.edu
** Date:   28 June 2000
** Caveat: this code is provided gratis but without
**         any performance warrantee or guarantee.
** Comments welcomed.
**
**> horner
**
**  Purpose:    evaluate scalar polynomial at given points
**              y=a0 + a1 x + a2 x^2 + . . . + an x^n
**
**  Format:     y = horner(x,a);
**
**  Input:      x    matrix of points for evaluation
**              a    column vector of polynomial coefficents
**                   a=(a0,a1,...,an)'
**  Output:     y    value of polynomial at x
**
**  Comments:   horner() ensures a=vecr(a);
**              note order of coefficents;
**              see GAUSS procs polyeval() and recsercp().
*/
proc (1)= horner(x,a);
  local y,ra;
  if cols(a)/=1;
    a=vecr(a);
    errorlog "setting a=vecr(a)";
  endif;
  ra=rows(a);
  y=a[ra];
  for i(1,ra-1,1);
    y=y.*x+a[ra-i];
  endfor;
retp(y);
endp;
@graph f(x)=3-2x-x^2@
library pgraph;
let a= 3 -2 -1;
x = seqa(-10,.1,201);
ypts = horner(x,a);
xy(x,ypts~zeros(rows(x),1));
