Evaluates the interpolating polynomial for the given data from the Newton form, utilising the Horner scheme. Input arguments: nodes, the interpolation nodes values, function values at the nodes x, values at which the interpolating polynomial should be evaluated Output arguments: y, value of interpolating polynomial at x
0001 function [ y ] = Newton_Horner( nodes,values,x ) 0002 % Evaluates the interpolating polynomial for the given data 0003 % from the Newton form, utilising the Horner scheme. 0004 % Input arguments: 0005 % nodes, the interpolation nodes 0006 % values, function values at the nodes 0007 % x, values at which the interpolating polynomial should be evaluated 0008 % Output arguments: 0009 % y, value of interpolating polynomial at x 0010 0011 [n,m]=size(nodes); % finding the size of nodes 0012 [k,l]=size(values); % finding the size of values 0013 [p,q]= size(x); % finding the size of x 0014 if m~=1 || l~=1 || q~=1; 0015 error('input need to be column vectors'); 0016 elseif n~=k 0017 error('input dimensions do not agree'); 0018 end 0019 0020 d=divdifftable(nodes,values); % this subroutine calculates the divided 0021 % difference table 0022 d=diag(d); % the required divided differences lie along the diagonal 0023 0024 y=d(n)*ones(p,1); % set y equal to the most deeply nested 0025 % term in the expression 0026 0027 for i=1:n-1; % expand out the brackets one after the other 0028 y=y.*(x-nodes(n-i)*ones(p,1))+d(n-i)*ones(p,1); 0029 end 0030 0031 end 0032