Calculates the divided difference table Input arguments: nodes, interpolation points values, function values Output arguments: d, square matrix containing the divided difference table in its lower triangular part.
0001 function [d] = divdifftable( nodes, values ) 0002 % Calculates the divided difference table 0003 % Input arguments: 0004 % nodes, interpolation points 0005 % values, function values 0006 % Output arguments: 0007 % d, square matrix containing the divided difference table in its 0008 % lower triangular part. 0009 0010 % Note: The divided differences used in Newton's interpolation 0011 % formula are the diagonal entries of d. 0012 0013 [n,m]=size(nodes); % finding the size of nodes 0014 [k,l] = size(values); % finding the size of values 0015 if m~=1 || l~=1 0016 error('input need to be column vectors'); 0017 elseif n~=k 0018 error('input dimensions do not agree'); 0019 end 0020 d(:,1) = values; % the first column of the divided difference table are 0021 % the function values 0022 for j=2:n % generate the divided difference table one column after 0023 % the other 0024 for i=j:n % generate the entries on or below the diagonal 0025 % using the recurrence relation for divided differences 0026 if nodes(i-j+1) == nodes(i) 0027 error('nodes coincide'); 0028 else 0029 d(i,j)= ( d(i-1,j-1)-d(i,j-1)) / (nodes(i-j+1)-nodes(i)); 0030 end 0031 end 0032 end 0033 end 0034