Functions > Data Analysis > Interpolation and Prediction > Example: Polynomial Interpolation
  
Example: Polynomial Interpolation
polyint
Use the polyint function to perform polynomial interpolation on a data set.
1. Define a data set.
Click to copy this expressionClick to copy this expression
2. Call the polyint function to calculate the polynomial interpolation of the data set at a particular point.
Click to copy this expression
At x = 328, the interpolated result is y = -0.189, with an error of 0.056.
3. Define the range of x values where you want to find the interpolated y values.
Click to copy this expression
Click to copy this expression
4. Record the interpolated values and their respective error.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
5. Plot the data points, the interpolated curve, and the error estimate.
Click to copy this expression
polycoeff
To calculate the interpolated values, use polyint. To calculate both the interpolating polynomial and some of its derivatives, use polycoeff. The coefficients provided by polycoeff are less accurate at given data points, so they are not the best representation of interpolated values.
1. Find the polynomial coefficients for the polynomial curve that passes through the set of data points defined above.
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Define a polynomial function, where c is the vector of polynomial coefficients.
Click to copy this expression
Click to copy this expression
3. Differentiate the polynomial function.
Click to copy this expression
Click to copy this expression
4. Plot the data points, the polynomial interpolation, and its first derivative.
Click to copy this expression
The polycoeff function does not construct the polynomial of best least-squares fit, as is done by the polyfit function.
The results of polyint and polycoeff should not be used to make predictions for y values outside of the range of the original x values.
polyiter
Use the polyiter function to perform a polynomial interpolation.
1. Define the maximum possible number of iterations and the tolerance.
Click to copy this expression
Click to copy this expression
2. Call the polyiter function.
Click to copy this expression
The algorithm did not converge, so it did not stop before the N_max iteration. It did not achieve an error of 0.01 and it returned the same result as polyint:
Click to copy this expression
3. Plot the original points, the exact polynomial, and the iterated polynomial.