% SLANCZOS Symbolic counterpart of stieltjes.m
%
function ab=slanczos(dig,N,xw)
digits(dig);
Ncap=size(xw,1);
p0=xw(:,1); p1=vpa(zeros(Ncap,1)); p1(1)=xw(1,2);
for n=1:Ncap-1
  pn=xw(n+1,2); gam=vpa(1); sig=vpa(0); t=vpa(0); 
  xlam=xw(n+1,1);
  for k=1:n+1
    rho=p1(k)+pn; tmp=gam*rho; tsig=sig;
    if subs(rho)<=0
      gam=vpa(1); sig=vpa(0);
    else
      gam=p1(k)/rho;
      sig=pn/rho;
    end
    tk=sig*(p0(k)-xlam)-gam*t;
    p0(k)=p0(k)-(tk-t); t=tk;
    if subs(sig)<=0
      pn=tsig*p1(k);
    else
      pn=(t^2)/sig;
    end
    tsig=sig; p1(k)=tmp;
  end
end
ab=[p0(1:N) p1(1:N)];
