function [a,b] = padecoef(T,n)
%PADECOEF  Pade approximation of time delays.
%
%   [NUM,DEN] = PADECOEF(T,N) returns the Nth-order Pade approximation 
%   of the continuous-time delay exp(-T*s) in transfer function form.
%   The row vectors NUM and DEN contain the polynomial coefficients  
%   in descending powers of s.
%
%   See also PADE

%   Andrew C.W. Grace 8-13-89, P. Gahinet 7-22-96, 5-98
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.2 $  $Date: 1998/09/18 19:22:37 $

%  Reference:  Golub and Van Loan, Matrix Computations, Johns Hopkins
%              University Press, pp. 557ff.

ni = nargin;
no = nargout;
error(nargchk(1,2,ni))
if ni==1,
   n = 1; 
elseif n<0 | T<0,
   error('T and N must be non negative.')
end
n = round(n);

% The coefficients of the Pade approximation are given by the 
% recursion   h[k+1] = (N-k)/(2*N-k)/(k+1) * h[k],  h[0] = 1
% and 
%     exp(-T*s) == Sum { h[k] (-T*s)^k } / Sum { h[k] (T*s)^k }
%
if T>0
   a = zeros(1,n+1);   a(1) = 1;
   b = zeros(1,n+1);   b(1) = 1;
   for k = 1:n,
      fact = T*(n-k+1)/(2*n-k+1)/k;
      a(k+1) = (-fact) * a(k);
      b(k+1) = fact * b(k);
   end
   a = fliplr(a/b(n+1));
   b = fliplr(b/b(n+1));
else
   a = 1;
   b = 1;
end

% end padecoef
