## -*- texinfo -*-
## @deftypefn {Function File} {} polytranslate (@var{f},@var{a})
## Return the coefficients of the shifted polynomial whose
## coefficients are given by vector @var{f}.  If @var{f} is the
## vector representing the polynomial f(x), then
## @var{g} = polytranslate(@var{f}, @var{a}) is the vector
## representing g(x) = f(x+a).
## 
## Here is a simple example that will plot both the original and
## translated (shifted) polynomials.  f is a third order polynomial.
## g is a polynomial obtained after shifting f one unit to the right:
##
## f = [1/5 4/5 -7/5 -2];
##
## g = polytranslate(f, -1);
##
## x = linspace(-4,4,100);
##
## plot(x,polyval(f,x),x,polyval(g,x));
##
## axis([-4 4 -3 5]);
##
## grid("on");
## @seealso{polyscale, polytranscale}
## @end deftypefn

## Author: Tony Richardson <richardson@evansville.edu)
## Created: April 2009

function g = polytranslate(f, a)

   if(nargin != 2)
      print_usage ();
   endif

   if(! isvector(f) )
      error("polytranslate: first argument must be a vector.");
   endif

   if(! isscalar(a) )
      error("polytranslate: second argument must be a scalar.");
   endif

   lf = length(f);

   # Ensure that f is a row vector
   if(rows(f) > 1)
      f = reshape(a, 1, lf);
   endif

   p = linspace(0, lf-1, lf)';
   T = (lf - 1 - p)*ones(1,lf);
   g = f * (a .^ toeplitz(p) .* bsxfun(@bincoeff,T,T'));

endfunction
