function lag=slagrange(dig,n,r,x)
%LAGRANGE Elementary Lagrange interpolation polynomials.
%   LAG=LAGRANGE(N,R,X) evaluates at the point X the N 
%   elementary Lagrange interpolation polynomials of degree  
%   N-1 associated with the N (distinct) entries of the
%   Nx1 array R.

digits(dig);
r=vpa(r); x=vpa(x);
lag=vpa(zeros(n,1));
for nu=1:n
  mu=[1:nu-1,nu+1:n];
  lag(nu)=prod(x-r(mu))./prod(r(nu)-r(mu));
end
