Functions > Data Analysis > Interpolation and Prediction > Example: Using Units with the Polynomial Interpolation Functions
Example: Using Units with the Polynomial Interpolation Functions
1. Define two input vectors and an independent variable.
 vx 4.4 7.9 3 9.1 2.0 5.7 2.6 4 8.5 1.9 vy
4 vx
x 3
2. Define the units.
3. Evaluate the input vectors and the input variable.
 X vx xu Y vy yu U x xu
 The unit of the independent variable U must match the unit of the first argument vector.
Polynomial Interpolation
1. Use the polyint function to evaluate the interpolation function at the specified independent variable values.
Looking up U in input vector X results in a match and the corresponding exact value in vector Y is 1.333 with an error of zero. However, 2U has no exact match in X and this results in an interpolated value with a none-zero error.
2. Use function length to determine the length of the input vectors, then create a short program to evaluate the interpolation functions at different points. Display the interpolated points in the first column and the error values in the second column.
Variable u must be a scalar, and the unit m is added as part of the function argument.
3. Save the interpolation points and the error values into two separate vectors.
4. Plot the interpolation points along with the error envelope.
The error starts out relatively large then becomes negligent after the second interpolation point.
Polynomial Iteration
1. Use the polyiter function to evaluate the iteration function at the specified independent variable value, the number of maximum iterations and the tolerance.
 • The algorithm stops if the last two iterated estimates of the data point agree to within the tolerance value, or if the number of iterations reaches the maximum allowed number of iterations.• The first result shows that the iteration function failed to converge after reaching the maximum allowed number of two iterations, so it returned the corresponding element in vector Y.• The second result shows that the iteration function converged after the third iteration and it did not reach the maximum allowed number of five iterations.
2. Use a short program to evaluate the iteration function at ten different points. Use function augment to add the error value in the fourth column of the returned matrix which displays the merge status in the first column, the number of utilized iterations in the second column, and the iterated values in the third column.
3. Save the interpolation points and the error values into separate vectors.
4. Plot the iteration points for 3 iterations and an error of 0.25.
The error is constant at every interpolation point.
5. Compare the returned results of interpolation and iteration when the maximum number of iterations is set to 3 and the error is set to 0.25.
6. Show that the result of interpolation is identical to the result of iteration when the number of iterations is set to a large number and the error is set to zero.
The maximum number of iterations must be less than the length of the input vectors.