function temp = Eval(n, x, a, t) % This procedure requires: % x = horizontal array of x values (used in Coef) % a = coefficients of the interpolation polynomial % (Newton form) % t = evaluate the polynomial at this value! % n = degree of interpolation polynomial % [This means that there must be (n + 1) elements in % x and a.] % % My example was: % Eval(3, x, a, 3) % [Type the above into the Command Window!] % I've already run Coef, and the coefficients are in % the array called "a". % % Unravel the nested form... temp = a(n+1); for i=n:-1:1 temp = temp*(t - x(i)) + a(i); end % Display the results. % Turn this off, if you don't want to see multiple interpolations. fprintf('The interpolated value at t = %7.4f is %10.7f.\n',t,temp);