function  DD=dd_table(FUN,xn);
%%  function  DD=dd_table(FUN,xn);
%%
%%  THE DIVIDED DIFFERENCE TABLE for the function 
%%  FUN at the distinct points xn
%% 
%%  INPUT:
%%   xn  - the points at which the divided difference is 
%%         taken as a row vector ,   e.g. [0,1,2,3,4]
%%    FUN  - the data for the difference which may be entered 
%%           EITHER as a string, enclosed in ' ',with the name
%%           the m-file of the unction,  OR as a row vector of 
%%           data in the same order as xn
%%  OUTPUT:
%%    DD  - the matrix containing the divided difference table 
%%          with xn as first column, the values of FUN at xn as
%%          2nd column and k-th order divided difference as 
%%          (k-2)nd column

n=length(xn)-1;  % determine the number of points

DD(:,1)=xn';   % points as first column in the table

if isstr(FUN)==1;  % test whether from a function file
   DD(:,2)=feval(FUN,xn'); %or from given data function 
			   %values as 2nd column (0th order 
			   %difference)
else
    DD(:,2)=FUN';  % given data as 2nd column
end;

for i=2:n+1;       %% an adjustment is made for indexing in MATLAB
  for j=3:i+1;
   DD(i,j)=(DD(i,j-1)-DD(i-1,j-1))/(xn(i)-xn(i-j+2));
  end;
end;
