% interp_poly.m % Using the Matlab polyfit and polyval functions % to calculate interpolating polynomial x = [1,2,3,4] % nodes y = [2,4,3,5] % values at the nodes % Determine coefficients defining the degree 3 % interpolating polynomial. Note that this % corresponds to the polynomial % a(1)*x^3 + a(2)*x^2 + a(3)*x + a(4) a = polyfit(x,y,3) % polynomial coefficients % plot the points and the polynomial xp = [1:0.01:4]; yp = polyval(a,xp); plot(x,y,'O', xp,yp, '-')