function [ dd ] = DividedDiff( x,y )
%DividedDiff Find the divided difference [yn ... y1 y0]
%   Input: x = [ x0, x1, ..., xn ], y = [y0, y1, ..., yn].
%   x, y can be either a column vector or row vector. 

% Check if the input is in the correct format
if ~isvector(x) || ~isvector(y)
    error('All input must be vector.');
elseif length (x) ~= length (y) 
    error ('Vectors have different lengths.');
end

% Recursive formula 
if length (x) == 1
   dd = y;
else
   dd = (DividedDiff(x(2:end),y(2:end))- DividedDiff(x(1:end-1),y(1:end-1)))/(x(end)-x(1));
end
end