% newtdriver.m % This is a driver which constructs the vector of % abscissas and the vector of ordinates for use in the % newtpoly.m function. % Construct the vectors nodes = [0;1;2;3;4]; % Nodes for interpolating polynomial fvals = cos(nodes); % Function values for the interpolating % polynomial x = [0:0.01:4]'; % x-values where we plan to evaluate the % interpolating polynomial. % Calling newtpoly.m to retrieve the % polynomial coefficients the % Divided Difference Table. % NOTE: delete the semicolon if you want % to see the output; [coefs,DT] = newtpoly(nodes,fvals); % Calling nestmult.m to evaluate the interpolating polynomial % at the points contained in the vector x. a = diag(DT); % Initializing the coefficients of the % Newton interpolating polynomial % Calling the nested multiplication routine in nestmult.m % NOTE: delete the semicolon if you want % to see the output; out = nestmult(a,nodes,x); plot(x,out,nodes,fvals,'g*');