Functions > Data Analysis > Interpolation and Prediction > Example: Linear Interpolation
  
Example: Linear Interpolation
Use the linterp function to perform linear interpolation.
1. Define a set of y values.
Click to copy this expression
2. Define a matching set of x values. These values need to be in increasing order.
Click to copy this expression
Click to copy this expression
3. Define a vector of x values for which you want to interpolate the curve.
Click to copy this expression
Click to copy this expression
4. Call the linterp function to perform linear interpolation between the data points.
Click to copy this expression
5. Plot the data points and the interpolated curve.
Click to copy this expression
As expected, the linterp function draws a straight line between each set of data points.
The interpolation assumes that the last approximation function, the one calculated between the last two points, continues to be true for all other points on that end of the range. This assumption is seldom appropriate. Different methods exist to predict values outside of a data range.
A curve created using linear interpolation is not smooth at each connecting data point, so there are no defined derivatives of the interpolated curve. For this reason, you may wish to use a cubic spline or a B-spline to fit your data.