To implement the Newton's method of interpolation in MATLAB, we can use the interp1 function which uses the Newton's divided difference formula under the hood. Here's an example code:
main.m871 chars42 linesThe divdiff function computes and returns the divided difference coefficients c given the input x and y vectors. The newton_eval function evaluates the interpolating polynomial using the divided differences and returns the interpolated values of y for the given x values.
We then use these functions to compute the divided difference coefficients for the given x and y vectors, define a function f to evaluate the interpolated values using the Newton's method, and then use f to compute the interpolated values for some new x_new values. Finally, we plot the original data and the interpolated values using the plot function.
gistlibby LogSnag