function out = sym2polyg(S,s,n)
%  Function: sym2polyg 
%Written by: Joel Haynie -- Joel@Haynie.com
%            www.Joel.Haynie.com
%      Date: 10/11/1998
%
%This function converts a symbolic nth degree polynomial to an array of 
%symbolic coeffients.
%
%This functions syntax is...
%If a nth degree polynomial is of the form:
%S = a*s^n + b*s^(n-1) + c*s^(n-1) + ... + y*s^1 + z*s^0
%This function will return an array out = [a b c ... y z]
%
%Usage:
%out = sym2polyg(SYMBOLIC_POLYNOMIAL, SYMBOLIC_VARIABLE, POLYNOMIAL_DEGREE);
%
%-----------------------------------END OF LINE-----------------------------
syms out temp;
out = repmat(out,1,n+1);
for i = 1:(n+1),
   if i == 1
      temp = S/s^n;
      temp = collect(temp, s);
      out(1) = limit(temp, s, inf);
   else
      temp = (temp-out(i-1))*s;
      temp = collect(temp, s);
      out(i) = limit(temp, s, inf);
   end
end
%end sym2polyg
%-----------------------------------END OF LINE-----------------------------

